"""
def __init__(self, code, message=None, response=None):
self.code = code
- message = message or httputil.responses.get(code, "Unknown")
+ self.message = message or httputil.responses.get(code, "Unknown")
self.response = response
- Exception.__init__(self, "HTTP %d: %s" % (self.code, message))
+ super(HTTPError, self).__init__(code, message, response)
+
+ def __str__(self):
+ return "HTTP %d: %s" % (self.code, self.message)
class _RequestProxy(object):
import base64
import binascii
from contextlib import closing
+import copy
import functools
import sys
import threading
request = HTTPRequest('http://example.com', if_modified_since=http_date)
self.assertEqual(request.headers,
{'If-Modified-Since': format_timestamp(http_date)})
+
+
+class HTTPErrorTestCase(unittest.TestCase):
+ def test_copy(self):
+ e = HTTPError(403)
+ e2 = copy.copy(e)
+ self.assertIsNot(e, e2)
+ self.assertEqual(e.code, e2.code)
+
+ def test_str(self):
+ e = HTTPError(403)
+ self.assertEqual(str(e), "HTTP 403: Forbidden")
import binascii
import contextlib
+import copy
import datetime
import email.utils
import itertools
def test_missing_remote_ip(self):
resp = self.fetch("/")
self.assertEqual(resp.body, b"GET / (None)")
+
+
+class HTTPErrorTest(unittest.TestCase):
+ def test_copy(self):
+ e = HTTPError(403, reason="Go away")
+ e2 = copy.copy(e)
+ self.assertIsNot(e, e2)
+ self.assertEqual(e.status_code, e2.status_code)
+ self.assertEqual(e.reason, e2.reason)
determined automatically from ``status_code``, but can be used
to use a non-standard numeric code.
"""
- def __init__(self, status_code, log_message=None, *args, **kwargs):
+ def __init__(self, status_code=500, log_message=None, *args, **kwargs):
self.status_code = status_code
self.log_message = log_message
self.args = args