From 9b2d132005c03a4cdb4e572a7bcc5e6dd3e62c55 Mon Sep 17 00:00:00 2001 From: "enus.linden" Date: Wed, 1 Oct 2008 07:37:34 +0000 Subject: [PATCH] cleaning up some exceptions --- pyogp/lib/base/caps.py | 12 ++++++------ pyogp/lib/base/credentials.py | 3 ++- pyogp/lib/base/exc.py | 12 ++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pyogp/lib/base/caps.py b/pyogp/lib/base/caps.py index 96b7d77..277d47b 100644 --- a/pyogp/lib/base/caps.py +++ b/pyogp/lib/base/caps.py @@ -93,16 +93,16 @@ class Capability(object): headers = {"Content-type" : content_type} headers.update(custom_headers) # give the user the ability to add headers - + try: restclient = getUtility(IRESTClient) response = restclient.POST(self.public_url, serialized_payload, headers=headers) except HTTPError, e: - if e.code==404: - raise exc.ResourceNotFound(self.public_url) - else: - raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="POST") - + if e.code==404: + raise exc.ResourceNotFound(self.public_url) + else: + raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="POST") + # now deserialize the data again, we ask for a utility with the content type # as the name content_type_charset = response.headers['Content-Type'] diff --git a/pyogp/lib/base/credentials.py b/pyogp/lib/base/credentials.py index 47e1238..8f9ddfb 100644 --- a/pyogp/lib/base/credentials.py +++ b/pyogp/lib/base/credentials.py @@ -29,6 +29,7 @@ import grokcore.component as grok from interfaces import IPlainPasswordCredential, IMD5PasswordCredential from interfaces import ISerialization, ICredentialDeserialization +import exc class PlainPasswordCredential(object): """a plain password credential""" @@ -156,5 +157,5 @@ class CredentialLLSDDeserializer(grok.GlobalUtility): return PlainPasswordCredential(payload['firstname'], payload['lastname'], payload['password']) elif payload.has_key("md5-password"): return MD5PasswordCredential(payload['firstname'], payload['lastname'], md5pw=payload['md5-password']) - raise Exception("couldn't deserialize credential payload '%s' because no matching format was found!" %str(payload)) + raise exc.CredentialDeserializerNotFound(str(payload)) diff --git a/pyogp/lib/base/exc.py b/pyogp/lib/base/exc.py index 79d77ca..f7cd044 100644 --- a/pyogp/lib/base/exc.py +++ b/pyogp/lib/base/exc.py @@ -88,6 +88,18 @@ class DeserializerNotFound(DeserializationError): def __str__(self): return "deserialization for %s not supported" %self.content_type +class CredentialDeserializerNotFound(DeserializationError): + """raised if a deserializer for a certain content type couldn't be found + + stores the content type inside a ``content_type`` attribute. + """ + + def __init__(self, payload=''): + self.payload = payload + + def __str__(self): + return "deserialization for payload '%s' not supported" % (self.payload) + class DeserializationFailed(DeserializationError): """raised if a deserializer couldn't deserialize a payload