How to use restore_object method in localstack

Best Python code snippet using localstack_python

serial.py

Source:serial.py Github

copy

Full Screen

...15 classes = {}16 @classmethod17 def loads(cls, obj):18 di = json.loads(obj)19 return cls.restore_object(di)20 @classmethod21 def dumps(cls, obj):22 di = cls.convert_object(obj)23 return json.dumps(di)24 @classmethod25 def convert_object(cls, obj):26 """27 convert all objects to dictionaries - otherwise preserve structure28 """29 if obj == None:30 return obj31 for a in cls.allowed:32 if isinstance(obj, a):33 return obj34 if isinstance(obj, list):35 return [cls.convert_object(x) for x in obj]36 if isinstance(obj, dict):37 return {x: cls.convert_object(y) for x, y in obj.items()}38 # all other objects39 return {40 "_type": obj.__class__.__name__,41 "_content": cls.convert_object(obj.__dict__),42 }43 @classmethod44 def restore_object(cls, obj):45 """46 recreate objects bases on classes currently avaliable47 """48 if obj == None:49 return obj50 for a in cls.allowed:51 if isinstance(obj, a):52 return obj53 if isinstance(obj, list):54 return [cls.restore_object(x) for x in obj]55 if isinstance(obj, dict):56 try:57 # object restoration58 t = obj["_type"]59 model = cls.classes[t]60 ins = model.__new__(model)61 ins.__dict__.update(62 {x: cls.restore_object(y) for x, y in obj["_content"].items()}63 )64 return ins65 except KeyError:66 return {x: cls.restore_object(y) for x, y in obj.items()}67class JsonBlockField(models.TextField):68 """69 store a collection of generic objects in JSON database70 """71 def from_db_value(self, value, expression, connection, context):72 if value is None:73 return []74 return BasicSerial.loads(value)75 def to_python(self, value):76 if isinstance(value, list):77 return value78 if value is None:79 return value80 return BasicSerial.loads(value)...

Full Screen

Full Screen

restore_object.py

Source:restore_object.py Github

copy

Full Screen

...20# language governing permissions and limitations under the License.21import logging22import boto323from botocore.exceptions import ClientError24def restore_object(bucket_name, object_name, days, retrieval_type='Standard'):25 """Restore an archived S3 Glacier object in an Amazon S3 bucket26 :param bucket_name: string27 :param object_name: string28 :param days: number of days to retain restored object29 :param retrieval_type: 'Standard' | 'Expedited' | 'Bulk'30 :return: True if a request to restore archived object was submitted, otherwise31 False32 """33 # Create request to restore object34 request = {'Days': days,35 'GlacierJobParameters': {'Tier': retrieval_type}}36 # Submit the request37 s3 = boto3.client('s3')38 try:39 s3.restore_object(Bucket=bucket_name, Key=object_name, RestoreRequest=request)40 except ClientError as e:41 # NoSuchBucket, NoSuchKey, or InvalidObjectState error == the object's42 # storage class was not GLACIER43 logging.error(e)44 return False45 return True46def main():47 """Exercise restore_object()"""48 # Assign these values before running the program49 test_bucket_name = 'BUCKET_NAME'50 test_object_name = 'OBJECT_NAME'51 # Set up logging52 logging.basicConfig(level=logging.DEBUG,53 format='%(levelname)s: %(asctime)s: %(message)s')54 # Restore archived object for two days. Expedite the restoration.55 success = restore_object(test_bucket_name, test_object_name, 2, 'Expedited')56 if success:57 logging.info(f'Submitted request to restore {test_object_name} '58 f'in {test_bucket_name}')59if __name__ == '__main__':...

Full Screen

Full Screen

permit_predictor.py

Source:permit_predictor.py Github

copy

Full Screen

...39 input('Year: '),40 input('Neighborhood: ')41 ]])42 # Restore required objects43 encoder = restore_object(ENCODER_PICKLE_FILE)44 pca = restore_object(PCA_PICKLE_FILE)45 clf = restore_object(MODEL_PICKLE_FILE)46 # Transform permit application47 permit = np.concatenate((encoder.transform(permit[:, CATEGORICAL_FEATURES]).toarray(),48 permit[:, NUMERIC_FEATURES].astype(float)), axis=1)49 permit = pca.transform(permit)50 # Predict confidence that the permit will be issued51 confidence_issued = clf.predict_proba(permit)[0][1]52 print('The permit will be issued with a confidence of: ' + str(confidence_issued))53 if input("Would you want to predict another permit? (y/n)") == 'y':54 calc_confidence()55if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful