From: Ben Darnell Date: Sun, 15 May 2011 23:29:19 +0000 (-0700) Subject: Python3 doesn't have a useful basestring type any more :( X-Git-Tag: v2.0.0~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6569f2a515e2ae6ada1dfa2e0bc32bb75174ad18;p=thirdparty%2Ftornado.git Python3 doesn't have a useful basestring type any more :( --- diff --git a/tornado/auth.py b/tornado/auth.py index b8ef87275..cb11db0f3 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -59,6 +59,7 @@ import uuid from tornado import httpclient from tornado import escape from tornado.ioloop import IOLoop +from tornado.util import bytes_type class OpenIdMixin(object): """Abstract implementation of OpenID and Attribute Exchange. @@ -784,7 +785,7 @@ class FacebookMixin(object): args["cancel_url"] = urlparse.urljoin( self.request.full_url(), cancel_uri) if extended_permissions: - if isinstance(extended_permissions, basestring): + if isinstance(extended_permissions, (unicode, bytes_type)): extended_permissions = [extended_permissions] args["req_perms"] = ",".join(extended_permissions) self.redirect("http://www.facebook.com/login.php?" + diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 2caaf21a3..5c462e871 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -6,7 +6,7 @@ import weakref from tornado.escape import utf8 from tornado import httputil from tornado.ioloop import IOLoop -from tornado.util import import_object +from tornado.util import import_object, bytes_type class HTTPClient(object): """A blocking HTTP client. @@ -137,7 +137,7 @@ class AsyncHTTPClient(object): on each IOLoop. Additional arguments may be supported depending on the implementation class in use. """ - if isinstance(impl, basestring): + if isinstance(impl, (unicode, bytes_type)): impl = import_object(impl) if impl is not None and not issubclass(impl, AsyncHTTPClient): raise ValueError("Invalid AsyncHTTPClient implementation") diff --git a/tornado/s3server.py b/tornado/s3server.py index b739c6c3b..de56776b9 100644 --- a/tornado/s3server.py +++ b/tornado/s3server.py @@ -42,6 +42,7 @@ from tornado import escape from tornado import httpserver from tornado import ioloop from tornado import web +from tornado.util import bytes_type def start(port, root_directory="/tmp/s3", bucket_depth=0): """Starts the mock S3 server on the given port at the given path.""" @@ -86,7 +87,7 @@ class BaseRequestHandler(web.RequestHandler): ''.join(parts)) def _render_parts(self, value, parts=[]): - if isinstance(value, basestring): + if isinstance(value, (unicode, bytes_type)): parts.append(escape.xhtml_escape(value)) elif isinstance(value, int) or isinstance(value, long): parts.append(str(value)) diff --git a/tornado/web.py b/tornado/web.py index 07021315d..61a674dcf 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -206,7 +206,7 @@ class RequestHandler(object): HTTP specification. If the value is not a string, we convert it to a string. All header values are then encoded as UTF-8. """ - if isinstance(value, basestring): + if isinstance(value, (unicode, bytes_type)): value = utf8(value) # If \n is allowed into the header, it is possible to inject # additional headers or split the request. Also cap length to @@ -439,7 +439,7 @@ class RequestHandler(object): if embed_part: js_embed.append(utf8(embed_part)) file_part = module.javascript_files() if file_part: - if isinstance(file_part, basestring): + if isinstance(file_part, (unicode, bytes_type)): js_files.append(file_part) else: js_files.extend(file_part) @@ -447,7 +447,7 @@ class RequestHandler(object): if embed_part: css_embed.append(utf8(embed_part)) file_part = module.css_files() if file_part: - if isinstance(file_part, basestring): + if isinstance(file_part, (unicode, bytes_type)): css_files.append(file_part) else: css_files.extend(file_part)