diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2018-08-17 14:44:14 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2018-08-17 14:44:14 -0400 |
commit | a95e619f156de6002be26a062fec0eead90cef25 (patch) | |
tree | 7a172727a19f0c045150266f8656092228af73a3 | |
parent | efa9e3722a763bb5a2c51199d6c0d9f90df8f90c (diff) | |
download | cherrypy-git-a95e619f156de6002be26a062fec0eead90cef25.tar.gz |
Now also on Python 2.7 when setting Response Body, reject Unicode values, same as on Python 3.
-rw-r--r-- | cherrypy/_cprequest.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/cherrypy/_cprequest.py b/cherrypy/_cprequest.py index 739ad2e8..b53364af 100644 --- a/cherrypy/_cprequest.py +++ b/cherrypy/_cprequest.py @@ -774,9 +774,8 @@ class ResponseBody(object): """The body of the HTTP response (the response entity).""" - if six.PY3: - unicode_err = ('Page handlers MUST return bytes. Use tools.encode ' - 'if you wish to return unicode.') + unicode_err = ('Page handlers MUST return bytes. Use tools.encode ' + 'if you wish to return unicode.') def __get__(self, obj, objclass=None): if obj is None: @@ -787,7 +786,7 @@ class ResponseBody(object): def __set__(self, obj, value): # Convert the given value to an iterable object. - if six.PY3 and isinstance(value, str): + if isinstance(value, six.text_type): raise ValueError(self.unicode_err) if isinstance(value, text_or_bytes): @@ -799,10 +798,10 @@ class ResponseBody(object): else: # [''] doesn't evaluate to False, so replace it with []. value = [] - elif six.PY3 and isinstance(value, list): + elif isinstance(value, list): # every item in a list must be bytes... for i, item in enumerate(value): - if isinstance(item, str): + if isinstance(item, six.text_type): raise ValueError(self.unicode_err) # Don't use isinstance here; io.IOBase which has an ABC takes # 1000 times as long as, say, isinstance(value, str) |