summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--paste/fixture.py15
-rw-r--r--paste/httpexceptions.py9
-rwxr-xr-xpaste/httpserver.py2
-rw-r--r--paste/session.py3
-rw-r--r--paste/translogger.py5
-rw-r--r--paste/urlparser.py3
-rw-r--r--paste/util/converters.py8
-rw-r--r--paste/util/looper.py5
-rw-r--r--paste/util/quoting.py5
-rw-r--r--paste/util/template.py16
-rw-r--r--tests/test_multidict.py17
11 files changed, 51 insertions, 37 deletions
diff --git a/paste/fixture.py b/paste/fixture.py
index 7a684e5..1b97c35 100644
--- a/paste/fixture.py
+++ b/paste/fixture.py
@@ -21,6 +21,7 @@ import shutil
import smtplib
import shlex
import re
+import six
import subprocess
from six.moves import cStringIO as StringIO
from six.moves.urllib.parse import urlencode
@@ -128,7 +129,7 @@ class TestApp(object):
``post_request_hook`` is a function, similar to
``pre_request_hook``, to be called after requests are made.
"""
- if isinstance(app, (str, unicode)):
+ if isinstance(app, (six.binary_type, six.text_type)):
from paste.deploy import loadapp
# @@: Should pick up relative_to from calling module's
# __file__
@@ -192,7 +193,7 @@ class TestApp(object):
# Hide from py.test:
__tracebackhide__ = True
if params:
- if not isinstance(params, (str, unicode)):
+ if not isinstance(params, (six.binary_type, six.text_type)):
params = urlencode(params, doseq=True)
if '?' in url:
url += '&'
@@ -794,9 +795,9 @@ class TestResponse(object):
of the response. Whitespace is normalized when searching
for a string.
"""
- if not isinstance(s, (str, unicode)):
+ if not isinstance(s, (six.binary_type, six.text_type)):
s = str(s)
- if isinstance(s, unicode):
+ if isinstance(s, six.text_type):
## FIXME: we don't know that this response uses utf8:
s = s.encode('utf8')
return (self.body.find(s) != -1
@@ -814,7 +815,7 @@ class TestResponse(object):
if 'no' in kw:
no = kw['no']
del kw['no']
- if isinstance(no, basestring):
+ if isinstance(no, (six.binary_type, six.text_type)):
no = [no]
else:
no = []
@@ -1687,7 +1688,7 @@ def _space_prefix(pref, full, sep=None, indent=None, include_sep=True):
def _make_pattern(pat):
if pat is None:
return None
- if isinstance(pat, (str, unicode)):
+ if isinstance(pat, (six.binary_type, six.text_type)):
pat = re.compile(pat)
if hasattr(pat, 'search'):
return pat.search
@@ -1713,7 +1714,7 @@ def setup_module(module=None):
if module is None:
# The module we were called from must be the module...
module = sys._getframe().f_back.f_globals['__name__']
- if isinstance(module, (str, unicode)):
+ if isinstance(module, (six.binary_type, six.text_type)):
module = sys.modules[module]
if hasattr(module, 'reset_state'):
module.reset_state()
diff --git a/paste/httpexceptions.py b/paste/httpexceptions.py
index d04308f..59d5b06 100644
--- a/paste/httpexceptions.py
+++ b/paste/httpexceptions.py
@@ -73,6 +73,7 @@ References:
"""
+import six
import types
from paste.wsgilib import catch_errors_app
from paste.response import has_header, header_value, replace_header
@@ -177,9 +178,9 @@ class HTTPException(Exception):
assert isinstance(headers, (type(None), list)), (
"headers must be None or a list: %r"
% headers)
- assert isinstance(detail, (type(None), basestring)), (
+ assert isinstance(detail, (type(None), six.binary_type, six.text_type)), (
"detail must be None or a string: %r" % detail)
- assert isinstance(comment, (type(None), basestring)), (
+ assert isinstance(comment, (type(None), six.binary_type, six.text_type)), (
"comment must be None or a string: %r" % comment)
self.headers = headers or tuple()
for req in self.required_headers:
@@ -206,7 +207,7 @@ class HTTPException(Exception):
for (k, v) in self.headers:
args[k.lower()] = escfunc(v)
for key, value in args.items():
- if isinstance(value, unicode):
+ if isinstance(value, six.text_type):
args[key] = value.encode('utf8', 'xmlcharrefreplace')
return template % args
@@ -236,7 +237,7 @@ class HTTPException(Exception):
else:
replace_header(headers, 'content-type', 'text/plain')
content = self.plain(environ)
- if isinstance(content, unicode):
+ if isinstance(content, six.text_type):
content = content.encode('utf8')
cur_content_type = (
header_value(headers, 'content-type')
diff --git a/paste/httpserver.py b/paste/httpserver.py
index d864cec..4609930 100755
--- a/paste/httpserver.py
+++ b/paste/httpserver.py
@@ -584,7 +584,7 @@ class ThreadPool(object):
self.daemon = daemon
if logger is None:
logger = logging.getLogger('paste.httpserver.ThreadPool')
- if isinstance(logger, basestring):
+ if isinstance(logger, six.string_types):
logger = logging.getLogger(logger)
self.logger = logger
self.error_email = error_email
diff --git a/paste/session.py b/paste/session.py
index 5f654f2..133cad6 100644
--- a/paste/session.py
+++ b/paste/session.py
@@ -33,6 +33,7 @@ import time
import random
import os
import datetime
+import six
import threading
import tempfile
@@ -184,7 +185,7 @@ class FileSession(object):
chmod=None,
expiration=2880, # in minutes: 48 hours
):
- if chmod and isinstance(chmod, basestring):
+ if chmod and isinstance(chmod, (six.binary_type, six.text_type)):
chmod = int(chmod, 8)
self.chmod = chmod
if not sid:
diff --git a/paste/translogger.py b/paste/translogger.py
index 355af9b..794efd8 100644
--- a/paste/translogger.py
+++ b/paste/translogger.py
@@ -5,6 +5,7 @@ Middleware for logging requests, using Apache combined log format
"""
import logging
+import six
import time
from six.moves.urllib.parse import quote
@@ -106,9 +107,9 @@ def make_filter(
setup_console_handler=True,
set_logger_level=logging.DEBUG):
from paste.util.converters import asbool
- if isinstance(logging_level, basestring):
+ if isinstance(logging_level, (six.binary_type, six.text_type)):
logging_level = logging._levelNames[logging_level]
- if isinstance(set_logger_level, basestring):
+ if isinstance(set_logger_level, (six.binary_type, six.text_type)):
set_logger_level = logging._levelNames[set_logger_level]
return TransLogger(
app,
diff --git a/paste/urlparser.py b/paste/urlparser.py
index 3554a98..19bcbac 100644
--- a/paste/urlparser.py
+++ b/paste/urlparser.py
@@ -5,6 +5,7 @@ WSGI applications that parse the URL and dispatch to on-disk resources
"""
import os
+import six
import sys
import imp
import mimetypes
@@ -525,7 +526,7 @@ class PkgResourcesParser(StaticURLParser):
def __init__(self, egg_or_spec, resource_name, manager=None, root_resource=None):
if pkg_resources is None:
raise NotImplementedError("This class requires pkg_resources.")
- if isinstance(egg_or_spec, (str, unicode)):
+ if isinstance(egg_or_spec, (six.binary_type, six.text_type)):
self.egg = pkg_resources.get_distribution(egg_or_spec)
else:
self.egg = egg_or_spec
diff --git a/paste/util/converters.py b/paste/util/converters.py
index f0ad349..11451bc 100644
--- a/paste/util/converters.py
+++ b/paste/util/converters.py
@@ -1,7 +1,11 @@
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+
+import six
+
+
def asbool(obj):
- if isinstance(obj, (str, unicode)):
+ if isinstance(obj, (six.binary_type, six.text_type)):
obj = obj.strip().lower()
if obj in ['true', 'yes', 'on', 'y', 't', '1']:
return True
@@ -13,7 +17,7 @@ def asbool(obj):
return bool(obj)
def aslist(obj, sep=None, strip=True):
- if isinstance(obj, (str, unicode)):
+ if isinstance(obj, (six.binary_type, six.text_type)):
lst = obj.split(sep)
if strip:
lst = [v.strip() for v in lst]
diff --git a/paste/util/looper.py b/paste/util/looper.py
index 03a6b42..8116323 100644
--- a/paste/util/looper.py
+++ b/paste/util/looper.py
@@ -20,6 +20,9 @@ looper you can get a better sense of the context. Use like::
__all__ = ['looper']
+import six
+
+
class looper(object):
"""
Helper for looping (particularly in templates)
@@ -137,7 +140,7 @@ class loop_pos(object):
def _compare_group(self, item, other, getter):
if getter is None:
return item != other
- elif (isinstance(getter, basestring)
+ elif (isinstance(getter, (six.binary_type, six.text_type))
and getter.startswith('.')):
getter = getter[1:]
if getter.endswith('()'):
diff --git a/paste/util/quoting.py b/paste/util/quoting.py
index 2052a90..8c578ee 100644
--- a/paste/util/quoting.py
+++ b/paste/util/quoting.py
@@ -2,6 +2,7 @@
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
import cgi
+import six
import re
from six.moves import html_entities
from six.moves.urllib.parse import quote, unquote
@@ -31,10 +32,10 @@ def html_quote(v, encoding=None):
return ''
elif isinstance(v, str):
return cgi.escape(v, 1)
- elif isinstance(v, unicode):
+ elif isinstance(v, six.text_type):
return cgi.escape(v.encode(encoding), 1)
else:
- return cgi.escape(unicode(v).encode(encoding), 1)
+ return cgi.escape(six.text_type(v).encode(encoding), 1)
_unquote_re = re.compile(r'&([a-zA-Z]+);')
def _entity_subber(match, name2c=html_entities.name2codepoint):
diff --git a/paste/util/template.py b/paste/util/template.py
index bcd282f..cdf503a 100644
--- a/paste/util/template.py
+++ b/paste/util/template.py
@@ -124,7 +124,7 @@ class Template(object):
def _interpret_codes(self, codes, ns, out):
__traceback_hide__ = True
for item in codes:
- if isinstance(item, basestring):
+ if isinstance(item, six.string_types):
out.append(item)
else:
self._interpret_code(item, ns, out)
@@ -185,7 +185,7 @@ class Template(object):
__traceback_hide__ = True
# @@: if/else/else gets through
for part in parts:
- assert not isinstance(part, basestring)
+ assert not isinstance(part, six.string_types)
name, pos = part[0], part[1]
if name == 'else':
result = True
@@ -318,7 +318,7 @@ class html(object):
def html_quote(value):
if value is None:
return ''
- if not isinstance(value, basestring):
+ if not isinstance(value, six.string_types):
if hasattr(value, '__unicode__'):
value = unicode(value)
else:
@@ -329,7 +329,7 @@ def html_quote(value):
return value
def url(v):
- if not isinstance(v, basestring):
+ if not isinstance(v, six.string_types):
if hasattr(v, '__unicode__'):
v = unicode(v)
else:
@@ -450,7 +450,7 @@ def trim_lex(tokens):
"""
for i in range(len(tokens)):
current = tokens[i]
- if isinstance(tokens[i], basestring):
+ if isinstance(tokens[i], six.string_types):
# we don't trim this
continue
item = current[0]
@@ -464,8 +464,8 @@ def trim_lex(tokens):
next = ''
else:
next = tokens[i+1]
- if (not isinstance(next, basestring)
- or not isinstance(prev, basestring)):
+ if (not isinstance(next, six.string_types)
+ or not isinstance(prev, six.string_types)):
continue
if ((not prev or trail_whitespace_re.search(prev))
and (not next or lead_whitespace_re.search(next))):
@@ -544,7 +544,7 @@ def parse(s, name=None):
return result
def parse_expr(tokens, name, context=()):
- if isinstance(tokens[0], basestring):
+ if isinstance(tokens[0], six.string_types):
return tokens[0], tokens[1:]
expr, pos = tokens[0]
expr = expr.strip()
diff --git a/tests/test_multidict.py b/tests/test_multidict.py
index 893bfcd..b43d168 100644
--- a/tests/test_multidict.py
+++ b/tests/test_multidict.py
@@ -2,6 +2,7 @@
# (c) 2007 Ian Bicking and Philip Jenvey; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
import cgi
+import six
from six.moves import StringIO
from nose.tools import assert_raises
@@ -63,13 +64,13 @@ def _test_unicode_dict(decode_param_names=False):
d.errors = 'ignore'
if decode_param_names:
- key_str = unicode
+ key_str = six.text_type
d.decode_keys = True
else:
key_str = str
def assert_unicode(obj):
- assert isinstance(obj, unicode)
+ assert isinstance(obj, six.text_type)
def assert_key_str(obj):
assert isinstance(obj, key_str)
@@ -77,7 +78,7 @@ def _test_unicode_dict(decode_param_names=False):
def assert_unicode_item(obj):
key, value = obj
assert isinstance(key, key_str)
- assert isinstance(value, unicode)
+ assert isinstance(value, six.text_type)
assert d.items() == [('a', u'a test')]
map(assert_key_str, d.keys())
@@ -104,9 +105,9 @@ def _test_unicode_dict(decode_param_names=False):
assert d.items() == [('a', u'a test'), ('c', u'3 test')]
map(assert_unicode_item, d.items())
assert d.pop('xxx', u'5 test') == u'5 test'
- assert isinstance(d.pop('xxx', u'5 test'), unicode)
+ assert isinstance(d.pop('xxx', u'5 test'), six.text_type)
assert d.getone('a') == u'a test'
- assert isinstance(d.getone('a'), unicode)
+ assert isinstance(d.getone('a'), six.text_type)
assert d.popitem() == ('c', u'3 test')
d['c'] = '3 test'
assert_unicode_item(d.popitem())
@@ -120,8 +121,8 @@ def _test_unicode_dict(decode_param_names=False):
assert isinstance(items[1][0], key_str)
assert isinstance(items[1][1], list)
- assert isinstance(d.setdefault('y', 'y test'), unicode)
- assert isinstance(d['y'], unicode)
+ assert isinstance(d.setdefault('y', 'y test'), six.text_type)
+ assert isinstance(d['y'], six.text_type)
assert d.mixed() == {u'a': u'a test', u'y': u'y test', u'z': item}
assert d.dict_of_lists() == {u'a': [u'a test'], u'y': [u'y test'],
@@ -156,6 +157,6 @@ def _test_unicode_dict(decode_param_names=False):
assert ufs.name == fs.name
assert isinstance(ufs.name, key_str)
assert ufs.filename == fs.filename
- assert isinstance(ufs.filename, unicode)
+ assert isinstance(ufs.filename, six.text_type)
assert isinstance(ufs.value, str)
assert ufs.value == 'hello'