Skip to content

Commit

Permalink
Move UploadNotAllowed exception into separate module
Browse files Browse the repository at this point in the history
Also, add it back to the public API.

It has to be importable, otherwise it is hard to catch it :-)

modified:   src/flask_uploads/__init__.py
new file:   src/flask_uploads/exceptions.py
modified:   src/flask_uploads/flask_uploads.py
  • Loading branch information
jugmac00 committed Jun 30, 2020
1 parent c7e08e5 commit 7a6c541
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/flask_uploads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from .flask_uploads import lowercase_ext
from .flask_uploads import config_for_set

from .exceptions import UploadNotAllowed

from .flask_uploads import ALL
from .flask_uploads import AllExcept
from .flask_uploads import TEXT
Expand Down Expand Up @@ -52,4 +54,5 @@
"SOURCE",
"EXECUTABLES",
"DEFAULTS",
"UploadNotAllowed",
]
6 changes: 6 additions & 0 deletions src/flask_uploads/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class UploadNotAllowed(Exception):
"""This exception is raised if the upload was not allowed.
You should catch it in your view code and
display an appropriate message to the user.
"""
9 changes: 2 additions & 7 deletions src/flask_uploads/flask_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from werkzeug.datastructures import FileStorage
from werkzeug.utils import secure_filename

from .exceptions import UploadNotAllowed

PY3 = sys.version_info[0] == 3

if PY3:
Expand Down Expand Up @@ -91,13 +93,6 @@
DEFAULTS = TEXT + DOCUMENTS + IMAGES + DATA


class UploadNotAllowed(Exception):
"""
This exception is raised if the upload was not allowed. You should catch
it in your view code and display an appropriate message to the user.
"""


def extension(filename):
ext = os.path.splitext(filename)[1]
if ext.startswith('.'):
Expand Down

0 comments on commit 7a6c541

Please sign in to comment.