Reorganization of storage.py.
Ordering: Errors, Storage interface / implementation, utils.
This commit is contained in:
parent
ffa2293549
commit
d807b7252d
@ -23,6 +23,9 @@ from werkzeug.utils import secure_filename
|
|||||||
|
|
||||||
from mediagoblin import util
|
from mediagoblin import util
|
||||||
|
|
||||||
|
########
|
||||||
|
# Errors
|
||||||
|
########
|
||||||
|
|
||||||
class Error(Exception): pass
|
class Error(Exception): pass
|
||||||
class InvalidFilepath(Error): pass
|
class InvalidFilepath(Error): pass
|
||||||
@ -31,32 +34,9 @@ class NoWebServing(Error): pass
|
|||||||
class NotImplementedError(Error): pass
|
class NotImplementedError(Error): pass
|
||||||
|
|
||||||
|
|
||||||
def clean_listy_filepath(listy_filepath):
|
###############################################
|
||||||
"""
|
# Storage interface & basic file implementation
|
||||||
Take a listy filepath (like ['dir1', 'dir2', 'filename.jpg']) and
|
###############################################
|
||||||
clean out any nastiness from it.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
>>> clean_listy_filepath([u'/dir1/', u'foo/../nasty', u'linooks.jpg'])
|
|
||||||
[u'dir1', u'foo_.._nasty', u'linooks.jpg']
|
|
||||||
|
|
||||||
Args:
|
|
||||||
- listy_filepath: a list of filepath components, mediagoblin
|
|
||||||
storage API style.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
A cleaned list of unicode objects.
|
|
||||||
"""
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class StorageInterface(object):
|
class StorageInterface(object):
|
||||||
"""
|
"""
|
||||||
@ -198,6 +178,37 @@ class BasicFileStorage(StorageInterface):
|
|||||||
'/'.join(clean_listy_filepath(filepath)))
|
'/'.join(clean_listy_filepath(filepath)))
|
||||||
|
|
||||||
|
|
||||||
|
###########
|
||||||
|
# Utilities
|
||||||
|
###########
|
||||||
|
|
||||||
|
def clean_listy_filepath(listy_filepath):
|
||||||
|
"""
|
||||||
|
Take a listy filepath (like ['dir1', 'dir2', 'filename.jpg']) and
|
||||||
|
clean out any nastiness from it.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
>>> clean_listy_filepath([u'/dir1/', u'foo/../nasty', u'linooks.jpg'])
|
||||||
|
[u'dir1', u'foo_.._nasty', u'linooks.jpg']
|
||||||
|
|
||||||
|
Args:
|
||||||
|
- listy_filepath: a list of filepath components, mediagoblin
|
||||||
|
storage API style.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A cleaned list of unicode objects.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def storage_system_from_paste_config(paste_config, storage_prefix):
|
def storage_system_from_paste_config(paste_config, storage_prefix):
|
||||||
"""
|
"""
|
||||||
Utility for setting up a storage system from the paste app config.
|
Utility for setting up a storage system from the paste app config.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user