921 lines
36 KiB
Diff
921 lines
36 KiB
Diff
From 2e6a65d93d4616f702bbc1f0f5b18c562e403956 Mon Sep 17 00:00:00 2001
|
|
From: Stephen Finucane <stephen@that.guru>
|
|
Date: Wed, 20 Nov 2019 00:08:33 +0700
|
|
Subject: [PATCH 19/26] Formatting changes to facilitate integration of "py3"
|
|
patchset.
|
|
|
|
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8367 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
|
|
Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
|
|
---
|
|
docutils/_compat.py | 2 +-
|
|
docutils/core.py | 2 +-
|
|
docutils/frontend.py | 4 ++--
|
|
docutils/io.py | 18 +++++++++---------
|
|
docutils/nodes.py | 12 ++++++------
|
|
docutils/parsers/rst/directives/__init__.py | 2 +-
|
|
docutils/parsers/rst/directives/misc.py | 4 ++--
|
|
docutils/parsers/rst/directives/tables.py | 4 ++--
|
|
docutils/statemachine.py | 2 +-
|
|
docutils/transforms/frontmatter.py | 2 +-
|
|
docutils/transforms/universal.py | 2 +-
|
|
docutils/utils/__init__.py | 8 ++++----
|
|
docutils/utils/error_reporting.py | 4 ++--
|
|
docutils/utils/math/math2html.py | 6 +++---
|
|
docutils/writers/_html_base.py | 2 +-
|
|
docutils/writers/docutils_xml.py | 4 ++--
|
|
docutils/writers/latex2e/__init__.py | 2 +-
|
|
docutils/writers/manpage.py | 2 +-
|
|
docutils/writers/odf_odt/__init__.py | 5 +++--
|
|
setup.py | 6 +++---
|
|
test/DocutilsTestSupport.py | 6 +++---
|
|
test/test__init__.py | 2 +-
|
|
test/test_command_line.py | 2 +-
|
|
test/test_error_reporting.py | 4 ++--
|
|
test/test_functional.py | 8 ++++----
|
|
test/test_io.py | 8 ++++----
|
|
test/test_language.py | 2 +-
|
|
test/test_nodes.py | 16 ++++++++--------
|
|
test/test_parsers/test_parser.py | 2 +-
|
|
.../test_rst/test_directives/test_include.py | 4 ++--
|
|
.../test_rst/test_directives/test_raw.py | 2 +-
|
|
.../test_rst/test_directives/test_tables.py | 2 +-
|
|
.../test_rst/test_directives/test_unicode.py | 2 +-
|
|
tools/dev/create_unimap.py | 4 ++--
|
|
tools/dev/generate_punctuation_chars.py | 4 ++--
|
|
tools/dev/unicode2rstsubs.py | 2 +-
|
|
36 files changed, 82 insertions(+), 81 deletions(-)
|
|
|
|
diff --git a/docutils/_compat.py b/docutils/_compat.py
|
|
index c9de633..1ff959c 100644
|
|
--- a/docutils/_compat.py
|
|
+++ b/docutils/_compat.py
|
|
@@ -14,7 +14,7 @@ This module currently provides the following helper symbols:
|
|
|
|
import sys
|
|
|
|
-if sys.version_info < (3,0):
|
|
+if sys.version_info < (3, 0):
|
|
u_prefix = 'u'
|
|
from StringIO import StringIO as BytesIO
|
|
else:
|
|
diff --git a/docutils/core.py b/docutils/core.py
|
|
index 12a0c93..d0db093 100644
|
|
--- a/docutils/core.py
|
|
+++ b/docutils/core.py
|
|
@@ -155,7 +155,7 @@ class Publisher(object):
|
|
if argv is None:
|
|
argv = sys.argv[1:]
|
|
# converting to Unicode (Python 3 does this automatically):
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
# TODO: make this failsafe and reversible?
|
|
argv_encoding = (frontend.locale_encoding or 'ascii')
|
|
argv = [a.decode(argv_encoding) for a in argv]
|
|
diff --git a/docutils/frontend.py b/docutils/frontend.py
|
|
index 815343d..7bfff6a 100644
|
|
--- a/docutils/frontend.py
|
|
+++ b/docutils/frontend.py
|
|
@@ -36,7 +36,7 @@ import warnings
|
|
import codecs
|
|
import optparse
|
|
from optparse import SUPPRESS_HELP
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
from configparser import RawConfigParser
|
|
else:
|
|
from ConfigParser import RawConfigParser
|
|
@@ -47,7 +47,7 @@ import docutils.nodes
|
|
from docutils.utils.error_reporting import (locale_encoding, SafeString,
|
|
ErrorOutput, ErrorString)
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/docutils/io.py b/docutils/io.py
|
|
index fb354fd..9c70f10 100644
|
|
--- a/docutils/io.py
|
|
+++ b/docutils/io.py
|
|
@@ -17,7 +17,7 @@ import codecs
|
|
from docutils import TransformSpec
|
|
from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
@@ -208,7 +208,7 @@ class FileInput(Input):
|
|
def __init__(self, source=None, source_path=None,
|
|
encoding=None, error_handler='strict',
|
|
autoclose=True,
|
|
- mode='r' if sys.version_info >= (3,0) else 'rU', **kwargs):
|
|
+ mode='r' if sys.version_info >= (3, 0) else 'rU', **kwargs):
|
|
"""
|
|
:Parameters:
|
|
- `source`: either a file-like object (which is read directly), or
|
|
@@ -239,7 +239,7 @@ class FileInput(Input):
|
|
if source is None:
|
|
if source_path:
|
|
# Specify encoding in Python 3
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
kwargs = {'encoding': self.encoding,
|
|
'errors': self.error_handler}
|
|
else:
|
|
@@ -251,7 +251,7 @@ class FileInput(Input):
|
|
raise InputError(error.errno, error.strerror, source_path)
|
|
else:
|
|
self.source = sys.stdin
|
|
- elif (sys.version_info >= (3,0) and
|
|
+ elif (sys.version_info >= (3, 0) and
|
|
check_encoding(self.source, self.encoding) is False):
|
|
# TODO: re-open, warn or raise error?
|
|
raise UnicodeError('Encoding clash: encoding given is "%s" '
|
|
@@ -268,7 +268,7 @@ class FileInput(Input):
|
|
Read and decode a single file and return the data (Unicode string).
|
|
"""
|
|
try:
|
|
- if self.source is sys.stdin and sys.version_info >= (3,0):
|
|
+ if self.source is sys.stdin and sys.version_info >= (3, 0):
|
|
# read as binary data to circumvent auto-decoding
|
|
data = self.source.buffer.read()
|
|
# normalize newlines
|
|
@@ -358,7 +358,7 @@ class FileOutput(Output):
|
|
|
|
def open(self):
|
|
# Specify encoding in Python 3.
|
|
- if sys.version_info >= (3,0) and 'b' not in self.mode:
|
|
+ if sys.version_info >= (3, 0) and 'b' not in self.mode:
|
|
kwargs = {'encoding': self.encoding,
|
|
'errors': self.error_handler}
|
|
else:
|
|
@@ -378,17 +378,17 @@ class FileOutput(Output):
|
|
"""
|
|
if not self.opened:
|
|
self.open()
|
|
- if ('b' not in self.mode and sys.version_info < (3,0)
|
|
+ if ('b' not in self.mode and sys.version_info < (3, 0)
|
|
or check_encoding(self.destination, self.encoding) is False
|
|
):
|
|
data = self.encode(data)
|
|
- if sys.version_info >= (3,0) and os.linesep != '\n':
|
|
+ if sys.version_info >= (3, 0) and os.linesep != '\n':
|
|
data = data.replace(b'\n', bytes(os.linesep, 'ascii')) # fix endings
|
|
|
|
try:
|
|
self.destination.write(data)
|
|
except TypeError as e:
|
|
- if sys.version_info >= (3,0) and isinstance(data, bytes):
|
|
+ if sys.version_info >= (3, 0) and isinstance(data, bytes):
|
|
try:
|
|
self.destination.buffer.write(data)
|
|
except AttributeError:
|
|
diff --git a/docutils/nodes.py b/docutils/nodes.py
|
|
index f8da02b..dd9c4b6 100644
|
|
--- a/docutils/nodes.py
|
|
+++ b/docutils/nodes.py
|
|
@@ -29,7 +29,7 @@ import re
|
|
import warnings
|
|
import unicodedata
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
basestring = str # noqa
|
|
|
|
@@ -64,7 +64,7 @@ class Node(object):
|
|
"""
|
|
return True
|
|
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
# on 2.x, str(node) will be a byte string with Unicode
|
|
# characters > 255 escaped; on 3.x this is no longer necessary
|
|
def __str__(self):
|
|
@@ -304,7 +304,7 @@ class Node(object):
|
|
except IndexError:
|
|
return None
|
|
|
|
-if sys.version_info < (3,0):
|
|
+if sys.version_info < (3, 0):
|
|
class reprunicode(unicode):
|
|
"""
|
|
A unicode sub-class that removes the initial u from unicode's repr.
|
|
@@ -320,7 +320,7 @@ def ensure_str(s):
|
|
"""
|
|
Failsave conversion of `unicode` to `str`.
|
|
"""
|
|
- if sys.version_info < (3,0) and isinstance(s, unicode):
|
|
+ if sys.version_info < (3, 0) and isinstance(s, unicode):
|
|
return s.encode('ascii', 'backslashreplace')
|
|
return s
|
|
|
|
@@ -352,7 +352,7 @@ class Text(Node, reprunicode):
|
|
children = ()
|
|
"""Text nodes have no children, and cannot have children."""
|
|
|
|
- if sys.version_info > (3,0):
|
|
+ if sys.version_info > (3, 0):
|
|
def __new__(cls, data, rawsource=None):
|
|
"""Prevent the rawsource argument from propagating to str."""
|
|
if isinstance(data, bytes):
|
|
@@ -544,7 +544,7 @@ class Element(Node):
|
|
else:
|
|
return self.emptytag()
|
|
|
|
- if sys.version_info > (3,0):
|
|
+ if sys.version_info > (3, 0):
|
|
# 2to3 doesn't convert __unicode__ to __str__
|
|
__str__ = __unicode__
|
|
|
|
diff --git a/docutils/parsers/rst/directives/__init__.py b/docutils/parsers/rst/directives/__init__.py
|
|
index 14fe1ff..7bccb5b 100644
|
|
--- a/docutils/parsers/rst/directives/__init__.py
|
|
+++ b/docutils/parsers/rst/directives/__init__.py
|
|
@@ -16,7 +16,7 @@ from docutils import nodes
|
|
from docutils.utils import split_escaped_whitespace, escape2null, unescape
|
|
from docutils.parsers.rst.languages import en as _fallback_language_module
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unichr = chr # noqa
|
|
|
|
|
|
diff --git a/docutils/parsers/rst/directives/misc.py b/docutils/parsers/rst/directives/misc.py
|
|
index 3b9b9de..0fc3610 100644
|
|
--- a/docutils/parsers/rst/directives/misc.py
|
|
+++ b/docutils/parsers/rst/directives/misc.py
|
|
@@ -473,7 +473,7 @@ class Date(Directive):
|
|
'Invalid context: the "%s" directive can only be used within '
|
|
'a substitution definition.' % self.name)
|
|
format_str = '\n'.join(self.content) or '%Y-%m-%d'
|
|
- if sys.version_info< (3,0):
|
|
+ if sys.version_info< (3, 0):
|
|
try:
|
|
format_str = format_str.encode(locale_encoding or 'utf-8')
|
|
except UnicodeEncodeError:
|
|
@@ -498,7 +498,7 @@ class Date(Directive):
|
|
# time.gmtime(int(source_date_epoch)))
|
|
# else:
|
|
text = time.strftime(format_str)
|
|
- if sys.version_info< (3,0):
|
|
+ if sys.version_info< (3, 0):
|
|
# `text` is a byte string that may contain non-ASCII characters:
|
|
try:
|
|
text = text.decode(locale_encoding or 'utf-8')
|
|
diff --git a/docutils/parsers/rst/directives/tables.py b/docutils/parsers/rst/directives/tables.py
|
|
index 36a52e7..b698e08 100644
|
|
--- a/docutils/parsers/rst/directives/tables.py
|
|
+++ b/docutils/parsers/rst/directives/tables.py
|
|
@@ -263,7 +263,7 @@ class CSVTable(Table):
|
|
return [detail.args[0]]
|
|
except csv.Error as detail:
|
|
message = str(detail)
|
|
- if sys.version_info < (3,0) and '1-character string' in message:
|
|
+ if sys.version_info < (3, 0) and '1-character string' in message:
|
|
message += '\nwith Python 2.x this must be an ASCII character.'
|
|
error = self.state_machine.reporter.error(
|
|
'Error with CSV data in "%s" directive:\n%s'
|
|
@@ -356,7 +356,7 @@ class CSVTable(Table):
|
|
raise SystemMessagePropagation(error)
|
|
return csv_data, source
|
|
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
# 2.x csv module doesn't do Unicode
|
|
def decode_from_csv(s):
|
|
return s.decode('utf-8')
|
|
diff --git a/docutils/statemachine.py b/docutils/statemachine.py
|
|
index 16252bb..6bc03f5 100644
|
|
--- a/docutils/statemachine.py
|
|
+++ b/docutils/statemachine.py
|
|
@@ -113,7 +113,7 @@ import unicodedata
|
|
from docutils import utils
|
|
from docutils.utils.error_reporting import ErrorOutput
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/docutils/transforms/frontmatter.py b/docutils/transforms/frontmatter.py
|
|
index 345e290..23b9c95 100644
|
|
--- a/docutils/transforms/frontmatter.py
|
|
+++ b/docutils/transforms/frontmatter.py
|
|
@@ -28,7 +28,7 @@ from docutils import nodes, utils
|
|
from docutils.transforms import TransformError, Transform
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/docutils/transforms/universal.py b/docutils/transforms/universal.py
|
|
index 770ec71..49fb2c8 100644
|
|
--- a/docutils/transforms/universal.py
|
|
+++ b/docutils/transforms/universal.py
|
|
@@ -24,7 +24,7 @@ from docutils.transforms import TransformError, Transform
|
|
from docutils.utils import smartquotes
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/docutils/utils/__init__.py b/docutils/utils/__init__.py
|
|
index de39247..cc1fd1a 100644
|
|
--- a/docutils/utils/__init__.py
|
|
+++ b/docutils/utils/__init__.py
|
|
@@ -22,7 +22,7 @@ from docutils.nodes import unescape
|
|
import docutils.io
|
|
from docutils.utils.error_reporting import ErrorOutput, SafeString
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str
|
|
|
|
|
|
@@ -592,7 +592,7 @@ def split_escaped_whitespace(text):
|
|
return list(itertools.chain(*strings))
|
|
|
|
def strip_combining_chars(text):
|
|
- if isinstance(text, str) and sys.version_info < (3,0):
|
|
+ if isinstance(text, str) and sys.version_info < (3, 0):
|
|
return text
|
|
return u''.join([c for c in text if not unicodedata.combining(c)])
|
|
|
|
@@ -604,7 +604,7 @@ def find_combining_chars(text):
|
|
[3, 6, 9]
|
|
|
|
"""
|
|
- if isinstance(text, str) and sys.version_info < (3,0):
|
|
+ if isinstance(text, str) and sys.version_info < (3, 0):
|
|
return []
|
|
return [i for i,c in enumerate(text) if unicodedata.combining(c)]
|
|
|
|
@@ -638,7 +638,7 @@ def column_width(text):
|
|
|
|
Correct ``len(text)`` for wide East Asian and combining Unicode chars.
|
|
"""
|
|
- if isinstance(text, str) and sys.version_info < (3,0):
|
|
+ if isinstance(text, str) and sys.version_info < (3, 0):
|
|
return len(text)
|
|
width = sum([east_asian_widths[unicodedata.east_asian_width(c)]
|
|
for c in text])
|
|
diff --git a/docutils/utils/error_reporting.py b/docutils/utils/error_reporting.py
|
|
index 21bc55b..02a1dab 100644
|
|
--- a/docutils/utils/error_reporting.py
|
|
+++ b/docutils/utils/error_reporting.py
|
|
@@ -65,7 +65,7 @@ else:
|
|
locale_encoding = None
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
@@ -93,7 +93,7 @@ class SafeString(object):
|
|
for arg in self.data.args]
|
|
return ', '.join(args)
|
|
if isinstance(self.data, unicode):
|
|
- if sys.version_info > (3,0):
|
|
+ if sys.version_info > (3, 0):
|
|
return self.data
|
|
else:
|
|
return self.data.encode(self.encoding,
|
|
diff --git a/docutils/utils/math/math2html.py b/docutils/utils/math/math2html.py
|
|
index ddaca48..475519f 100644
|
|
--- a/docutils/utils/math/math2html.py
|
|
+++ b/docutils/utils/math/math2html.py
|
|
@@ -30,7 +30,7 @@ import unicodedata
|
|
import urllib
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str #noqa
|
|
basestring = str # noqa
|
|
file = io.IOBase # noqa
|
|
@@ -73,7 +73,7 @@ class Trace(object):
|
|
|
|
def show(cls, message, channel):
|
|
"Show a message out of a channel"
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
message = message.encode('utf-8')
|
|
channel.write(message + '\n')
|
|
|
|
@@ -1785,7 +1785,7 @@ class LineWriter(object):
|
|
"Write a string"
|
|
if not self.file:
|
|
self.file = codecs.open(self.filename, 'w', "utf-8")
|
|
- if self.file == sys.stdout and sys.version_info < (3,0):
|
|
+ if self.file == sys.stdout and sys.version_info < (3, 0):
|
|
string = string.encode('utf-8')
|
|
self.file.write(string)
|
|
|
|
diff --git a/docutils/writers/_html_base.py b/docutils/writers/_html_base.py
|
|
index 63d5a5b..a957311 100644
|
|
--- a/docutils/writers/_html_base.py
|
|
+++ b/docutils/writers/_html_base.py
|
|
@@ -40,7 +40,7 @@ from docutils.utils.math import (unichar2tex, pick_math_environment,
|
|
math2html, latex2mathml, tex2mathml_extern)
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py
|
|
index 12306b6..60ee07b 100644
|
|
--- a/docutils/writers/docutils_xml.py
|
|
+++ b/docutils/writers/docutils_xml.py
|
|
@@ -30,7 +30,7 @@ from StringIO import StringIO
|
|
import docutils
|
|
from docutils import frontend, writers, nodes
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
@@ -185,7 +185,7 @@ class XMLTranslator(nodes.GenericNodeVisitor):
|
|
self.output.append(xml_string)
|
|
self.default_departure(node) # or not?
|
|
# Check validity of raw XML:
|
|
- if isinstance(xml_string, unicode) and sys.version_info < (3,0):
|
|
+ if isinstance(xml_string, unicode) and sys.version_info < (3, 0):
|
|
xml_string = xml_string.encode('utf8')
|
|
try:
|
|
self.xmlparser.parse(StringIO(xml_string))
|
|
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
|
|
index 636d477..05b55eb 100644
|
|
--- a/docutils/writers/latex2e/__init__.py
|
|
+++ b/docutils/writers/latex2e/__init__.py
|
|
@@ -28,7 +28,7 @@ from docutils.transforms import writer_aux
|
|
from docutils.utils.math import pick_math_environment, unichar2tex
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/docutils/writers/manpage.py b/docutils/writers/manpage.py
|
|
index ed163de..df4f1a3 100644
|
|
--- a/docutils/writers/manpage.py
|
|
+++ b/docutils/writers/manpage.py
|
|
@@ -47,7 +47,7 @@ __docformat__ = 'reStructuredText'
|
|
import re
|
|
import sys
|
|
|
|
-if sys.version_info < (3,0):
|
|
+if sys.version_info < (3, 0):
|
|
range = xrange
|
|
|
|
import docutils
|
|
diff --git a/docutils/writers/odf_odt/__init__.py b/docutils/writers/odf_odt/__init__.py
|
|
index f36980f..c79d4c1 100644
|
|
--- a/docutils/writers/odf_odt/__init__.py
|
|
+++ b/docutils/writers/odf_odt/__init__.py
|
|
@@ -37,7 +37,8 @@ if type(sys.version_info)!=type((0,)) and sys.version_info.major >= 3:
|
|
else:
|
|
from ConfigParser import ConfigParser
|
|
from StringIO import StringIO
|
|
- from urllib2 import urlopen, HTTPError
|
|
+ from urllib2 import HTTPError
|
|
+ from urllib2 import urlopen
|
|
|
|
|
|
VERSION = '1.0a'
|
|
@@ -947,7 +948,7 @@ class ODFTranslator(nodes.GenericNodeVisitor):
|
|
self.document.reporter.warning(
|
|
'Style "%s" is not a style used by odtwriter.' % (
|
|
rststyle, ))
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
self.format_map[rststyle] = format
|
|
else:
|
|
self.format_map[rststyle] = format.decode('utf-8')
|
|
diff --git a/setup.py b/setup.py
|
|
index 12c398b..d636f46 100755
|
|
--- a/setup.py
|
|
+++ b/setup.py
|
|
@@ -13,7 +13,7 @@ try:
|
|
from distutils.core import setup, Command
|
|
from distutils.command.build import build
|
|
from distutils.command.build_py import build_py
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
from distutils.command.build_py import build_py_2to3
|
|
from distutils.util import copydir_run_2to3
|
|
from distutils.command.install_data import install_data
|
|
@@ -27,7 +27,7 @@ except ImportError:
|
|
sys.exit(1)
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
# copy-convert auxiliary python sources
|
|
class copy_build_py_2to3(build_py_2to3):
|
|
"""Copy/convert Python source files in given directories recursively.
|
|
@@ -97,7 +97,7 @@ def do_setup():
|
|
kwargs['cmdclass'] = {'build_data': build_data,
|
|
'install_data': smart_install_data}
|
|
# Auto-convert source code for Python 3
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
kwargs['cmdclass']['build_py'] = copy_build_py_2to3
|
|
else:
|
|
kwargs['cmdclass']['build_py'] = build_py
|
|
diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py
|
|
index 390df5b..47ba83c 100644
|
|
--- a/test/DocutilsTestSupport.py
|
|
+++ b/test/DocutilsTestSupport.py
|
|
@@ -51,7 +51,7 @@ from pprint import pformat
|
|
|
|
testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir)
|
|
os.chdir(testroot)
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
sys.path.insert(0, os.path.normpath(os.path.join(testroot,
|
|
'..', 'build', 'lib')))
|
|
sys.path.append(os.path.normpath(os.path.join(testroot, '..',
|
|
@@ -89,7 +89,7 @@ except:
|
|
import pdb
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
@@ -202,7 +202,7 @@ class CustomTestCase(StandardTestCase):
|
|
"""`input`, `output`, and `expected` should all be strings."""
|
|
if isinstance(input, unicode):
|
|
input = input.encode('raw_unicode_escape')
|
|
- if sys.version_info > (3,0):
|
|
+ if sys.version_info > (3, 0):
|
|
# API difference: Python 3's node.__str__ doesn't escape
|
|
#assert expected is None or isinstance(expected, unicode)
|
|
if isinstance(expected, bytes):
|
|
diff --git a/test/test__init__.py b/test/test__init__.py
|
|
index 87ec14f..8f1d749 100644
|
|
--- a/test/test__init__.py
|
|
+++ b/test/test__init__.py
|
|
@@ -16,7 +16,7 @@ import docutils
|
|
import docutils.utils
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/test/test_command_line.py b/test/test_command_line.py
|
|
index eb6ca8a..d9e0850 100644
|
|
--- a/test/test_command_line.py
|
|
+++ b/test/test_command_line.py
|
|
@@ -33,7 +33,7 @@ class CommandLineEncodingTests(unittest.TestCase):
|
|
if argv_encoding == 'ascii': # cannot test
|
|
return
|
|
sys.argv.append('--source-url=test.txt') # pure ASCII argument
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
sys.argv.append(u'--title=Dornröschen'.encode(argv_encoding))
|
|
else:
|
|
sys.argv.append(u'--title=Dornröschen')
|
|
diff --git a/test/test_error_reporting.py b/test/test_error_reporting.py
|
|
index 4b337e3..d1509c6 100644
|
|
--- a/test/test_error_reporting.py
|
|
+++ b/test/test_error_reporting.py
|
|
@@ -25,10 +25,10 @@ instances like, e.g., ::
|
|
unless the minimal required Python version has this problem fixed.
|
|
"""
|
|
|
|
-import unittest
|
|
import sys
|
|
import os
|
|
import codecs
|
|
+import unittest
|
|
from io import StringIO, BytesIO
|
|
|
|
import DocutilsTestSupport # must be imported before docutils
|
|
@@ -46,7 +46,7 @@ if sys.version_info < (3,0): # problems solved in py3k
|
|
print('cannot test error reporting with problematic locales,\n'
|
|
'`import locale` failed.')
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/test/test_functional.py b/test/test_functional.py
|
|
index 5d3beb9..cdc75a0 100755
|
|
--- a/test/test_functional.py
|
|
+++ b/test/test_functional.py
|
|
@@ -160,7 +160,7 @@ expected output and check it in:
|
|
output = docutils.core.publish_file(**params)
|
|
# ensure output is unicode
|
|
output_encoding = params.get('output_encoding', 'utf-8')
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
try:
|
|
output = output.decode(output_encoding)
|
|
except UnicodeDecodeError:
|
|
@@ -172,14 +172,14 @@ expected output and check it in:
|
|
no_expected = self.no_expected_template % {
|
|
'exp': expected_path, 'out': params['destination_path']}
|
|
self.assertTrue(os.access(expected_path, os.R_OK), no_expected)
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
f = open(expected_path, 'r')
|
|
else: # samples are UTF8 encoded. 'rb' leads to errors with Python 3!
|
|
f = open(expected_path, 'r', encoding='utf-8')
|
|
# Normalize line endings:
|
|
expected = '\n'.join(f.read().splitlines())
|
|
f.close()
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
try:
|
|
expected = expected.decode(output_encoding)
|
|
except UnicodeDecodeError:
|
|
@@ -193,7 +193,7 @@ expected output and check it in:
|
|
diff = ''.join(difflib.unified_diff(
|
|
expected.splitlines(True), output.splitlines(True),
|
|
expected_path, params['destination_path']))
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
diff = diff.encode(sys.stderr.encoding or 'ascii', 'replace')
|
|
print('\n%s:' % (self,), file=sys.stderr)
|
|
print(diff, file=sys.stderr)
|
|
diff --git a/test/test_io.py b/test/test_io.py
|
|
index 737a19d..6294613 100755
|
|
--- a/test/test_io.py
|
|
+++ b/test/test_io.py
|
|
@@ -103,7 +103,7 @@ print("hello world")
|
|
# if no encoding is given, try decoding with utf8:
|
|
input = io.FileInput(source_path='functional/input/cyrillic.txt')
|
|
data = input.read()
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
# in Py3k, the locale encoding is used without --input-encoding
|
|
# skipping the heuristic
|
|
self.assertEqual(input.successful_encoding, 'utf-8')
|
|
@@ -111,7 +111,7 @@ print("hello world")
|
|
def test_heuristics_no_utf8(self):
|
|
# if no encoding is given and decoding with utf8 fails,
|
|
# use either the locale encoding (if specified) or latin-1:
|
|
- if sys.version_info >= (3,0) and locale_encoding != "utf8":
|
|
+ if sys.version_info >= (3, 0) and locale_encoding != "utf8":
|
|
# in Py3k, the locale encoding is used without --input-encoding
|
|
# skipping the heuristic unless decoding fails.
|
|
return
|
|
@@ -169,7 +169,7 @@ class OutputTests(unittest.TestCase):
|
|
self.assertEqual(self.udrain.getvalue(), self.udata)
|
|
|
|
def test_write_utf8(self):
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
fo = io.FileOutput(destination=self.udrain, encoding='utf8',
|
|
autoclose=False)
|
|
fo.write(self.udata)
|
|
@@ -189,7 +189,7 @@ class OutputTests(unittest.TestCase):
|
|
self.assertEqual(self.bdrain.getvalue(), self.bdata)
|
|
|
|
# Test for Python 3 features:
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
def test_write_bytes_to_stdout(self):
|
|
# try writing data to `destination.buffer`, if data is
|
|
# instance of `bytes` and writing to `destination` fails:
|
|
diff --git a/test/test_language.py b/test/test_language.py
|
|
index 455357a..31ac613 100755
|
|
--- a/test/test_language.py
|
|
+++ b/test/test_language.py
|
|
@@ -26,7 +26,7 @@ _reporter = docutils.utils.new_reporter('', _settings)
|
|
|
|
reference_language = 'en'
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
diff --git a/test/test_nodes.py b/test/test_nodes.py
|
|
index 6805799..ec8824e 100755
|
|
--- a/test/test_nodes.py
|
|
+++ b/test/test_nodes.py
|
|
@@ -17,7 +17,7 @@ from DocutilsTestSupport import nodes, utils
|
|
|
|
debug = False
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
|
|
|
|
@@ -36,7 +36,7 @@ class TextTests(unittest.TestCase):
|
|
self.assertEqual(self.text.shortrepr(),
|
|
r"<#text: 'Line 1.\nLine 2.'>")
|
|
self.assertEqual(nodes.reprunicode('foo'), u'foo')
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
self.assertEqual(repr(self.unicode_text), r"<#text: 'M\xf6hren'>")
|
|
else:
|
|
self.assertEqual(repr(self.unicode_text), u"<#text: 'Möhren'>")
|
|
@@ -65,7 +65,7 @@ class TextTests(unittest.TestCase):
|
|
self.assertEqual(stripped2, u's noc')
|
|
|
|
def test_asciirestriction(self):
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
self.assertRaises(UnicodeDecodeError, nodes.Text,
|
|
b'hol%s' % chr(224))
|
|
else:
|
|
@@ -98,7 +98,7 @@ class ElementTests(unittest.TestCase):
|
|
del element['attr']
|
|
element['mark'] = u'\u2022'
|
|
self.assertEqual(repr(element), '<Element: >')
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
self.assertEqual(str(element), '<Element mark="\\u2022"/>')
|
|
else:
|
|
self.assertEqual(str(element), u'<Element mark="\u2022"/>')
|
|
@@ -106,7 +106,7 @@ class ElementTests(unittest.TestCase):
|
|
self.assertEqual(dom.toxml(), u'<Element mark="\u2022"/>')
|
|
dom.unlink()
|
|
element['names'] = ['nobody', u'имя', u'näs']
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
self.assertEqual(repr(element),
|
|
'<Element "nobody; \\u0438\\u043c\\u044f; n\\xe4s": >')
|
|
else:
|
|
@@ -117,7 +117,7 @@ class ElementTests(unittest.TestCase):
|
|
element = nodes.Element('text\nmore', nodes.Text('text\nmore'))
|
|
uelement = nodes.Element(u'grün', nodes.Text(u'grün'))
|
|
self.assertEqual(repr(element), r"<Element: <#text: 'text\nmore'>>")
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
self.assertEqual(repr(uelement), "<Element: <#text: 'gr\\xfcn'>>")
|
|
else:
|
|
self.assertEqual(repr(uelement), u"<Element: <#text: 'grün'>>")
|
|
@@ -341,7 +341,7 @@ class MiscTests(unittest.TestCase):
|
|
self.assertTrue(isinstance(nodes.reprunicode('foo'), unicode))
|
|
self.assertEqual(nodes.reprunicode('foo'), u'foo')
|
|
self.assertEqual(nodes.reprunicode(u'Möhre'), u'Möhre')
|
|
- if sys.version_info < (3,0): # strip leading "u" from representation
|
|
+ if sys.version_info < (3, 0): # strip leading "u" from representation
|
|
self.assertEqual(repr(nodes.reprunicode(u'Möhre')),
|
|
repr(u'Möhre')[1:])
|
|
else: # no change to `unicode` under Python 3k
|
|
@@ -350,7 +350,7 @@ class MiscTests(unittest.TestCase):
|
|
def test_ensure_str(self):
|
|
self.assertTrue(isinstance(nodes.ensure_str(u'über'), str))
|
|
self.assertEqual(nodes.ensure_str('over'), 'over')
|
|
- if sys.version_info < (3,0): # strip leading "u" from representation
|
|
+ if sys.version_info < (3, 0): # strip leading "u" from representation
|
|
self.assertEqual(nodes.ensure_str(u'über'), r'\xfcber')
|
|
else:
|
|
self.assertEqual(nodes.ensure_str(u'über'), r'über')
|
|
diff --git a/test/test_parsers/test_parser.py b/test/test_parsers/test_parser.py
|
|
index 6c57963..d2142b4 100644
|
|
--- a/test/test_parsers/test_parser.py
|
|
+++ b/test/test_parsers/test_parser.py
|
|
@@ -23,7 +23,7 @@ class RstParserTests(unittest.TestCase):
|
|
document = utils.new_document('test data', frontend.OptionParser(
|
|
components=(parser, )).get_default_values())
|
|
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
# supplying string input is supported, but only if ascii-decodable
|
|
self.assertRaises(UnicodeDecodeError,
|
|
parser.parse, b'hol%s' % chr(224), document)
|
|
diff --git a/test/test_parsers/test_rst/test_directives/test_include.py b/test/test_parsers/test_rst/test_directives/test_include.py
|
|
index 92d0193..31a5c02 100755
|
|
--- a/test/test_parsers/test_rst/test_directives/test_include.py
|
|
+++ b/test/test_parsers/test_rst/test_directives/test_include.py
|
|
@@ -16,7 +16,7 @@ from docutils.parsers.rst import states
|
|
from docutils.utils.code_analyzer import with_pygments
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unichr = chr # noqa
|
|
|
|
|
|
@@ -48,7 +48,7 @@ include_literal = mydir('include_literal.txt')
|
|
utf_16_file = mydir('utf-16.csv')
|
|
utf_16_error_str = ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe "
|
|
"in position 0: ordinal not in range(128)")
|
|
-if sys.version_info < (3,0):
|
|
+if sys.version_info < (3, 0):
|
|
utf_16_error_str = ("UnicodeError: Unable to decode input data. "
|
|
"Tried the following encodings: 'ascii'.\n"
|
|
" (%s)" % utf_16_error_str)
|
|
diff --git a/test/test_parsers/test_rst/test_directives/test_raw.py b/test/test_parsers/test_rst/test_directives/test_raw.py
|
|
index 2da962a..b86b23f 100755
|
|
--- a/test/test_parsers/test_rst/test_directives/test_raw.py
|
|
+++ b/test/test_parsers/test_rst/test_directives/test_raw.py
|
|
@@ -26,7 +26,7 @@ utf_16_file = os.path.join(mydir, 'utf-16.csv')
|
|
utf_16_file_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_file)
|
|
utf_16_error_str = ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe "
|
|
"in position 0: ordinal not in range(128)")
|
|
-if sys.version_info < (3,0):
|
|
+if sys.version_info < (3, 0):
|
|
utf_16_error_str = ("UnicodeError: Unable to decode input data. "
|
|
"Tried the following encodings: 'ascii'.\n"
|
|
" (%s)" % utf_16_error_str)
|
|
diff --git a/test/test_parsers/test_rst/test_directives/test_tables.py b/test/test_parsers/test_rst/test_directives/test_tables.py
|
|
index cc450f3..ca27f9a 100755
|
|
--- a/test/test_parsers/test_rst/test_directives/test_tables.py
|
|
+++ b/test/test_parsers/test_rst/test_directives/test_tables.py
|
|
@@ -18,7 +18,7 @@ from docutils.parsers.rst.directives import tables
|
|
from . import DocutilsTestSupport
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str # noqa
|
|
unichr = chr # noqa
|
|
|
|
diff --git a/test/test_parsers/test_rst/test_directives/test_unicode.py b/test/test_parsers/test_rst/test_directives/test_unicode.py
|
|
index 576bc1d..b99b5d0 100755
|
|
--- a/test/test_parsers/test_rst/test_directives/test_unicode.py
|
|
+++ b/test/test_parsers/test_rst/test_directives/test_unicode.py
|
|
@@ -14,7 +14,7 @@ import sys
|
|
from . import DocutilsTestSupport
|
|
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unichr = chr # noqa
|
|
|
|
|
|
diff --git a/tools/dev/create_unimap.py b/tools/dev/create_unimap.py
|
|
index 808861d..74e8bc7 100755
|
|
--- a/tools/dev/create_unimap.py
|
|
+++ b/tools/dev/create_unimap.py
|
|
@@ -14,7 +14,7 @@ from xml.dom import minidom
|
|
import sys
|
|
import pprint
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unicode = str #noqa
|
|
else:
|
|
bytes = str # noqa
|
|
@@ -22,7 +22,7 @@ else:
|
|
|
|
|
|
def w(s):
|
|
- if sys.version_info >= (3,0) and isinstance(s, unicode):
|
|
+ if sys.version_info >= (3, 0) and isinstance(s, unicode):
|
|
s = s.encode('utf8')
|
|
sys.stdout.write(s)
|
|
|
|
diff --git a/tools/dev/generate_punctuation_chars.py b/tools/dev/generate_punctuation_chars.py
|
|
index cfe97df..9f211b9 100644
|
|
--- a/tools/dev/generate_punctuation_chars.py
|
|
+++ b/tools/dev/generate_punctuation_chars.py
|
|
@@ -38,7 +38,7 @@ from __future__ import print_function
|
|
import sys
|
|
import unicodedata
|
|
|
|
-if sys.version_info >= (3,0):
|
|
+if sys.version_info >= (3, 0):
|
|
unichr = chr # unichr not available in Py3k
|
|
else:
|
|
import codecs
|
|
@@ -361,7 +361,7 @@ if __name__ == '__main__':
|
|
# Import the punctuation_chars module from the source
|
|
# or Py3k build path for local Python modules::
|
|
|
|
- if sys.version_info < (3,0):
|
|
+ if sys.version_info < (3, 0):
|
|
sys.path.insert(0, '../../docutils')
|
|
else:
|
|
sys.path.insert(0, '../../build/lib')
|
|
diff --git a/tools/dev/unicode2rstsubs.py b/tools/dev/unicode2rstsubs.py
|
|
index ac38bf4..028af78 100755
|
|
--- a/tools/dev/unicode2rstsubs.py
|
|
+++ b/tools/dev/unicode2rstsubs.py
|
|
@@ -48,7 +48,7 @@ def main(argv=None):
|
|
inpath = 'unicode.xml'
|
|
if not os.path.isfile(inpath):
|
|
usage(argv[0], 1, 'No such file: "%s".' % inpath)
|
|
- if sys.version_info >= (3,0):
|
|
+ if sys.version_info >= (3, 0):
|
|
infile = open(inpath, mode='rb')
|
|
else:
|
|
infile = open(inpath)
|
|
--
|
|
2.24.0.375.geb5ae68d41
|
|
|