diff options
| author | shimizukawa <shimizukawa@gmail.com> | 2014-04-29 19:59:58 +0900 |
|---|---|---|
| committer | shimizukawa <shimizukawa@gmail.com> | 2014-04-29 19:59:58 +0900 |
| commit | ec98611f2e058a419a28bf7f780f35e761e384ef (patch) | |
| tree | f329b64577f21b54e54764ea2b2eb36dff149940 /sphinx/util | |
| parent | 5e9df0d136140d5b2aba94319ecba7ec541c7446 (diff) | |
| download | sphinx-ec98611f2e058a419a28bf7f780f35e761e384ef.tar.gz | |
use six privided functions/classes to support py2/py3 in one source. refs #1350.
Diffstat (limited to 'sphinx/util')
| -rw-r--r-- | sphinx/util/__init__.py | 3 | ||||
| -rw-r--r-- | sphinx/util/jsdump.py | 6 | ||||
| -rw-r--r-- | sphinx/util/jsonimpl.py | 5 |
3 files changed, 9 insertions, 5 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 3c9366a1..2330f42f 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -22,6 +22,7 @@ from codecs import open, BOM_UTF8 from collections import deque import six +from six.moves import range import docutils from docutils.utils import relative_path @@ -327,7 +328,7 @@ def parselinenos(spec, total): else: start = (begend[0] == '') and 0 or int(begend[0])-1 end = (begend[1] == '') and total or int(begend[1]) - items.extend(xrange(start, end)) + items.extend(range(start, end)) except Exception: raise ValueError('invalid line number spec: %r' % spec) return items diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py index 85845a72..709439a6 100644 --- a/sphinx/util/jsdump.py +++ b/sphinx/util/jsdump.py @@ -12,6 +12,8 @@ import re +import six + from sphinx.util.pycompat import u _str_re = re.compile(r'"(\\\\|\\"|[^"])*"') @@ -74,7 +76,7 @@ double in super""".split()) def dumps(obj, key=False): if key: - if not isinstance(obj, basestring): + if not isinstance(obj, six.string_types): obj = str(obj) if _nameonly_re.match(obj) and obj not in reswords: return obj # return it as a bare word @@ -93,7 +95,7 @@ def dumps(obj, key=False): ) for key, value in obj.iteritems()) elif isinstance(obj, (tuple, list, set)): return '[%s]' % ','.join(dumps(x) for x in obj) - elif isinstance(obj, basestring): + elif isinstance(obj, six.string_types): return encode_string(obj) raise TypeError(type(obj)) diff --git a/sphinx/util/jsonimpl.py b/sphinx/util/jsonimpl.py index 05a6ec6e..6682a376 100644 --- a/sphinx/util/jsonimpl.py +++ b/sphinx/util/jsonimpl.py @@ -9,14 +9,15 @@ :license: BSD, see LICENSE for details. """ -import UserString import json +from six.moves import UserString + class SphinxJSONEncoder(json.JSONEncoder): """JSONEncoder subclass that forces translation proxies.""" def default(self, obj): - if isinstance(obj, UserString.UserString): + if isinstance(obj, UserString): return unicode(obj) return json.JSONEncoder.default(self, obj) |
