コード例 #1
0
ファイル: __main__.py プロジェクト: hzheng/cachette
    def __init__(self, cache_file, password):
        self._cache_file = cache_file
        self._password = password

        if not os.path.isfile(cache_file) or os.path.getsize(cache_file) < 2:
            # initialize a non-existent or a nearly-empty file
            with open(cache_file, 'w') as f:
                f.write(encrypt("{}", password))
コード例 #2
0
ファイル: __main__.py プロジェクト: hzheng/cachette
    def __init__(self, cache_file, password):
        self._cache_file = cache_file
        self._password = password

        if not os.path.isfile(cache_file) or os.path.getsize(cache_file) < 2:
            # initialize a non-existent or a nearly-empty file
            with open(cache_file, 'w') as f:
                f.write(encrypt("{}", password))
コード例 #3
0
ファイル: __main__.py プロジェクト: hzheng/cachette
 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)
コード例 #4
0
ファイル: __main__.py プロジェクト: hzheng/cachette
 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)
コード例 #5
0
ファイル: test_crypt.py プロジェクト: hzheng/cachette
def test_crypt_str():
    for key, plain, cipher in plain_cipher_pairs:
        assert encrypt(plain, key) == cipher
        assert decrypt(cipher, key) == plain
コード例 #6
0
ファイル: test_crypt.py プロジェクト: hzheng/cachette
def test_crypt_str():
    for key, plain, cipher in plain_cipher_pairs:
        assert encrypt(plain, key) == cipher
        assert decrypt(cipher, key) == plain