Commits

Andriy Kornatskyy  committed 688b0c1

Minor refinements in http response status code processing.

  • Participants
  • Parent commits ac87542

Comments (0)

Files changed (1)

File src/wheezy/http/response.py

 
 # see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
 # see http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
-HTTP_STATUS = (
-    None,
+HTTP_STATUS = {
     # Informational
-    ('100 Continue', '101 Switching Protocols'),
+    100: '100 Continue',
+    101: '101 Switching Protocols',
     # Successful
-    ('200 OK', '201 Created', '202 Accepted',
-     '203 Non-Authoritative Information', '204 No Content',
-     '205 Reset Content', '206 Partial Content', '207 Multi-Status'),
+    200: '200 OK',
+    201: '201 Created',
+    202: '202 Accepted',
+    203: '203 Non-Authoritative Information',
+    204: '204 No Content',
+    205: '205 Reset Content',
+    206: '206 Partial Content',
+    207: '207 Multi-Status',
     # Redirection
-    ('300 Multiple Choices', '301 Moved Permanently', '302 Found',
-     '303 See Other', '304 Not Modified', '305 Use Proxy', None,
-     '307 Temporary Redirect'),
+    300: '300 Multiple Choices',
+    301: '301 Moved Permanently',
+    302: '302 Found',
+    303: '303 See Other',
+    304: '304 Not Modified',
+    305: '305 Use Proxy',
+    307: '307 Temporary Redirect',
     # Client Error
-    ('400 Bad Request', '401 Unauthorized', '402 Payment Required',
-     '403 Forbidden', '404 Not Found', '405 Method Not Allowed',
-     '406 Not Acceptable', '407 Proxy Authentication Required',
-     '408 Request Timeout', '409 Conflict', '410 Gone',
-     '411 Length Required', '412 Precondition Failed',
-     '413 Request Entity Too Large', '414 Request-Uri Too Long',
-     '415 Unsupported Media Type',
-     '416 Requested Range Not Satisfiable', '417 Expectation Failed'),
+    400: '400 Bad Request',
+    401: '401 Unauthorized',
+    402: '402 Payment Required',
+    403: '403 Forbidden',
+    404: '404 Not Found',
+    405: '405 Method Not Allowed',
+    406: '406 Not Acceptable',
+    407: '407 Proxy Authentication Required',
+    408: '408 Request Timeout',
+    409: '409 Conflict',
+    410: '410 Gone',
+    411: '411 Length Required',
+    412: '412 Precondition Failed',
+    413: '413 Request Entity Too Large',
+    414: '414 Request-Uri Too Long',
+    415: '415 Unsupported Media Type',
+    416: '416 Requested Range Not Satisfiable',
+    417: '417 Expectation Failed',
     # Server Error
-    ('500 Internal Server Error', '501 Not Implemented',
-     '502 Bad Gateway', '503 Service Unavailable',
-     '504 Gateway Timeout', '505 Http Version Not Supported')
-)
-
+    500: '500 Internal Server Error',
+    501: '501 Not Implemented',
+    502: '502 Bad Gateway',
+    503: '503 Service Unavailable',
+    504: '504 Gateway Timeout',
+    505: '505 Http Version Not Supported'
+}
 
 HTTP_HEADER_CACHE_CONTROL_DEFAULT = ('Cache-Control', 'private')
 HTTP_HEADER_CONTENT_LENGTH_ZERO = ('Content-Length', '0')
             >>> r.status
             '301 Moved Permanently'
         """
-        code = self.status_code
-        return HTTP_STATUS[int(code / 100)][code % 100]
+        return HTTP_STATUS[self.status_code]
 
     status = property(get_status)
 
             start_response(self.status, headers)
             return []
         buffer = self.buffer
-        content_length = sum([len(chunk) for chunk in buffer])
-        append(('Content-Length', str(content_length)))
-        start_response(self.status, headers)
+        append(('Content-Length', str(sum([len(chunk) for chunk in buffer]))))
+        start_response(HTTP_STATUS[self.status_code], headers)
         return buffer