Best Python code snippet using yandex-tank
trafid_cipher.py
Source:trafid_cipher.py  
...22        if len(tmp) == len(messagePart):23            result.append(tmp)24            tmp = ""25    return result[0], result[1], result[2]26def __prepare(27    message: str, alphabet: str28) -> tuple[str, str, dict[str, str], dict[str, str]]:29    # Validate message and alphabet, set to upper and remove spaces30    alphabet = alphabet.replace(" ", "").upper()31    message = message.replace(" ", "").upper()32    # Check length and characters33    if len(alphabet) != 27:34        raise KeyError("Length of alphabet has to be 27.")35    for each in message:36        if each not in alphabet:37            raise ValueError("Each message character has to be included in alphabet!")38    # Generate dictionares39    numbers = (40        "111",41        "112",42        "113",43        "121",44        "122",45        "123",46        "131",47        "132",48        "133",49        "211",50        "212",51        "213",52        "221",53        "222",54        "223",55        "231",56        "232",57        "233",58        "311",59        "312",60        "313",61        "321",62        "322",63        "323",64        "331",65        "332",66        "333",67    )68    character2Number = {}69    number2Character = {}70    for letter, number in zip(alphabet, numbers):71        character2Number[letter] = number72        number2Character[number] = letter73    return message, alphabet, character2Number, number2Character74def encryptMessage(75    message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 576) -> str:77    message, alphabet, character2Number, number2Character = __prepare(message, alphabet)78    encrypted, encrypted_numeric = "", ""79    for i in range(0, len(message) + 1, period):80        encrypted_numeric += __encryptPart(message[i : i + period], character2Number)81    for i in range(0, len(encrypted_numeric), 3):82        encrypted += number2Character[encrypted_numeric[i : i + 3]]83    return encrypted84def decryptMessage(85    message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 586) -> str:87    message, alphabet, character2Number, number2Character = __prepare(message, alphabet)88    decrypted_numeric = []89    decrypted = ""90    for i in range(0, len(message) + 1, period):91        a, b, c = __decryptPart(message[i : i + period], character2Number)92        for j in range(0, len(a)):93            decrypted_numeric.append(a[j] + b[j] + c[j])94    for each in decrypted_numeric:95        decrypted += number2Character[each]96    return decrypted97if __name__ == "__main__":98    msg = "DEFEND THE EAST WALL OF THE CASTLE."99    encrypted = encryptMessage(msg, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")100    decrypted = decryptMessage(encrypted, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")101    print(f"Encrypted: {encrypted}\nDecrypted: {decrypted}")Mongodriver.py
Source:Mongodriver.py  
...9        self.db = self.client[db_name]10        self.collection = self.db[collection_name]11    def push(self, data=None):12        try:13            self.__prepare()14            self.collection.insert_one(data)15        except Exception as e:16            print(e)17    def get(self, index=None, value=None):18        try:19            result = self.collection.find_one({index: value})20            return result21        except Exception as e:22            print(e)23            pass24    def get_last_item(self, param='id'):25        self.__prepare()26        return self.collection.count()27    def find_all(self):28        self.__prepare()29        current_pos = 030        while True:31            try:32                all_docs = self.collection.find(no_cursor_timeout=True).skip(current_pos)33                for doc in all_docs:34                    current_pos += 135                    yield doc36                break37            except:38                self.__prepare()39    def is_empty(self):40        self.__prepare()41        return self.collection.find_one({}) is None42    def update_id(self, index, id_, data):43        try:44            self.__prepare()45            self.collection.update({index: id_}, {'$set': data}, upsert=True)46        except Exception as e:47            print(str(e) + str(2))48    def pop(self, index=None, value=None):49        try:50            self.__prepare()51            if index is None:52                result = self.collection.find_one_and_delete({})53            else:54                result = self.collection.find_one_and_delete({index: value})55            return result56        except Exception as e:57            print(e)58    def update(self, item=None):59        try:60            self.__prepare()61            item_id = item['id']62            self.collection.update_one({'id': item_id}, {'$set': item}, upsert=True)63        except Exception as e:64            print(e)65    def find_all(self):66        self.__prepare()67        current_pos = 068        while True:69            try:70                all_docs = self.collection.find(no_cursor_timeout=True).skip(current_pos)71                for doc in all_docs:72                    current_pos += 173                    yield doc74                break75            except:76                self.__prepare()77    def find_one(self, key, value):78        self.__prepare()79        return self.collection.find_one({key: value})80    def is_in(self, index=None, value=None):81        self.__prepare()82        return self.collection.find_one({index: value}) is not None83    def restart(self):84        self.__init(self.db_name, self.collection_name)85    def __prepare(self):86        try:87            self.client.server_info()88        except:...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!!
