diff --git a/eventlet/httpc.py b/eventlet/httpc.py index 63c6caf..fd39ab3 100644 --- a/eventlet/httpc.py +++ b/eventlet/httpc.py @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +import copy import datetime import httplib import os.path @@ -220,9 +221,20 @@ class _LocalParams(_Params): setattr(self, k, v) def __getattr__(self, key): + if key == '__setstate__': return return getattr(self._delegate, key) - + def __reduce__(self): + params = copy.copy(self._delegate) + kwargs = copy.copy(self.__dict__) + assert(kwargs.has_key('_delegate')) + del kwargs['_delegate'] + if hasattr(params,'aux'): del params.aux + return (_LocalParams,(params,),kwargs) + + def __setitem__(self, k, item): + setattr(self, k, item) + class ConnectionError(Exception): """Detailed exception class for reporting on http connection problems. @@ -323,6 +335,14 @@ class TemporaryRedirect(Retriable): class BadRequest(ConnectionError): """ 400 Bad Request """ pass + +class Unauthorized(ConnectionError): + """ 401 Unauthorized """ + pass + +class PaymentRequired(ConnectionError): + """ 402 Payment Required """ + pass class Forbidden(ConnectionError): @@ -339,18 +359,43 @@ class Gone(ConnectionError): """ 410 Gone """ pass +class LengthRequired(ConnectionError): + """ 411 Length Required """ + pass + +class RequestURITooLong(ConnectionError): + """ 414 Request-URI Too Long """ + pass + +class UnsupportedMediaType(ConnectionError): + """ 415 Unsupported Media Type """ + pass + +class RequestedRangeNotSatisfiable(ConnectionError): + """ 416 Requested Range Not Satisfiable """ + pass + +class ExpectationFailed(ConnectionError): + """ 417 Expectation Failed """ + pass + +class NotImplemented(ConnectionError): + """ 501 Not Implemented """ + pass class ServiceUnavailable(Retriable): """ 503 Service Unavailable """ def url(self): return self.params._delegate.url - class GatewayTimeout(Retriable): """ 504 Gateway Timeout """ def url(self): return self.params._delegate.url +class HTTPVersionNotSupported(ConnectionError): + """ 505 HTTP Version Not Supported """ + pass class InternalServerError(ConnectionError): """ 500 Internal Server Error """ @@ -389,12 +434,21 @@ status_to_error_map = { 304: NotModified, 307: TemporaryRedirect, 400: BadRequest, + 401: Unauthorized, + 402: PaymentRequired, 403: Forbidden, 404: NotFound, 410: Gone, + 411: LengthRequired, + 414: RequestURITooLong, + 415: UnsupportedMediaType, + 416: RequestedRangeNotSatisfiable, + 417: ExpectationFailed, 500: InternalServerError, + 501: NotImplemented, 503: ServiceUnavailable, 504: GatewayTimeout, + 505: HTTPVersionNotSupported, } scheme_to_factory_map = {