#!/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
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:
# 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
import Cookie
import base64
import binascii
-import cStringIO
import calendar
import contextlib
import datetime
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.
("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)