def decode(filename, struct): for item in struct: for attr in EncodedFields: if attr in item: item[attr]=encoder.decode(item[attr], SecretKey) modfilename=filename.replace("encoded", "decoded") dest=file(modfilename, 'w') dest.write(yaml.safe_dump(struct, default_flow_style=False)) dest.close() print "Dumped to %s" % modfilename
""" script to test encoding """ if __name__=="__main__": try: import sys if len(sys.argv) < 3: raise RuntimeError("Please enter text, secret key") text, secretkey = sys.argv[1:3] from lib.encoder import encode, decode encodedtext=encode(text, secretkey) print encodedtext print "**%s**" % decode(encodedtext, secretkey) except RuntimeError, error: print "Error: %s" % str(error)
def decode_accounts(accounts, secretkey): from lib.encoder import decode for account in accounts: for attr in EncodedFields: if attr in account: account[attr]=decode(account[attr], secretkey)