diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-11-11 10:07:56 -0200 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-11-11 10:15:32 -0200 |
commit | d2d01c13f202b6c51d01e48bf9cfef53e879f38a (patch) | |
tree | 24c3ce8b1f628eabfc76a74daea2ab9aa80b14fe /service/pixelated/support | |
parent | 58a018169dfec5899b1dca0df9cbf8ebf89a8b72 (diff) |
Some refactorings for clarity on EncryptedFileStorage
Diffstat (limited to 'service/pixelated/support')
-rw-r--r-- | service/pixelated/support/encrypted_file_storage.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/service/pixelated/support/encrypted_file_storage.py b/service/pixelated/support/encrypted_file_storage.py index 1776c62e..6d94def7 100644 --- a/service/pixelated/support/encrypted_file_storage.py +++ b/service/pixelated/support/encrypted_file_storage.py @@ -26,8 +26,7 @@ class EncryptedFileStorage(FileStorage): def temp_storage(self, name=None): name = name or "%s.tmp" % random_name() path = os.path.join(self.folder, name) - tempstore = EncryptedFileStorage(path, self.masterkey) - return tempstore.create() + return EncryptedFileStorage(path, self.masterkey).create() def file_length(self, name): f = self._open_encrypted_file(name) @@ -36,19 +35,15 @@ class EncryptedFileStorage(FileStorage): return length def _encrypt_index_on_close(self, name): - def wrapper(file_struct): - file_struct.seek(0) - content = file_struct.file.read() + def wrapper(struct_file): + struct_file.seek(0) + content = struct_file.file.read() encrypted_content = self.f.encrypt(content) - with open(self._fpath(name), 'w+b') as _f: - _f.write(encrypted_content) + with open(self._fpath(name), 'w+b') as f: + f.write(encrypted_content) return wrapper - def _decrypt(self, file_content): - return self.f.decrypt(file_content) if len(file_content) else file_content - def _open_encrypted_file(self, name, onclose=lambda x: None): file_content = open(self._fpath(name), "rb").read() - decrypted = self._decrypt(file_content) - f = BufferFile(buffer(decrypted), name=name, onclose=onclose) - return f + decrypted = self.f.decrypt(file_content) + return BufferFile(buffer(decrypted), name=name, onclose=onclose) |