aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/storage.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-04-09 11:45:38 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-04-09 11:45:38 -0500
commit770c12be8d29ab0d6960bbc20ca5c58363da753d (patch)
tree5fecf906620cfd6b23975762972310f851acf674 /mediagoblin/storage.py
parenta6b378ef4d8a30eb1c832ea131167c8f69fc7d34 (diff)
downloadmediagoblin-770c12be8d29ab0d6960bbc20ca5c58363da753d.tar.lz
mediagoblin-770c12be8d29ab0d6960bbc20ca5c58363da753d.tar.xz
mediagoblin-770c12be8d29ab0d6960bbc20ca5c58363da753d.zip
Raise a specific error if a filename component can't be resolved into anything.
Diffstat (limited to 'mediagoblin/storage.py')
-rw-r--r--mediagoblin/storage.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py
index c06cb3a8..805be84c 100644
--- a/mediagoblin/storage.py
+++ b/mediagoblin/storage.py
@@ -18,6 +18,10 @@
from werkzeug.utils import secure_filename
+class Error(Exception): pass
+class InvalidFilepath(Error): pass
+
+
def clean_listy_filepath(listy_filepath):
"""
Take a listy filepath (like ['dir1', 'dir2', 'filename.jpg']) and
@@ -34,8 +38,14 @@ def clean_listy_filepath(listy_filepath):
Returns:
A cleaned list of unicode objects.
"""
- return [
+ cleaned_filepath = [
unicode(secure_filename(filepath))
for filepath in listy_filepath]
+ if u'' in cleaned_filepath:
+ raise InvalidFilepath(
+ "A filename component could not be resolved into a usable name.")
+
+ return cleaned_filepath
+