From: Christopher Allan Webber Date: Thu, 1 Sep 2011 02:36:24 +0000 (-0500) Subject: Remove the inner-classing-ness of StorageObjectWrapper X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4dea708cd3a7066ebdf260640173061cf806f872;p=mediagoblin.git Remove the inner-classing-ness of StorageObjectWrapper --- diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py index 9cae0ca6..39c9eafc 100644 --- a/mediagoblin/storage.py +++ b/mediagoblin/storage.py @@ -228,30 +228,11 @@ class BasicFileStorage(StorageInterface): return self._resolve_filepath(filepath) -class CloudFilesStorage(StorageInterface): - class StorageObjectWrapper(): - """ - Wrapper for python-cloudfiles's cloudfiles.storage_object.Object - used to circumvent the mystic `medium.jpg` corruption issue, where - we had both python-cloudfiles and PIL doing buffering on both - ends and that breaking things. - - This wrapper currently meets mediagoblin's needs for a public_store - file-like object. - """ - def __init__(self, storage_object): - self.storage_object = storage_object - - def read(self, *args, **kwargs): - return self.storage_object.read(*args, **kwargs) - - def write(self, data, *args, **kwargs): - if self.storage_object.size and type(data) == str: - data = self.read() + data - - self.storage_object.write(data, *args, **kwargs) - +# ---------------------------------------------------- +# OpenStack/Rackspace Cloud's Swift/CloudFiles support +# ---------------------------------------------------- +class CloudFilesStorage(StorageInterface): def __init__(self, **kwargs): self.param_container = kwargs.get('cloudfiles_container') self.param_user = kwargs.get('cloudfiles_user') @@ -324,6 +305,33 @@ class CloudFilesStorage(StorageInterface): self._resolve_filepath(filepath)]) +class StorageObjectWrapper(): + """ + Wrapper for python-cloudfiles's cloudfiles.storage_object.Object + used to circumvent the mystic `medium.jpg` corruption issue, where + we had both python-cloudfiles and PIL doing buffering on both + ends and that breaking things. + + This wrapper currently meets mediagoblin's needs for a public_store + file-like object. + """ + def __init__(self, storage_object): + self.storage_object = storage_object + + def read(self, *args, **kwargs): + return self.storage_object.read(*args, **kwargs) + + def write(self, data, *args, **kwargs): + if self.storage_object.size and type(data) == str: + data = self.read() + data + + self.storage_object.write(data, *args, **kwargs) + + +# ------------ +# MountStorage +# ------------ + class MountStorage(StorageInterface): """ Experimental "Mount" virtual Storage Interface