def _update_data(self, process_data): with open(self._cache_file, 'r+') as f: decrypted = decrypt_file(f, self._password) json_data = json.loads(decrypted) process_data(json_data) encrypted = encrypt(json.dumps(json_data), self._password) f.seek(0) f.truncate() f.write(encrypted)
def retrieve_all_data(self, key): json_data = {} with open(self._cache_file) as f: decrypted = decrypt_file(f, self._password) json_data = json.loads(decrypted) for k in sorted(json_data): pattern = ".*".join([c for c in key]) if re.search(pattern, k): yield k, json_data[k]
def retrieve_all_data(self, key): json_data = {} with open(self._cache_file) as f: decrypted = decrypt_file(f, self._password) json_data = json.loads(decrypted) for k in sorted(json_data): pattern = ".*".join([c for c in key]) if re.search(pattern, k): yield k, json_data[k]
def _update_data(self, process_data): with open(self._cache_file, 'r+') as f: decrypted = decrypt_file(f, self._password) json_data = json.loads(decrypted) process_data(json_data) encrypted = encrypt( json.dumps(json_data), self._password) f.seek(0) f.truncate() f.write(encrypted)
def test_crypt_file(tmpdir): for key, plain, cipher in plain_cipher_pairs: plain_file = tmpdir.join("plain.txt") plain_file.write(plain) with open(str(plain_file)) as f: assert encrypt_file(f, key) == cipher cipher_file = tmpdir.join("cipher.txt") cipher_file.write(cipher) with open(str(cipher_file)) as f: assert decrypt_file(f, key) == plain
def test_crypt_file(tmpdir): for key, plain, cipher in plain_cipher_pairs: plain_file = tmpdir.join("plain.txt") plain_file.write(plain) with open(str(plain_file)) as f: assert encrypt_file(f, key) == cipher cipher_file = tmpdir.join("cipher.txt") cipher_file.write(cipher) with open(str(cipher_file)) as f: assert decrypt_file(f, key) == plain
def retrieve_data(self, key, exact=False): json_data = {} with open(self._cache_file) as f: decrypted = decrypt_file(f, self._password) json_data = json.loads(decrypted) if exact: return json_data[key] else: for k in sorted(json_data): pattern = ".*".join([c for c in key]) if re.search(pattern, k): return json_data[k] raise KeyError(u"{}(fuzzy)".format(key))
def retrieve_data(self, key, exact=False): json_data = {} with open(self._cache_file) as f: decrypted = decrypt_file(f, self._password) json_data = json.loads(decrypted) if exact: return json_data[key] else: for k in sorted(json_data): pattern = ".*".join([c for c in key]) if re.search(pattern, k): return json_data[k] raise KeyError(u"{}(fuzzy)".format(key))
def list_all_data(self): with open(self._cache_file) as f: decrypted = decrypt_file(f, self._password) return json.loads(decrypted)
def list_all_data(self): with open(self._cache_file) as f: decrypted = decrypt_file(f, self._password) return json.loads(decrypted)