Package restkit :: Module errors
[hide private]
[frames] | no frames]

Source Code for Module restkit.errors

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of restkit released under the MIT license.  
 4  # See the NOTICE for more information. 
 5   
 6  """ 
 7  exception classes. 
 8  """ 
 9  from restkit.util import deprecated_property 
10                       
11 -class ResourceError(Exception):
12 """ default error class """
13 - def __init__(self, msg=None, http_code=None, response=None):
14 self.msg = msg or '' 15 self.status = http_code 16 self.response = response 17 Exception.__init__(self)
18
19 - def _status_int__get(self):
20 """ 21 The status as an integer 22 """ 23 return self.status
24 - def _status_int__set(self, http_code):
25 self.status = http_code
26 status_int = property(_status_int__get, _status_int__set, 27 doc=_status_int__get.__doc__) 28 29 status_code = deprecated_property( 30 status_int, 'status_code', 'use .status_int instead', 31 warning=False) 32
33 - def _get_message(self):
34 return self.msg
35 - def _set_message(self, msg):
36 self.msg = msg or ''
37 message = property(_get_message, _set_message) 38
39 - def __str__(self):
40 if self.msg: 41 return self.msg 42 try: 43 return str(self.__dict__) 44 except (NameError, ValueError, KeyError), e: 45 return 'Unprintable exception %s: %s' \ 46 % (self.__class__.__name__, str(e))
47 48
49 -class ResourceNotFound(ResourceError):
50 """Exception raised when no resource was found at the given url. 51 """
52
53 -class Unauthorized(ResourceError):
54 """Exception raised when an authorization is required to access to 55 the resource specified. 56 """
57
58 -class RequestFailed(ResourceError):
59 """Exception raised when an unexpected HTTP error is received in response 60 to a request. 61 62 63 The request failed, meaning the remote HTTP server returned a code 64 other than success, unauthorized, or NotFound. 65 66 The exception message attempts to extract the error 67 68 You can get the status code by e.http_code, or see anything about the 69 response via e.response. For example, the entire result body (which is 70 probably an HTML error page) is e.response.body. 71 """
72
73 -class RedirectLimit(Exception):
74 """Exception raised when the redirection limit is reached."""
75
76 -class RequestError(Exception):
77 """Exception raised when a request is malformed"""
78
79 -class InvalidUrl(Exception):
80 """ 81 Not a valid url for use with this software. 82 """
83
84 -class ResponseError(Exception):
85 """ Error raised while getting response or decompressing response stream"""
86 87
88 -class ProxyError(Exception):
89 """ raised when proxy error happend"""
90
91 -class BadStatusLine(Exception):
92 """ Exception returned by the parser when the status line is invalid""" 93 pass
94
95 -class ParserError(Exception):
96 """ Generic exception returned by the parser """ 97 pass
98