comparison venv/lib/python2.7/site-packages/requests/packages/urllib3/exceptions.py @ 0:d67268158946 draft

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