]> granicus.if.org Git - python/commitdiff
Fix BytesWarning with -bb in wsgiref.headers.Headers.
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 3 Jan 2009 20:28:05 +0000 (20:28 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 3 Jan 2009 20:28:05 +0000 (20:28 +0000)
Lib/test/test_wsgiref.py
Lib/wsgiref/headers.py

index cea3565343a033e70599d6d1b0196af98c211593..cfadfbdbdf2e20e26fde480246c5c158c709f9bf 100755 (executable)
@@ -426,15 +426,20 @@ class HeaderTests(TestCase):
 
         h[b"Foo"] = bytes(b"bar")
         self.assertEqual("bar", h.get("Foo"))
+        self.assertEqual("bar", h.get(b"Foo"))
 
         h.setdefault(b"Bar", b"foo")
         self.assertEqual("foo", h.get("Bar"))
+        self.assertEqual("foo", h.get(b"Bar"))
 
         h.add_header(b'content-disposition', b'attachment',
             filename=b'bud.gif')
         self.assertEqual('attachment; filename="bud.gif"',
             h.get("content-disposition"))
 
+        del h['content-disposition']
+        self.assert_(b'content-disposition' not in h)
+
 
 class ErrorHandler(BaseCGIHandler):
     """Simple handler subclass for testing BaseHandler"""
index 83074af6ca05e82b78f648d25092d3a984a56c5e..4e0076c2cfdedf800d6abad176cebd6c8d604365 100644 (file)
@@ -73,7 +73,7 @@ class Headers:
 
         Does *not* raise an exception if the header is missing.
         """
-        name = name.lower()
+        name = self._convert_string_type(name.lower())
         self._headers[:] = [kv for kv in self._headers if kv[0].lower() != name]
 
     def __getitem__(self,name):
@@ -104,13 +104,13 @@ class Headers:
         fields deleted and re-inserted are always appended to the header list.
         If no fields exist with the given name, returns an empty list.
         """
-        name = name.lower()
+        name = self._convert_string_type(name.lower())
         return [kv[1] for kv in self._headers if kv[0].lower()==name]
 
 
     def get(self,name,default=None):
         """Get the first header value for 'name', or return 'default'"""
-        name = name.lower()
+        name = self._convert_string_type(name.lower())
         for k,v in self._headers:
             if k.lower()==name:
                 return v