diff options
author | Phillip J. Eby <pje@telecommunity.com> | 2010-11-02 22:28:59 (GMT) |
---|---|---|
committer | Phillip J. Eby <pje@telecommunity.com> | 2010-11-02 22:28:59 (GMT) |
commit | e159422ce9cd6cedff7b45eef5a00d7e6a2aa90c (patch) | |
tree | 440c749fa07d0aaf42a32f52e79951b35f74ab6d /Lib/wsgiref/headers.py | |
parent | 5a43f72d1b19d8018380a1aac2f1753471003cec (diff) | |
download | cpython-e159422ce9cd6cedff7b45eef5a00d7e6a2aa90c.zip cpython-e159422ce9cd6cedff7b45eef5a00d7e6a2aa90c.tar.gz cpython-e159422ce9cd6cedff7b45eef5a00d7e6a2aa90c.tar.bz2 |
Update wsgiref for PEP 3333, and fix errors introduced into the test suite by converting type() checks to isinstance().
(When WSGI specifies a built-in type, it does NOT mean "this type or a subclass" -- it means 'type(x) is SpecifiedType'.)
Diffstat (limited to 'Lib/wsgiref/headers.py')
-rw-r--r-- | Lib/wsgiref/headers.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/wsgiref/headers.py b/Lib/wsgiref/headers.py index cc01f5f..d939628 100644 --- a/Lib/wsgiref/headers.py +++ b/Lib/wsgiref/headers.py @@ -30,21 +30,20 @@ class Headers: """Manage a collection of HTTP response headers""" def __init__(self,headers): - if not isinstance(headers, list): + if type(headers) is not list: raise TypeError("Headers must be a list of name/value tuples") - self._headers = [] - for k, v in headers: - k = self._convert_string_type(k) - v = self._convert_string_type(v) - self._headers.append((k, v)) + self._headers = headers + if __debug__: + for k, v in headers: + self._convert_string_type(k) + self._convert_string_type(v) def _convert_string_type(self, value): """Convert/check value type.""" - if isinstance(value, str): + if type(value) is str: return value - assert isinstance(value, bytes), ("Header names/values must be" - " a string or bytes object (not {0})".format(value)) - return str(value, "iso-8859-1") + raise AssertionError("Header names/values must be" + " of type str (got {0})".format(repr(value))) def __len__(self): """Return the total number of headers, including duplicates.""" @@ -139,6 +138,9 @@ class Headers: suitable for direct HTTP transmission.""" return '\r\n'.join(["%s: %s" % kv for kv in self._headers]+['','']) + def __bytes__(self): + return str(self).encode('iso-8859-1') + def setdefault(self,name,value): """Return first matching header value for 'name', or 'value' |