1
2
3
4
5
6
7 import restkit.errors
8 import webob.exc
9
11 """
12 Wrapper to return webob exceptions instead of restkit errors. Usefull
13 for those who want to build `WSGI <http://wsgi.org/wsgi/>`_ applications
14 speaking directly to others via HTTP.
15
16 To do it place somewhere in your application the function
17 `wrap_exceptions`::
18
19 wrap_exceptions()
20
21 It will automatically replace restkit errors by webob exceptions.
22 """
23
24 - def __init__(self, msg=None, http_code=None, response=None):
25 webob.exc.WSGIHTTPException.__init__(self)
26
27 http_code = http_code or 500
28 klass = webob.exc.status_map[http_code]
29 self.code = http_code
30 self.title = klass.title
31 self.status = '%s %s' % (self.code, self.title)
32 self.explanation = msg
33 self.response = response
34
35 self.msg = msg
36
38 """
39 The status as an integer
40 """
41 return int(self.status.split()[0])
44 status_int = property(_status_int__get, _status_int__set,
45 doc=_status_int__get.__doc__)
46
48 return self.explanation
50 self.explanation = msg or ''
51 message = property(_get_message, _set_message)
52
53 webob_exceptions = False
60