Skip to content

Commit a95e619

Browse files
committed
Now also on Python 2.7 when setting Response Body, reject Unicode values, same as on Python 3.
1 parent efa9e37 commit a95e619

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cherrypy/_cprequest.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,8 @@ class ResponseBody(object):
774774

775775
"""The body of the HTTP response (the response entity)."""
776776

777-
if six.PY3:
778-
unicode_err = ('Page handlers MUST return bytes. Use tools.encode '
779-
'if you wish to return unicode.')
777+
unicode_err = ('Page handlers MUST return bytes. Use tools.encode '
778+
'if you wish to return unicode.')
780779

781780
def __get__(self, obj, objclass=None):
782781
if obj is None:
@@ -787,7 +786,7 @@ def __get__(self, obj, objclass=None):
787786

788787
def __set__(self, obj, value):
789788
# Convert the given value to an iterable object.
790-
if six.PY3 and isinstance(value, str):
789+
if isinstance(value, six.text_type):
791790
raise ValueError(self.unicode_err)
792791

793792
if isinstance(value, text_or_bytes):
@@ -799,10 +798,10 @@ def __set__(self, obj, value):
799798
else:
800799
# [''] doesn't evaluate to False, so replace it with [].
801800
value = []
802-
elif six.PY3 and isinstance(value, list):
801+
elif isinstance(value, list):
803802
# every item in a list must be bytes...
804803
for i, item in enumerate(value):
805-
if isinstance(item, str):
804+
if isinstance(item, six.text_type):
806805
raise ValueError(self.unicode_err)
807806
# Don't use isinstance here; io.IOBase which has an ABC takes
808807
# 1000 times as long as, say, isinstance(value, str)

0 commit comments

Comments
 (0)