summaryrefslogtreecommitdiff
path: root/paste/util
diff options
context:
space:
mode:
authorCyril Roelandt <cyril.roelandt@enovance.com>2014-03-18 12:47:02 +0100
committerCyril Roelandt <cyril.roelandt@enovance.com>2014-03-18 12:47:02 +0100
commit4262b41da195cb959abf4a5a06ce34a6dec2c4a3 (patch)
treecb6a9ef83ac83e6e6e0a90dd48ad9672b4e32a9d /paste/util
parent3f98341a08e2899fdf6914776198bd0878e4f5c2 (diff)
downloadpaste-4262b41da195cb959abf4a5a06ce34a6dec2c4a3.tar.gz
Python 3: Use six types for strings
* Replace (str, unicode) with (six.binary_type, six.text_type) * Replace basestring with (six.binary_type, six.text_type)
Diffstat (limited to 'paste/util')
-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
4 files changed, 21 insertions, 13 deletions
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()