summaryrefslogtreecommitdiff
path: root/cherrypy/lib/encoding.py
diff options
context:
space:
mode:
authorAllan Crooks <allan@amcone.net>2014-04-16 14:25:24 -0400
committerAllan Crooks <allan@amcone.net>2014-04-16 14:25:24 -0400
commit601ec96fc62f190a1d802596119aefb95fb70e51 (patch)
tree447a58ee92aaef0a17759c63804d5dc4748d8fe7 /cherrypy/lib/encoding.py
parent68c3cc406c6cb1a46a8ef45a445ea717caf8ba8f (diff)
downloadcherrypy-git-601ec96fc62f190a1d802596119aefb95fb70e51.tar.gz
Fix for recent commits which were causing a number of tests to fail in Python 3.
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r--cherrypy/lib/encoding.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py
index 59ae3b15..6d54ac8c 100644
--- a/cherrypy/lib/encoding.py
+++ b/cherrypy/lib/encoding.py
@@ -32,6 +32,27 @@ def decode(encoding=None, default_encoding='utf-8'):
if not isinstance(default_encoding, list):
default_encoding = [default_encoding]
body.attempt_charsets = body.attempt_charsets + default_encoding
+
+class UTF8StreamEncoder:
+ def __init__(self, iterator):
+ self._iterator = iterator
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return self.__next__()
+
+ def __next__(self):
+ res = next(self._iterator)
+ if isinstance(res, unicodestr):
+ res = res.encode('utf-8')
+ return res
+
+ def __getattr__(self, attr):
+ if attr.startswith('__'):
+ raise AttributeError(self, attr)
+ return getattr(self._iterator, attr)
class ResponseEncoder: