Commits

Jason R. Coombs committed 585ecd8

Backed out changeset: d6db81278553
A better fix is in cherrypy-3.2.x (2a8d3af391c4)

Comments (0)

Files changed (2)

cherrypy/_cpcompat.py

     if not isinstance(n, nativestr):
         raise TypeError("n must be a native str (got %s)" % type(n).__name__)
 
-def always_bytes(str, encoding='utf-8'):
-    if isinstance(str, unicodestr):
-        str = str.encode(encoding)
-    return str
-
 try:
     set = set
 except NameError:

cherrypy/test/webtest.py

 from unittest import *
 from unittest import _TextTestResult
 
-from cherrypy._cpcompat import basestring, ntob, py3k, HTTPConnection, HTTPSConnection, unicodestr, always_bytes
+from cherrypy._cpcompat import basestring, ntob, py3k, HTTPConnection, HTTPSConnection, unicodestr
 
 
 def interface(host):
         """Open the url with debugging support. Return status, headers, body."""
         ServerError.on = False
 
-        url = always_bytes(url)
-        body = always_bytes(body)
+        if isinstance(url, unicodestr):
+            url = url.encode('utf-8')
+        if isinstance(body, unicodestr):
+            body = body.encode('utf-8')
 
         self.url = url
         self.time = None
                 conn.putrequest(method.upper(), url)
 
             for key, value in headers:
-                conn.putheader(key, always_bytes(value, "Latin-1"))
+                conn.putheader(key, ntob(value, "Latin-1"))
             conn.endheaders()
 
             if body is not None: