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               
10 -class ResourceError(Exception):
11 """ default error class """ 12 13 status_int = None 14
15 - def __init__(self, msg=None, http_code=None, response=None):
16 self.msg = msg or '' 17 self.status_int = http_code or self.status_int 18 self.response = response 19 Exception.__init__(self)
20
21 - def _get_message(self):
22 return self.msg
23 - def _set_message(self, msg):
24 self.msg = msg or ''
25 message = property(_get_message, _set_message) 26
27 - def __str__(self):
28 if self.msg: 29 return self.msg 30 try: 31 return str(self.__dict__) 32 except (NameError, ValueError, KeyError), e: 33 return 'Unprintable exception %s: %s' \ 34 % (self.__class__.__name__, str(e))
35 36
37 -class ResourceNotFound(ResourceError):
38 """Exception raised when no resource was found at the given url. 39 """ 40 status_int = 404
41
42 -class Unauthorized(ResourceError):
43 """Exception raised when an authorization is required to access to 44 the resource specified. 45 """
46
47 -class RequestFailed(ResourceError):
48 """Exception raised when an unexpected HTTP error is received in response 49 to a request. 50 51 52 The request failed, meaning the remote HTTP server returned a code 53 other than success, unauthorized, or NotFound. 54 55 The exception message attempts to extract the error 56 57 You can get the status code by e.http_code, or see anything about the 58 response via e.response. For example, the entire result body (which is 59 probably an HTML error page) is e.response.body. 60 """
61
62 -class RedirectLimit(Exception):
63 """Exception raised when the redirection limit is reached."""
64
65 -class RequestError(Exception):
66 """Exception raised when a request is malformed"""
67
68 -class InvalidUrl(Exception):
69 """ 70 Not a valid url for use with this software. 71 """
72
73 -class ResponseError(Exception):
74 """ Error raised while getting response or decompressing response stream"""
75 76
77 -class ProxyError(Exception):
78 """ raised when proxy error happend"""
79
80 -class BadStatusLine(Exception):
81 """ Exception returned by the parser when the status line is invalid""" 82 pass
83
84 -class ParserError(Exception):
85 """ Generic exception returned by the parser """ 86 pass
87
88 -class UnexpectedEOF(object):
89 """ exception raised when remote closed the connection """
90
91 -class AlreadyRead(object):
92 """ raised when a response have already been read """
93 94 95 96 ############################# 97 # HTTP parser errors 98 ############################# 99
100 -class ParseException(Exception):
101 pass
102
103 -class NoMoreData(ParseException):
104 - def __init__(self, buf=None):
105 self.buf = buf
106 - def __str__(self):
107 return "No more data after: %r" % self.buf
108
109 -class InvalidRequestLine(ParseException):
110 - def __init__(self, req):
111 self.req = req 112 self.code = 400
113
114 - def __str__(self):
115 return "Invalid HTTP request line: %r" % self.req
116
117 -class InvalidRequestMethod(ParseException):
118 - def __init__(self, method):
119 self.method = method
120
121 - def __str__(self):
122 return "Invalid HTTP method: %r" % self.method
123
124 -class InvalidHTTPVersion(ParseException):
125 - def __init__(self, version):
126 self.version = version
127
128 - def __str__(self):
129 return "Invalid HTTP Version: %s" % self.version
130
131 -class InvalidHTTPStatus(ParseException):
132 - def __init__(self, status):
133 self.status = status
134
135 - def __str__(self):
136 return "Invalid HTTP Status: %s" % self.status
137
138 -class InvalidHeader(ParseException):
139 - def __init__(self, hdr):
140 self.hdr = hdr
141
142 - def __str__(self):
143 return "Invalid HTTP Header: %r" % self.hdr
144
145 -class InvalidHeaderName(ParseException):
146 - def __init__(self, hdr):
147 self.hdr = hdr
148
149 - def __str__(self):
150 return "Invalid HTTP header name: %r" % self.hdr
151
152 -class InvalidChunkSize(ParseException):
153 - def __init__(self, data):
154 self.data = data
155
156 - def __str__(self):
157 return "Invalid chunk size: %r" % self.data
158
159 -class ChunkMissingTerminator(ParseException):
160 - def __init__(self, term):
161 self.term = term
162
163 - def __str__(self):
164 return "Invalid chunk terminator is not '\\r\\n': %r" % self.term
165