A self-format exception, ClaimNotPermitted.

Change-Id: I8bc8f8d8f9f74f3e7400f00fbfcc72d2cdb945cd
This commit is contained in:
Zhihao Yuan
2013-04-15 19:49:24 -04:00
parent 3d2b7aff46
commit 95e8ffffc9
2 changed files with 10 additions and 7 deletions

View File

@@ -46,3 +46,11 @@ class ClaimDoesNotExist(DoesNotExist):
"queue %(queue)s of tenant %(tenant)s") %
dict(cid=cid, queue=queue, tenant=tenant))
super(ClaimDoesNotExist, self).__init__(msg)
class ClaimNotPermitted(NotPermitted):
def __init__(self, mid, cid):
msg = (_("Message %(mid)s is not claimed by %(cid)s") %
dict(cid=cid, mid=mid))
super(ClaimNotPermitted, self).__init__(msg)

View File

@@ -251,15 +251,10 @@ class Message(base.MessageBase):
''', id, _cid_decode(claim))
if not self.driver.affected:
raise _BadID
raise exceptions.ClaimNotPermitted(_msgid_encode(id), claim)
except _BadID:
#TODO(zyuan): use exception itself to format this
msg = (_("Attempt to delete message %(id)s "
"with a wrong claim")
% dict(id=_msgid_encode(id)))
raise exceptions.NotPermitted(msg)
raise exceptions.ClaimNotPermitted(_msgid_encode(id), claim)
class Claim(base.ClaimBase):