Skip to content

Commit

Permalink
Merge pull request googleapis#328 from tseaver/160-doc_avoid_notfound…
Browse files Browse the repository at this point in the history
…_when_del_key

Fix googleapis#160:  document how 'NotFoundError' propagates.
  • Loading branch information
tseaver committed Nov 3, 2014
2 parents 963d0dd + 7441438 commit 2b73c7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ def delete_key(self, key):
:rtype: :class:`gcloud.storage.key.Key`
:returns: The key that was just deleted.
:raises: :class:`gcloud.storage.exceptions.NotFoundError`
:raises: :class:`gcloud.storage.exceptions.NotFoundError` (to suppress
the exception, call ``delete_keys``, passing a no-op
``on_error`` callback, e.g.::
>>> bucket.delete_keys([key], on_error=lambda key: pass)
"""
key = self.new_key(key)
self.connection.api_request(method='DELETE', path=key.path)
Expand All @@ -204,8 +208,12 @@ def delete_keys(self, keys, on_error=None):
:param keys: A list of key names or Key objects to delete.
:type on_error: a callable taking (key)
:param on_error: If not ``None``, called once for each key which
raises a ``NotFoundError``.
:param on_error: If not ``None``, called once for each key raising
:class:`gcloud.storage.exceptions.NotFoundError`;
otherwise, the exception is propagated.
:raises: :class:`gcloud.storage.exceptions.NotFoundError` (if
`on_error` is not passed).
"""
for key in keys:
try:
Expand Down
3 changes: 3 additions & 0 deletions gcloud/storage/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def delete(self):
:rtype: :class:`Key`
:returns: The key that was just deleted.
:raises: :class:`gcloud.storage.exceptions.NotFoundError`
(propagated from
:meth:`gcloud.storage.bucket.Bucket.delete_key`).
"""
return self.bucket.delete_key(self)

Expand Down

0 comments on commit 2b73c7b

Please sign in to comment.