gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / requests / packages / urllib3 / exceptions.py @ 564
History | View | Annotate | Download (5.31 KB)
1 |
from __future__ import absolute_import |
---|---|
2 |
# Base Exceptions
|
3 |
|
4 |
|
5 |
class HTTPError(Exception): |
6 |
"Base exception used by this module."
|
7 |
pass
|
8 |
|
9 |
|
10 |
class HTTPWarning(Warning): |
11 |
"Base warning used by this module."
|
12 |
pass
|
13 |
|
14 |
|
15 |
class PoolError(HTTPError): |
16 |
"Base exception for errors caused within a pool."
|
17 |
def __init__(self, pool, message): |
18 |
self.pool = pool
|
19 |
HTTPError.__init__(self, "%s: %s" % (pool, message)) |
20 |
|
21 |
def __reduce__(self): |
22 |
# For pickling purposes.
|
23 |
return self.__class__, (None, None) |
24 |
|
25 |
|
26 |
class RequestError(PoolError): |
27 |
"Base exception for PoolErrors that have associated URLs."
|
28 |
def __init__(self, pool, url, message): |
29 |
self.url = url
|
30 |
PoolError.__init__(self, pool, message)
|
31 |
|
32 |
def __reduce__(self): |
33 |
# For pickling purposes.
|
34 |
return self.__class__, (None, self.url, None) |
35 |
|
36 |
|
37 |
class SSLError(HTTPError): |
38 |
"Raised when SSL certificate fails in an HTTPS connection."
|
39 |
pass
|
40 |
|
41 |
|
42 |
class ProxyError(HTTPError): |
43 |
"Raised when the connection to a proxy fails."
|
44 |
pass
|
45 |
|
46 |
|
47 |
class DecodeError(HTTPError): |
48 |
"Raised when automatic decoding based on Content-Type fails."
|
49 |
pass
|
50 |
|
51 |
|
52 |
class ProtocolError(HTTPError): |
53 |
"Raised when something unexpected happens mid-request/response."
|
54 |
pass
|
55 |
|
56 |
|
57 |
#: Renamed to ProtocolError but aliased for backwards compatibility.
|
58 |
ConnectionError = ProtocolError |
59 |
|
60 |
|
61 |
# Leaf Exceptions
|
62 |
|
63 |
class MaxRetryError(RequestError): |
64 |
"""Raised when the maximum number of retries is exceeded.
|
65 |
|
66 |
:param pool: The connection pool
|
67 |
:type pool: :class:`~urllib3.connectionpool.HTTPConnectionPool`
|
68 |
:param string url: The requested Url
|
69 |
:param exceptions.Exception reason: The underlying error
|
70 |
|
71 |
"""
|
72 |
|
73 |
def __init__(self, pool, url, reason=None): |
74 |
self.reason = reason
|
75 |
|
76 |
message = "Max retries exceeded with url: %s (Caused by %r)" % (
|
77 |
url, reason) |
78 |
|
79 |
RequestError.__init__(self, pool, url, message)
|
80 |
|
81 |
|
82 |
class HostChangedError(RequestError): |
83 |
"Raised when an existing pool gets a request for a foreign host."
|
84 |
|
85 |
def __init__(self, pool, url, retries=3): |
86 |
message = "Tried to open a foreign host with url: %s" % url
|
87 |
RequestError.__init__(self, pool, url, message)
|
88 |
self.retries = retries
|
89 |
|
90 |
|
91 |
class TimeoutStateError(HTTPError): |
92 |
""" Raised when passing an invalid state to a timeout """
|
93 |
pass
|
94 |
|
95 |
|
96 |
class TimeoutError(HTTPError): |
97 |
""" Raised when a socket timeout error occurs.
|
98 |
|
99 |
Catching this error will catch both :exc:`ReadTimeoutErrors
|
100 |
<ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.
|
101 |
"""
|
102 |
pass
|
103 |
|
104 |
|
105 |
class ReadTimeoutError(TimeoutError, RequestError): |
106 |
"Raised when a socket timeout occurs while receiving data from a server"
|
107 |
pass
|
108 |
|
109 |
|
110 |
# This timeout error does not have a URL attached and needs to inherit from the
|
111 |
# base HTTPError
|
112 |
class ConnectTimeoutError(TimeoutError): |
113 |
"Raised when a socket timeout occurs while connecting to a server"
|
114 |
pass
|
115 |
|
116 |
|
117 |
class NewConnectionError(ConnectTimeoutError, PoolError): |
118 |
"Raised when we fail to establish a new connection. Usually ECONNREFUSED."
|
119 |
pass
|
120 |
|
121 |
|
122 |
class EmptyPoolError(PoolError): |
123 |
"Raised when a pool runs out of connections and no more are allowed."
|
124 |
pass
|
125 |
|
126 |
|
127 |
class ClosedPoolError(PoolError): |
128 |
"Raised when a request enters a pool after the pool has been closed."
|
129 |
pass
|
130 |
|
131 |
|
132 |
class LocationValueError(ValueError, HTTPError): |
133 |
"Raised when there is something wrong with a given URL input."
|
134 |
pass
|
135 |
|
136 |
|
137 |
class LocationParseError(LocationValueError): |
138 |
"Raised when get_host or similar fails to parse the URL input."
|
139 |
|
140 |
def __init__(self, location): |
141 |
message = "Failed to parse: %s" % location
|
142 |
HTTPError.__init__(self, message)
|
143 |
|
144 |
self.location = location
|
145 |
|
146 |
|
147 |
class ResponseError(HTTPError): |
148 |
"Used as a container for an error reason supplied in a MaxRetryError."
|
149 |
GENERIC_ERROR = 'too many error responses'
|
150 |
SPECIFIC_ERROR = 'too many {status_code} error responses'
|
151 |
|
152 |
|
153 |
class SecurityWarning(HTTPWarning): |
154 |
"Warned when perfoming security reducing actions"
|
155 |
pass
|
156 |
|
157 |
|
158 |
class SubjectAltNameWarning(SecurityWarning): |
159 |
"Warned when connecting to a host with a certificate missing a SAN."
|
160 |
pass
|
161 |
|
162 |
|
163 |
class InsecureRequestWarning(SecurityWarning): |
164 |
"Warned when making an unverified HTTPS request."
|
165 |
pass
|
166 |
|
167 |
|
168 |
class SystemTimeWarning(SecurityWarning): |
169 |
"Warned when system time is suspected to be wrong"
|
170 |
pass
|
171 |
|
172 |
|
173 |
class InsecurePlatformWarning(SecurityWarning): |
174 |
"Warned when certain SSL configuration is not available on a platform."
|
175 |
pass
|
176 |
|
177 |
|
178 |
class SNIMissingWarning(HTTPWarning): |
179 |
"Warned when making a HTTPS request without SNI available."
|
180 |
pass
|
181 |
|
182 |
|
183 |
class ResponseNotChunked(ProtocolError, ValueError): |
184 |
"Response needs to be chunked in order to read it as chunks."
|
185 |
pass
|
186 |
|
187 |
|
188 |
class ProxySchemeUnknown(AssertionError, ValueError): |
189 |
"ProxyManager does not support the supplied scheme"
|
190 |
# TODO(t-8ch): Stop inheriting from AssertionError in v2.0.
|
191 |
|
192 |
def __init__(self, scheme): |
193 |
message = "Not supported proxy scheme %s" % scheme
|
194 |
super(ProxySchemeUnknown, self).__init__(message) |
195 |
|
196 |
|
197 |
class HeaderParsingError(HTTPError): |
198 |
"Raised by assert_header_parsing, but we convert it to a log.warning statement."
|
199 |
def __init__(self, defects, unparsed_data): |
200 |
message = '%s, unparsed data: %r' % (defects or 'Unknown', unparsed_data) |
201 |
super(HeaderParsingError, self).__init__(message) |