Best Python code snippet using pytractor_python
registry.py
Source:registry.py
...25 def __init__(self, subscription_point):26 self.subscription_point = subscription_point27 28 def __call__(self, function):29 def wrapped_function(*args):30 return function(*args)31 setattr(wrapped_function, '_keys', self.subscription_point._keys)32 setattr(wrapped_function, '_path', self.subscription_point._path)33 setattr(wrapped_function, '_schema_descriptor', self.subscription_point._current_descriptor)34 return wrapped_function35def pre_commit(function):36 '''37 Annotation for pre_commit functions.38 '''39 def wrapped_function(*args):40 return function(*args)41 setattr(wrapped_function, '_group_wide', True)42 setattr(wrapped_function, '_pre_commit', True)43 return wrapped_function44def abort(function):45 '''46 Annotation for abort functions.47 '''48 def wrapped_function(*args):49 return function(*args)50 setattr(wrapped_function, '_group_wide', True)51 setattr(wrapped_function, '_abort', True)52 return wrapped_function53def commit(function):54 '''55 Annotation for commit functions.56 '''57 def wrapped_function(*args):58 return function(*args)59 setattr(wrapped_function, '_group_wide', True)60 setattr(wrapped_function, '_commit', True)61 return wrapped_function62def cached_member_data(function):63 '''64 Annotation for the function that returns the list of cached member data.65 '''66 def wrapped_function(*args):67 return function(*args)68 setattr(wrapped_function, '_cached_member_data', True)69 return wrapped_function70class subscribe(PathAnnotation):71 '''72 Annotation for a subscription pre_commit.73 '''74 def __init__(self, subscription_point):75 super(__class__, self).__init__(subscription_point)76 def __call__(self, function):77 wrapped_function = super(__class__, self).__call__(function)78 setattr(wrapped_function, '_group_wide', True)79 setattr(wrapped_function, '_subscribe', True)80 return wrapped_function...
privacyInfo.py
Source:privacyInfo.py
...23 self.url = url24 # ç®åä¸éè¦ä¸»æ¹æ³æä¾å
·ä½çè¿åï¼ éè¿ç»§æ¿äºè¿å25 def __call__(self, func):26 @wraps(func)27 def wrapped_function(*args, **kwargs):28 log.warning('æªå®ä¹æ¹æ³ï¼ä»ä¹é½ä¸ä¼å')29 return func(*args, **kwargs)30 return wrapped_function31 def token(self):32 # è·åsoa管æ§çå¨ætoken33 def soatoken(appid=self.appid, token=self.token, url=self.url):34 data = {35 'appId': appid,36 'credential': base64.b64encode(token.encode('utf-8')).decode('utf-8'),37 }38 response = requests.post(url=url, json=data)39 result = json.loads(response.text)40 status = result.get('status')41 statusCode = result.get('status').get('statusCode')42 errorMsg = status.get('errorMsg')43 if statusCode == 'EXCEPION' or result['result'] == None:44 print('è·åToken失败! è¿å失败信æ¯: ', errorMsg)45 return result['result']46 return soatoken()47 def getPrivateValue(self, **kwargs):48 name = None49 phone = None50 address = None51 if 'name' in kwargs:52 name = kwargs['name']53 if 'phone' in kwargs:54 phone = kwargs['phone']55 if 'address' in kwargs:56 address = kwargs['address']57 theToken = mainEntry.token(self)58 url = r'http://kweuat.huawei.com/ppc/common/privacy/data/batch/upsert?appid=' + self.appid59 header = {'AppId': self.appid, 'Content-Type': 'application/json', 'Authorization': theToken}60 result = {}61 if name is not None and name != '':62 name_data = {"itemList": [{"channelId": self.appid,"countryCode": "CN","plainText": name,"type": "SENDER_NAME"}],"respFieldConfig": {"respFieldList": ["ID","ANONYMIZED","HASHKEY"]}}63 response = requests.post(url=url, headers=header, json=name_data)64 respJson = json.loads(response.text)65 itemList = respJson.get('result').get('itemList')66 result['name'] = itemList[0]67 if phone is not None and phone != '':68 phone_data = {"itemList": [{"channelId": self.appid,"countryCode": "CN","plainText": phone,"type": "SENDER_PHONE"}],"respFieldConfig": {"respFieldList": ["ID","ANONYMIZED","HASHKEY"]}}69 response = requests.post(url=url, headers=header, json=phone_data)70 respJson = json.loads(response.text)71 itemList = respJson.get('result').get('itemList')72 result['phone'] = itemList[0]73 if address is not None and address != '':74 address_data = {"itemList": [{"channelId": self.appid,"countryCode": "CN","plainText": address,"type": "SENDER_ADDRESS"}],"respFieldConfig": {"respFieldList": ["ID","ANONYMIZED","HASHKEY"]}}75 response = requests.post(url=url, headers=header, json=address_data)76 respJson = json.loads(response.text)77 itemList = respJson.get('result').get('itemList')78 result['address'] = itemList[0]79 return result80# 修饰符 - å°å称å å¯ä¸ºå¯æåè¿åå±ç¤º81class name(mainEntry):82 def __call__(self, func):83 @wraps(func)84 def wrapped_function(*args, **kwargs):85 name = func(*args)86 return mainEntry.getPrivateValue(self, name=name)87 return wrapped_function88# 修饰符 - å°çµè¯å å¯ä¸ºå¯æåè¿åå±ç¤º89class phone(mainEntry):90 def __call__(self, func):91 @wraps(func)92 def wrapped_function(*args, **kwargs):93 phone = func(*args)94 return mainEntry.getPrivateValue(self, phone=phone)95 return wrapped_function96# 修饰符 - å°å°åå å¯ä¸ºå¯æåè¿åå±ç¤º97class address(mainEntry):98 def __call__(self, func):99 @wraps(func)100 def wrapped_function(*args, **kwargs):101 address = func(*args)102 return mainEntry.getPrivateValue(self, address=address)...
utils.py
Source:utils.py
...19 """20 Preserve dummy channel dim.2122 """23 def wrapped_function(img, *args, **kwargs):24 shape = img.shape25 result = func(img, *args, **kwargs)26 if len(shape) == 3 and shape[-1] == 1 and len(result.shape) == 2:27 result = np.expand_dims(result, axis=-1)28 return result2930 return wrapped_function3132def preserve_mask_channel_dim(func):33 def wrapped_function(img, *args, **kwargs):34 shape = img.shape35 if len(shape) == 2:36 img = np.expand_dims(img, axis=-1)37 result = func(img, *args, **kwargs)38 result = np.squeeze(result)39 else:40 result = func(img, *args, **kwargs)41 return result4243 return wrapped_function444546def preserve_shape(func):47 """48 Preserve shape of the image4950 """51 def wrapped_function(img, *args, **kwargs):52 shape = img.shape53 result = func(img, *args, **kwargs)54 result = result.reshape(shape)55 return result5657 return wrapped_function585960def is_rgb_image(image):61 return len(image.shape) == 3 and image.shape[-1] == 3626364def is_grayscale_image(image):65 return (len(image.shape) == 2) or (len(image.shape) == 3 and image.shape[-1] == 1)666768def clip(img, dtype, maxval):69 return np.clip(img, 0, maxval).astype(dtype)707172def clipped(func):73 @wraps(func)74 def wrapped_function(img, *args, **kwargs):75 dtype = img.dtype76 maxval = MAX_VALUES_BY_DTYPE.get(dtype, 1.0)77 return clip(func(img, *args, **kwargs), dtype, maxval)78
...
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!!