void-packages/srcpkgs/python-docutils/patches/0013-Consistent-Python-3-checks.patch
Doan Tran Cong Danh 6b24f153d7 python3-docutils: unbroken: import from upstream
All of those patches are picked from upstream.

    xbps-src check python3-docutils

works fine now!
2019-12-01 12:38:58 +01:00

594 lines
22 KiB
Diff

From 7e79a539c426bbbb2932286b2efa2cf03a467e46 Mon Sep 17 00:00:00 2001
From: Stephen Finucane <stephen@that.guru>
Date: Wed, 20 Nov 2019 00:02:34 +0700
Subject: [PATCH 13/26] Consistent Python 3 checks.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8360 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
---
docutils/frontend.py | 2 +-
docutils/io.py | 4 ++--
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 | 2 +-
docutils/utils/error_reporting.py | 2 +-
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 | 2 +-
setup.py | 6 +++---
test/DocutilsTestSupport.py | 4 ++--
test/test__init__.py | 2 +-
test/test_error_reporting.py | 2 +-
test/test_language.py | 2 +-
test/test_nodes.py | 16 ++++++++--------
test/test_parsers/test_parser.py | 2 +-
.../test_rst/test_directives/test_include.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 ++--
28 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/docutils/frontend.py b/docutils/frontend.py
index 4b389b0..627f603 100644
--- a/docutils/frontend.py
+++ b/docutils/frontend.py
@@ -43,7 +43,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 3cdf00e..fb354fd 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, 4) 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
diff --git a/docutils/nodes.py b/docutils/nodes.py
index e29b887..3d714a2 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,) 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,):
+ 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,):
+ 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 7bccb5b..14fe1ff 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 0fc3610..3b9b9de 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 bf97e26..36a52e7 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,) 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,):
+ 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 6bc03f5..16252bb 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 23b9c95..345e290 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 49fb2c8..770ec71 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 77c70f8..de39247 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
diff --git a/docutils/utils/error_reporting.py b/docutils/utils/error_reporting.py
index 8fcc816..21bc55b 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
diff --git a/docutils/writers/_html_base.py b/docutils/writers/_html_base.py
index a957311..63d5a5b 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 34e810d..12306b6 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,):
+ 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 249ec4a..2c76b0f 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 cbb8648..52cd49c 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 417dc34..75f846c 100644
--- a/docutils/writers/odf_odt/__init__.py
+++ b/docutils/writers/odf_odt/__init__.py
@@ -947,7 +947,7 @@ class ODFTranslator(nodes.GenericNodeVisitor):
self.document.reporter.warning(
'Style "%s" is not a style used by odtwriter.' % (
rststyle, ))
- if sys.version_info.major >= 3:
+ 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 4280b98..12c398b 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,):
+ 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,):
+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,):
+ 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 21ea982..390df5b 100644
--- a/test/DocutilsTestSupport.py
+++ b/test/DocutilsTestSupport.py
@@ -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,):
+ 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 8f1d749..87ec14f 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_error_reporting.py b/test/test_error_reporting.py
index 893082c..4b337e3 100644
--- a/test/test_error_reporting.py
+++ b/test/test_error_reporting.py
@@ -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_language.py b/test/test_language.py
index 31ac613..455357a 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 af04e86..6805799 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,):
+ 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,):
+ 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,):
+ 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,):
+ 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,):
+ 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,): # 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,): # 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 6faecc7..6c57963 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,):
+ 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 d848262..92d0193 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
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 ee930c8..9d417e8 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 b99b5d0..576bc1d 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 74e8bc7..808861d 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 b718f78..fbb72c0 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,):
+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,):
+ if sys.version_info < (3,0):
sys.path.insert(0, '../../docutils')
else:
sys.path.insert(0, '../../build/lib')
--
2.24.0.375.geb5ae68d41