summaryrefslogtreecommitdiff
path: root/sphinx/util/pycompat.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/pycompat.py')
-rw-r--r--sphinx/util/pycompat.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index a3ea36ba4..c7ea19d75 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -9,11 +9,19 @@
:license: BSD, see LICENSE for details.
"""
+import io
import sys
import codecs
+import warnings
+
+from six import class_types
+from six.moves import zip_longest
+from itertools import product
from six import PY3, text_type, exec_
+NoneType = type(None)
+
# ------------------------------------------------------------------------------
# Python 2/3 compatibility
@@ -22,12 +30,14 @@ if PY3:
# prefix for Unicode strings
u = ''
from io import TextIOWrapper
+
# safely encode a string for printing to the terminal
def terminal_safe(s):
return s.encode('ascii', 'backslashreplace').decode('ascii')
# some kind of default system encoding; should be used with a lenient
# error handler
sys_encoding = sys.getdefaultencoding()
+
# support for running 2to3 over config files
def convert_with_2to3(filepath):
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
@@ -43,14 +53,14 @@ if PY3:
# try to match ParseError details with SyntaxError details
raise SyntaxError(err.msg, (filepath, lineno, offset, err.value))
return text_type(tree)
- from html import escape as htmlescape # >= Python 3.2
+ from html import escape as htmlescape # noqa: >= Python 3.2
class UnicodeMixin:
- """Mixin class to handle defining the proper __str__/__unicode__
- methods in Python 2 or 3."""
+ """Mixin class to handle defining the proper __str__/__unicode__
+ methods in Python 2 or 3."""
- def __str__(self):
- return self.__unicode__()
+ def __str__(self):
+ return self.__unicode__()
from textwrap import indent
@@ -59,8 +69,10 @@ else:
u = 'u'
# no need to refactor on 2.x versions
convert_with_2to3 = None
+
def TextIOWrapper(stream, encoding):
return codecs.lookup(encoding or 'ascii')[2](stream)
+
# safely encode a string for printing to the terminal
def terminal_safe(s):
return s.encode('ascii', 'backslashreplace')
@@ -68,7 +80,7 @@ else:
# error handler
sys_encoding = __import__('locale').getpreferredencoding()
# use Python 3 name
- from cgi import escape as htmlescape # 2.6, 2.7
+ from cgi import escape as htmlescape # noqa: 2.6, 2.7
class UnicodeMixin(object):
"""Mixin class to handle defining the proper __str__/__unicode__
@@ -120,12 +132,6 @@ def execfile_(filepath, _globals, open=open):
# ------------------------------------------------------------------------------
# Internal module backwards-compatibility
-import warnings
-
-from six import class_types
-from six.moves import zip_longest
-import io
-from itertools import product
class _DeprecationWrapper(object):
def __init__(self, mod, deprecated):