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