[svn r70] Handle status code 504

This commit is contained in:
sardonyx.linden
2007-12-13 19:34:51 -05:00
parent dfc9065e1f
commit c49670da8b
2 changed files with 36 additions and 0 deletions

View File

@@ -340,11 +340,19 @@ class Gone(ConnectionError):
""" 410 Gone """
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 InternalServerError(ConnectionError):
""" 500 Internal Server Error """
def __repr__(self):
@@ -382,6 +390,7 @@ status_to_error_map = {
410: Gone,
500: InternalServerError,
503: ServiceUnavailable,
504: GatewayTimeout,
}
scheme_to_factory_map = {

View File

@@ -336,6 +336,13 @@ class Site500(BasicSite):
req.response(500, body="screw you world")
return
class Site500(BasicSite):
def handle_request(self, req):
req.response(500, body="screw you world")
return
class TestHttpc500(TestBase, tests.TestCase):
site_class = Site500
@@ -351,7 +358,27 @@ class TestHttpc500(TestBase, tests.TestCase):
self.assertEquals(e.params.response_body, data)
self.assert_(str(e).count(data))
self.assert_(repr(e).count(data))
class Site504(BasicSite):
def handle_request(self, req):
req.response(504, body="screw you world")
class TestHttpc504(TestBase, tests.TestCase):
site_class = Site504
def base_url(self):
return 'http://localhost:31337/'
def test_post(self):
# Simply ensure that a 504 status code results in a
# GatewayTimeout. Don't bother retrying.
data = 'hello world'
self.assertRaises(httpc.GatewayTimeout,
lambda: httpc.post(self.base_url(), data=data))
class TestHttpTime(tests.TestCase):
rfc1123_time = 'Sun, 06 Nov 1994 08:49:37 GMT'
rfc850_time = 'Sunday, 06-Nov-94 08:49:37 GMT'