Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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]
Exemplo n.º 3
0
 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]
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
 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))
Exemplo n.º 9
0
 def list_all_data(self):
     with open(self._cache_file) as f:
         decrypted = decrypt_file(f, self._password)
         return json.loads(decrypted)
Exemplo n.º 10
0
 def list_all_data(self):
     with open(self._cache_file) as f:
         decrypted = decrypt_file(f, self._password)
         return json.loads(decrypted)