How to use asdict method in localstack

Best Python code snippet using localstack_python

DaemonHelper.py

Source:DaemonHelper.py Github

copy

Full Screen

...227 def save_wallet(self, filename):228 if not self.verify_wallet():229 raise WalletException("Could not be saved. Invalid wallet.")230 with open(filename, "wb") as outfile:231 address_items_asdict = [a._asdict() for a in self._address_items]232 for a in address_items_asdict:233 a["address"] = a.pop("qaddress") # for backwards compatibility with webwallet234 a.pop('encrypted') # ver1 wallet AddressItems do not have encrypted field.235 slave_group_asdict = []236 for slaves in a['slaves']:237 slave_list_asdict = []238 for i in range(len(slaves)):239 slave_list_asdict.append(slaves[i]._asdict())240 slave_list_asdict[i]["address"] = slave_list_asdict[i].pop("qaddress")241 slave_group_asdict.append(slave_list_asdict)242 a['slaves'] = slave_group_asdict243 output = {244 "addresses": address_items_asdict,245 "encrypted": self.encrypted,246 "version": 1247 }248 data_out = simplejson.dumps(output).encode('ascii')249 outfile.write(data_out)250 def decrypt_address_item(self, item: AddressItem, key: str):251 cipher = AESHelper(key)252 tmp = item._asdict()253 tmp['hexseed'] = cipher.decrypt(tmp['hexseed']).decode()254 tmp['mnemonic'] = cipher.decrypt(tmp['mnemonic']).decode()255 tmp['encrypted'] = False256 return AddressItem(**tmp)257 def decrypt_item(self, index: int, key: str):258 cipher = AESHelper(key)259 tmp = self._address_items[index]._asdict() # noqa260 tmp['hexseed'] = cipher.decrypt(tmp['hexseed']).decode()261 tmp['mnemonic'] = cipher.decrypt(tmp['mnemonic']).decode()262 slave_group_asdict = []263 for slaves in tmp['slaves']:264 slave_list_asdict = []265 for i in range(len(slaves)):266 slave_list_asdict.append(slaves[i]._asdict()) # noqa267 slave_list_asdict[i]['hexseed'] = cipher.decrypt(slave_list_asdict[i]['hexseed']).decode()268 slave_list_asdict[i]['mnemonic'] = cipher.decrypt(slave_list_asdict[i]['mnemonic']).decode()269 slave_list_asdict[i]['encrypted'] = False270 slave_list_asdict[i] = AddressItem(**slave_list_asdict[i])271 slave_group_asdict.append(slave_list_asdict)272 tmp['slaves'] = slave_group_asdict273 tmp['encrypted'] = False274 self._address_items[index] = AddressItem(**tmp)275 def decrypt_item_ver0(self, index: int, key: str):276 cipher = AESHelper(key)277 tmp = self._address_items[index]._asdict() # noqa278 tmp['qaddress'] = cipher.decrypt(tmp['qaddress']).decode()279 tmp['hexseed'] = cipher.decrypt(tmp['hexseed']).decode()280 tmp['mnemonic'] = cipher.decrypt(tmp['mnemonic']).decode()281 tmp['encrypted'] = False282 self._address_items[index] = AddressItem(**tmp)283 def encrypt_address_item(self, item: AddressItem, key: str):284 cipher = AESHelper(key)285 tmp = item._asdict() # noqa286 tmp['hexseed'] = cipher.encrypt(tmp['hexseed'].encode())287 tmp['mnemonic'] = cipher.encrypt(tmp['mnemonic'].encode())288 tmp['encrypted'] = True289 return AddressItem(**tmp)290 def encrypt_item(self, index: int, key: str):291 cipher = AESHelper(key)292 tmp = self._address_items[index]._asdict() # noqa293 tmp['hexseed'] = cipher.encrypt(tmp['hexseed'].encode())294 tmp['mnemonic'] = cipher.encrypt(tmp['mnemonic'].encode())295 slave_group_asdict = []296 for slaves in tmp['slaves']:297 slave_list_asdict = []298 for i in range(len(slaves)):299 slave_list_asdict.append(slaves[i]._asdict()) # noqa300 slave_list_asdict[i]['hexseed'] = cipher.encrypt(slave_list_asdict[i]['hexseed'].encode())301 slave_list_asdict[i]['mnemonic'] = cipher.encrypt(slave_list_asdict[i]['mnemonic'].encode())302 slave_list_asdict[i]['encrypted'] = True303 slave_list_asdict[i] = AddressItem(**slave_list_asdict[i])304 slave_group_asdict.append(slave_list_asdict)305 tmp['slaves'] = slave_group_asdict306 tmp['encrypted'] = True307 self._address_items[index] = AddressItem(**tmp)308 def decrypt(self, password: str, first_address_only: bool=False):309 if self.encrypted_partially:310 raise WalletEncryptionError("Some addresses are already decrypted. Please re-encrypt all addresses before"311 "running decrypt().")312 elif not self.encrypted:313 raise WalletEncryptionError("Wallet is already unencrypted.")...

