diff options
author | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-03-18 12:49:12 +0100 |
---|---|---|
committer | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-03-18 12:49:12 +0100 |
commit | 674ae7718bc06a8b8c8b658075bf82c8198fb632 (patch) | |
tree | 0075bace24ead7f03ae7cb18935e4c707f71a860 /paste/util | |
parent | 3cdb7e4227cbaad690b1c1557c03fa6da0decc36 (diff) | |
download | paste-674ae7718bc06a8b8c8b658075bf82c8198fb632.tar.gz |
Python 3: use new names of standard library modules
Use "try/except ImportError" to try Python 2 and Python 3 names.
Diffstat (limited to 'paste/util')
-rw-r--r-- | paste/util/PySourceColor.py | 5 | ||||
-rw-r--r-- | paste/util/multidict.py | 8 | ||||
-rw-r--r-- | paste/util/quoting.py | 11 | ||||
-rw-r--r-- | paste/util/template.py | 4 |
4 files changed, 16 insertions, 12 deletions
diff --git a/paste/util/PySourceColor.py b/paste/util/PySourceColor.py index 65406ec..d9f451f 100644 --- a/paste/util/PySourceColor.py +++ b/paste/util/PySourceColor.py @@ -195,10 +195,7 @@ import keyword import token
import tokenize
import traceback
-try :
- import cStringIO as StringIO
-except:
- import StringIO
+from six.moves import cStringIO as StringIO
# Do not edit
NAME = token.NAME
NUMBER = token.NUMBER
diff --git a/paste/util/multidict.py b/paste/util/multidict.py index d3eb1e9..867f309 100644 --- a/paste/util/multidict.py +++ b/paste/util/multidict.py @@ -3,7 +3,13 @@ import cgi import copy import sys -from UserDict import DictMixin + +try: + # Python 3 + from collections import MutableMapping as DictMixin +except ImportError: + # Python 2 + from UserDict import DictMixin class MultiDict(DictMixin): diff --git a/paste/util/quoting.py b/paste/util/quoting.py index 6184752..2052a90 100644 --- a/paste/util/quoting.py +++ b/paste/util/quoting.py @@ -2,9 +2,10 @@ # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php import cgi -import htmlentitydefs -import urllib import re +from six.moves import html_entities +from six.moves.urllib.parse import quote, unquote + __all__ = ['html_quote', 'html_unquote', 'url_quote', 'url_unquote', 'strip_html'] @@ -36,7 +37,7 @@ def html_quote(v, encoding=None): return cgi.escape(unicode(v).encode(encoding), 1) _unquote_re = re.compile(r'&([a-zA-Z]+);') -def _entity_subber(match, name2c=htmlentitydefs.name2codepoint): +def _entity_subber(match, name2c=html_entities.name2codepoint): code = name2c.get(match.group(1)) if code: return unichr(code) @@ -90,8 +91,8 @@ def comment_quote(s): comment = _comment_quote_re.sub('->', comment) return comment -url_quote = urllib.quote -url_unquote = urllib.unquote +url_quote = quote +url_unquote = unquote if __name__ == '__main__': import doctest diff --git a/paste/util/template.py b/paste/util/template.py index 1e42b5a..fd9e802 100644 --- a/paste/util/template.py +++ b/paste/util/template.py @@ -33,7 +33,7 @@ If there are syntax errors ``TemplateError`` will be raised. import re import sys import cgi -import urllib +from six.moves.urllib.parse import quote from paste.util.looper import looper __all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate', @@ -335,7 +335,7 @@ def url(v): v = str(v) if isinstance(v, unicode): v = v.encode('utf8') - return urllib.quote(v) + return quote(v) def attr(**kw): kw = kw.items() |