]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
On python3, use BytesIO instead of StringIO
authorBen Darnell <ben@bendarnell.com>
Thu, 24 Feb 2011 22:43:58 +0000 (14:43 -0800)
committerBen Darnell <ben@bendarnell.com>
Thu, 24 Feb 2011 22:43:58 +0000 (14:43 -0800)
tornado/simple_httpclient.py
tornado/web.py

index 03e26e4e36d794ca5b8b7dd1261f00b61213b963..c943284683aa9c19356b69f61e84662b9c0b6e61 100644 (file)
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 from __future__ import with_statement
 
-from cStringIO import StringIO
 from tornado.escape import utf8
 from tornado.httpclient import HTTPRequest, HTTPResponse, HTTPError, AsyncHTTPClient
 from tornado.httputil import HTTPHeaders
@@ -24,6 +23,11 @@ import time
 import urlparse
 import zlib
 
+try:
+    from io import BytesIO  # python 3
+except ImportError:
+    from cStringIO import StringIO as BytesIO  # python 2
+
 try:
     import ssl # python 2.6+
 except ImportError:
@@ -275,9 +279,9 @@ class _HTTPConnection(object):
                 # if chunks is not None, we already called streaming_callback
                 # in _on_chunk_data
                 self.request.streaming_callback(data)
-            buffer = StringIO()
+            buffer = BytesIO()
         else:
-            buffer = StringIO(data) # TODO: don't require one big string?
+            buffer = BytesIO(data) # TODO: don't require one big string?
         original_request = getattr(self.request, "original_request",
                                    self.request)
         if (self.request.follow_redirects and
index 2a3b3ac97fc64de0cd7169c2b5e7065ba49469ab..50de8fccc769e7ae865181ac30839d727674ad9c 100644 (file)
@@ -54,7 +54,6 @@ from __future__ import with_statement
 import Cookie
 import base64
 import binascii
-import cStringIO
 import calendar
 import contextlib
 import datetime
@@ -84,6 +83,11 @@ from tornado import template
 from tornado.escape import utf8
 from tornado.util import b, bytes_type
 
+try:
+    from io import BytesIO  # python 3
+except ImportError:
+    from cStringIO import StringIO as BytesIO  # python 2
+
 class RequestHandler(object):
     """Subclass this class and define get() or post() to make a handler.
 
@@ -1430,7 +1434,7 @@ class GZipContentEncoding(OutputTransform):
                 ("Content-Encoding" not in headers)
         if self._gzipping:
             headers["Content-Encoding"] = "gzip"
-            self._gzip_value = cStringIO.StringIO()
+            self._gzip_value = BytesIO()
             self._gzip_file = gzip.GzipFile(mode="w", fileobj=self._gzip_value)
             self._gzip_pos = 0
             chunk = self.transform_chunk(chunk, finishing)