diff options
Diffstat (limited to 'fbin/file_storage')
-rw-r--r-- | fbin/file_storage/base.py | 3 | ||||
-rw-r--r-- | fbin/file_storage/exceptions.py | 8 | ||||
-rw-r--r-- | fbin/file_storage/filesystem.py | 7 | ||||
-rw-r--r-- | fbin/file_storage/s3.py | 7 |
4 files changed, 16 insertions, 9 deletions
diff --git a/fbin/file_storage/base.py b/fbin/file_storage/base.py index aa2c510..40c1588 100644 --- a/fbin/file_storage/base.py +++ b/fbin/file_storage/base.py @@ -1,7 +1,8 @@ import datetime from ..db import db, File -from .exceptions import * +from .exceptions import FileSizeError + class BaseStorage: def __init__(self, app): diff --git a/fbin/file_storage/exceptions.py b/fbin/file_storage/exceptions.py index 140221b..e949f20 100644 --- a/fbin/file_storage/exceptions.py +++ b/fbin/file_storage/exceptions.py @@ -1,2 +1,6 @@ -class StorageError(Exception): pass -class FileSizeError(StorageError): pass +class StorageError(Exception): + pass + + +class FileSizeError(StorageError): + pass diff --git a/fbin/file_storage/filesystem.py b/fbin/file_storage/filesystem.py index b132264..5b4f0a3 100644 --- a/fbin/file_storage/filesystem.py +++ b/fbin/file_storage/filesystem.py @@ -4,6 +4,7 @@ import tempfile from .base import BaseStorage + class Storage(BaseStorage): def __init__(self, app): super().__init__(app) @@ -49,7 +50,7 @@ class Storage(BaseStorage): file_path, size = self.upload_file(uploaded_file, file_hash, user) try: return self.add_file(file_hash, uploaded_file.filename, size, user, ip) - except: + except: # noqa: E722; we want to unlink and re-raise on all exceptions if os.path.exists(file_path): os.unlink(file_path) raise @@ -89,7 +90,7 @@ class Storage(BaseStorage): def store_thumbnail(self, f, stream): path = self.get_thumb_path(f) with open(path, 'wb') as f: - buf = stream.read(1024*10) + buf = stream.read(1024 * 10) while buf: f.write(buf) - buf = stream.read(1024*10) + buf = stream.read(1024 * 10) diff --git a/fbin/file_storage/s3.py b/fbin/file_storage/s3.py index 71ee1e7..b372dd7 100644 --- a/fbin/file_storage/s3.py +++ b/fbin/file_storage/s3.py @@ -7,6 +7,7 @@ from flask import request, send_file from .base import BaseStorage + class Storage(BaseStorage): def __init__(self, app): super().__init__(app) @@ -35,7 +36,7 @@ class Storage(BaseStorage): obj, size = self.upload_file(uploaded_file, file_hash, user) try: return self.add_file(file_hash, uploaded_file.filename, size, user, ip) - except: + except: # noqa: E722; we want to delete and re-raise on all exceptions obj.delete() raise @@ -44,7 +45,7 @@ class Storage(BaseStorage): bucket = self.app.config['S3_BUCKET'] obj = self.client.Object(bucket, key) try: - meta = obj.load() + obj.load() return True except botocore.exceptions.ClientError as e: if e.response['Error']['Code'] == '404': @@ -96,4 +97,4 @@ class Storage(BaseStorage): def store_thumbnail(self, f, stream): bucket = self.client.Bucket(self.app.config['S3_THUMB_BUCKET']) key = self.get_object_key(f, thumb=True) - obj = bucket.upload_fileobj(Fileobj=stream, Key=key) + bucket.upload_fileobj(Fileobj=stream, Key=key) |