Provide href on AlreadyExistingError

See #212
This commit is contained in:
Markus Unterwaditzer 2015-06-05 00:13:36 +02:00
parent ce1c255152
commit 2170a4fce2
4 changed files with 5 additions and 4 deletions

View file

@ -42,7 +42,8 @@ class NotFoundError(PreconditionFailed):
class AlreadyExistingError(PreconditionFailed):
'''Item already exists'''
'''Item already exists.'''
existing_href = None
class WrongEtagError(PreconditionFailed):

View file

@ -138,7 +138,7 @@ class FilesystemStorage(Storage):
return fpath, get_etag_from_fileobject(f)
except OSError as e:
if e.errno == errno.EEXIST:
raise exceptions.AlreadyExistingError(item)
raise exceptions.AlreadyExistingError(existing_href=href)
else:
raise

View file

@ -41,7 +41,7 @@ class MemoryStorage(Storage):
def upload(self, item):
href = self._get_href(item)
if href in self.items:
raise exceptions.AlreadyExistingError(item)
raise exceptions.AlreadyExistingError(existing_href=href)
etag = _random_string()
self.items[href] = (etag, item)
return href, etag

View file

@ -134,7 +134,7 @@ class SingleFileStorage(Storage):
def upload(self, item):
href = item.ident
if href in self._items:
raise exceptions.AlreadyExistingError(href)
raise exceptions.AlreadyExistingError(existing_href=href)
self._items[href] = item, item.hash
return href, item.hash