Best Python code snippet using localstack_python
rsa_key_generator.py
Source:rsa_key_generator.py
...11 def __init__(self, algorithm):12 self.config = init_config()13 self.key = RSA.generate(self._get_key_length_based_on(algorithm))14 self.filename = "my_rsa_key"15 self.dirname = self._init_directories()16 self.priv_dir = init_directory(os.path.join(self.dirname, "private"))17 self.public_dir = init_directory(os.path.join(self.dirname, "public"))18 def save_keys(self) -> str:19 """20 Generate and save keyfiles in specified directory. After this return this directory name.21 """22 private_key = self.key.export_key()23 with open(os.path.join(self.priv_dir, self.filename), "wb") as private_keyfile:24 private_keyfile.write(private_key)25 public_key = self.key.publickey().export_key()26 with open(os.path.join(self.public_dir, f"{self.filename}"), "wb") as public_keyfile:27 public_keyfile.write(public_key)28 return self.dirname29 def _get_key_length_based_on(self, algorithm_name: str) -> int:30 """31 Get key length based on algorith name. If such algorithm doesnt exist raise an exception32 """33 algorithms = self.config.get("algorithms").get("asymmetric")34 for key, value in algorithms.items():35 if key == algorithm_name:36 return value37 raise Exception("Not found such algorithm")38 def _init_directories(self) -> str:39 """40 Init directory for storing RSA keys and return its name41 """42 main_dir = self.config.get("directory").get("main_dir")43 asym_dir = self.config.get("directory").get("asym_dir")...
__init__.py
Source:__init__.py
...41 help = cmd['description']42 )43 cmd['parser_init'](ap)44 args = parser.parse_args()45 _init_directories()46 if not path.exists(ENV_CACHE):47 with open(ENV_CACHE, 'w') as ec:48 json.dump(known_envs, ec)49 else:50 with open(ENV_CACHE, 'r') as ec:51 known_envs = json.load(ec)52 cmd = list(filter(lambda c: c['name'] == args.action, COMMANDS))[0]53 ret_code = cmd['main'](args, known_envs)54 with open(ENV_CACHE, 'w') as ec:55 json.dump(known_envs, ec)56 return ret_code57if __name__ == '__main__':58 _init_directories()...
logger.py
Source:logger.py
...4 def __init__(self, save_dir, opt):5 self.save_dir = save_dir6 self.opt = opt7 self.log_filename = 'params.txt'8 self._init_directories()9 self._init_logfile()10 def _init_directories(self):11 # create/initialize folders12 if os.path.exists(self.save_dir):13 shutil.rmtree(self.save_dir)14 os.makedirs(self.save_dir)15 os.makedirs(os.path.join(self.save_dir, 'net_d_checkpoints'))16 os.makedirs(os.path.join(self.save_dir, 'net_g_checkpoints'))17 os.makedirs(os.path.join(self.save_dir, 'hists'))18 def _init_logfile(self):19 # create a log file and initialize it with training parameters info20 log_msg = ''21 for key_name in self.opt.__dict__:22 log_msg += key_name + ':' + str(self.opt.__dict__[key_name]) + '\n'23 print(log_msg + '\n')24 with open(os.path.join(self.save_dir, self.log_filename), 'w') as log_file:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!