Full Screen

Full Screen

test_namedtuple.py

Source:test_namedtuple.py Github

copy

Full Screen

...7except ImportError:8 class Value(tuple):9 def __new__(cls, *args):10 return tuple.__new__(cls, args)11 def _asdict(self):12 return {'value': self[0]}13 class Point(tuple):14 def __new__(cls, *args):15 return tuple.__new__(cls, args)16 def _asdict(self):17 return {'x': self[0], 'y': self[1]}18else:19 Value = namedtuple('Value', ['value'])20 Point = namedtuple('Point', ['x', 'y'])21class DuckValue(object):22 def __init__(self, *args):23 self.value = Value(*args)24 def _asdict(self):25 return self.value._asdict()26class DuckPoint(object):27 def __init__(self, *args):28 self.point = Point(*args)29 def _asdict(self):30 return self.point._asdict()31class DeadDuck(object):32 _asdict = None33class DeadDict(dict):34 _asdict = None35CONSTRUCTORS = [36 lambda v: v,37 lambda v: [v],38 lambda v: [{'key': v}],39]40class TestNamedTuple(unittest.TestCase):41 def test_namedtuple_dumps(self):42 for v in [Value(1), Point(1, 2), DuckValue(1), DuckPoint(1, 2)]:43 d = v._asdict()44 self.assertEqual(d, json.loads(json.dumps(v)))45 self.assertEqual(46 d,47 json.loads(json.dumps(v, namedtuple_as_object=True)))48 self.assertEqual(d, json.loads(json.dumps(v, tuple_as_array=False)))49 self.assertEqual(50 d,51 json.loads(json.dumps(v, namedtuple_as_object=True,52 tuple_as_array=False)))53 def test_namedtuple_dumps_false(self):54 for v in [Value(1), Point(1, 2)]:55 l = list(v)56 self.assertEqual(57 l,58 json.loads(json.dumps(v, namedtuple_as_object=False)))59 self.assertRaises(TypeError, json.dumps, v,60 tuple_as_array=False, namedtuple_as_object=False)61 def test_namedtuple_dump(self):62 for v in [Value(1), Point(1, 2), DuckValue(1), DuckPoint(1, 2)]:63 d = v._asdict()64 sio = StringIO()65 json.dump(v, sio)66 self.assertEqual(d, json.loads(sio.getvalue()))67 sio = StringIO()68 json.dump(v, sio, namedtuple_as_object=True)69 self.assertEqual(70 d,71 json.loads(sio.getvalue()))72 sio = StringIO()73 json.dump(v, sio, tuple_as_array=False)74 self.assertEqual(d, json.loads(sio.getvalue()))75 sio = StringIO()76 json.dump(v, sio, namedtuple_as_object=True,77 tuple_as_array=False)...

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