Best Python code snippet using localstack_python
LSB.py
Source:LSB.py
...6from PIL import Image7def plus(string):8 # Python zfill() æ¹æ³è¿åæå®é¿åº¦çå符串ï¼åå符串å³å¯¹é½ï¼åé¢å¡«å
0ã9 return string.zfill(8)10def get_key(strr):11 # è·åè¦éèçæ件å
容12 with open(strr, "rb") as f:13 s = f.read()14 string = ""15 for i in range(len(s)):16 # é个åèå°è¦éèçæ件å
容转æ¢ä¸ºäºè¿å¶ï¼å¹¶æ¼æ¥èµ·æ¥17 # 1.å
ç¨ord()å½æ°å°sçå
容é个转æ¢ä¸ºasciiç 18 # 2.使ç¨bin()å½æ°å°åè¿å¶çasciiç 转æ¢ä¸ºäºè¿å¶19 # 3.ç±äºbin()å½æ°è½¬æ¢äºè¿å¶åï¼äºè¿å¶å符串çåé¢ä¼æ"0b"æ¥è¡¨ç¤ºè¿ä¸ªå符串æ¯äºè¿å¶å½¢å¼ï¼æ以ç¨replace()æ¿æ¢ä¸ºç©º20 # 4.åç±äºasciiç 转æ¢äºè¿å¶åæ¯ä¸ä½ï¼èæ£å¸¸æ
åµä¸æ¯ä¸ªå符ç±8ä½äºè¿å¶ç»æï¼æ以使ç¨èªå®ä¹å½æ°pluså°å
¶å¡«å
为8ä½21 string = string + "" + plus(bin(s[i]).replace('0b', ''))22 return string23def mod(x, y):24 return x % y25def opreations(n, key, count):26 e = 827 print(count, len(key))28 return n - mod(n, (2**e)) + (int(key[count])*(2**e))29# str1为载ä½å¾çè·¯å¾ï¼str2为éåæ件ï¼str3为å å¯å¾çä¿åçè·¯å¾30def func(str1, str2, str3):31 im = Image.open(str1)32 # è·åå¾çç宽åé«33 width, height = im.size[0], im.size[1]34 print("width:" + str(width))35 print("height:" + str(height))36 count = 037 # è·åéè¦éèçä¿¡æ¯38 key = get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2) + get_key(str2)39 keylen = len(key)40 for h in range(height):41 for w in range(width):42 pixel = im.getpixel((w, h))43 a = pixel[0]44 b = pixel[1]45 c = pixel[2]46 if count == keylen:47 break48 # ä¸é¢çæä½æ¯å°ä¿¡æ¯éèè¿å»49 # åå«å°æ¯ä¸ªåç´ ç¹çRGBå¼ä½2ï¼è¿æ ·å¯ä»¥å»ææä½ä½çå¼50 # åä»éè¦éèçä¿¡æ¯ä¸ååºä¸ä½ï¼è½¬æ¢ä¸ºæ´å51 # 两å¼ç¸å ï¼å°±æä¿¡æ¯éèèµ·æ¥äº52 a = opreations(a, key, count)...
yamlget
Source:yamlget
...14import os15import sys16from optparse import OptionParser17import yaml18def get_key(fullkey, data):19 """20 Get the requested key from the parsed data.21 :param fullkey: the key to get, nested values can be accessed by using a22 colon (":") as the separator23 :param data: the parsed data, from yaml.load()24 Examples:25 >>> data = {26 ... 'bool': [True, False, True, False],27 ... 'dict': {'hp': 13, 'sp': 5},28 ... 'float': 3.14159,29 ... 'int': 42,30 ... 'list': ['LITE', 'RES_ACID', 'SUS_DEXT'],31 ... 'none': [None, None],32 ... 'text': "The Set of Gauntlets 'Pauraegen'",33 ... }34 >>> get_key('bool', data)35 [True, False, True, False]36 >>> get_key('bool:2', data)37 False38 >>> get_key('dict', data)39 {'hp': 13, 'sp': 5}40 >>> get_key('dict:hp', data)41 1342 >>> get_key('float', data)43 3.1415944 >>> get_key('int', data)45 4246 >>> get_key('list', data)47 ['LITE', 'RES_ACID', 'SUS_DEXT']48 >>> get_key('list:2', data)49 'RES_ACID'50 >>> get_key('list:2:5', data)51 'RES_ACID'52 >>> get_key('none', data)53 [None, None]54 >>> get_key('none:1', data)55 >>> get_key('text', data)56 "The Set of Gauntlets 'Pauraegen'"57 >>> get_key('2', ['item1', 'item2', 'item3'])58 'item2'59 """60 value = data61 while value is not None:62 key, _sep, fullkey = fullkey.partition(":")63 if isinstance(value, list):64 try:65 key = int(key)66 except TypeError:67 print("Wrong key format: %s, it should be an integer" % key,68 file=sys.stderr)69 sys.exit(1)70 value = value[key - 1] # start at 1, not 071 elif isinstance(value, dict):72 value = value.get(key)73 else:74 break # we've got the value now75 if not fullkey:76 break # can't go any further77 return value78def main():79 parser = OptionParser(usage="%prog <key> <yaml-file>")80 args = parser.parse_args()[1]81 if len(args) != 2:82 parser.error("wrong number of arguments")83 fullkey, filepath = args84 if not os.path.exists(filepath):85 parser.error("no such file: %s" % filepath)86 with open(filepath) as yamlfile:87 data = yaml.safe_load_all(yamlfile).next()88 #from pprint import pprint; pprint(data)89 value = get_key(fullkey, data)90 if value is not None:91 print(value)92if __name__ == "__main__":...
env_variables.py
Source:env_variables.py
...12 project_folder = Path(__file__).parent.absolute()13 envPath = find_dotenv(os.path.join(project_folder, '.env'))14 except Exception:15 print(".env not found")16azureSubscriptionId = get_key(envPath, "SUBSCRIPTION_ID")17resourceLocation = get_key(envPath, "RESOURCE_LOCATION")18resourceGroupName = get_key(envPath, "RESOURCE_GROUP")19acrServiceName = get_key(envPath, "ACR_SERVICE_NAME")20acrServiceFullName = get_key(envPath, "ACR_SERVICE_FULL_NAME")21iotHubServiceName = get_key(envPath, "IOT_HUB_SERVICE_NAME")22iotDeviceId = get_key(envPath, "IOT_DEVICE_ID")23mediaServiceName = get_key(envPath, "AMS_ACCOUNT")24storageServiceName = get_key(envPath, "STORAGE_SERVICE_NAME")25acrUserName = get_key(envPath, "CONTAINER_REGISTRY_USERNAME_myacr")26acrPassword = get_key(envPath, "CONTAINER_REGISTRY_PASSWORD_myacr")27containerImageName = get_key(envPath, "CONTAINER_IMAGE_NAME")28debugOutputFolder = get_key(envPath, "DEBUG_OUTPUT_FOLDER")29aadTenantId = get_key(envPath, "AAD_TENANT_ID")30aadServicePrincipalId = get_key(envPath, "AAD_SERVICE_PRINCIPAL_ID")31aadServicePrincipalSecret = get_key(envPath, "AAD_SERVICE_PRINCIPAL_SECRET")32iotHubConnString = get_key(envPath, "IOT_HUB_CONN_STRING")33iotEdgeDeviceConnString = get_key(envPath, "IOT_EDGE_DEVICE_CONN_STRING")34sshstring = get_key(envPath, "SSH_STRING")35lvaExtensionPath = get_key(envPath, "LVA_EXTENSION_PATH")36userName = get_key(envPath, "USERNAME")37lvaSamplePath = get_key(envPath, "LVA_SAMPLE_PATH")38topologyFile = get_key(envPath, "TOPOLOGY_FILE")39graphInstanceName = get_key(envPath, "GRAPH_INSTANCE_NAME")40topologyName = get_key(envPath, "TOPOLOGY_NAME")...
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!!