void-packages/srcpkgs/python-docutils/patches/0004-py3-Add-aliases-for-removed-symbols.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

599 lines
17 KiB
Diff

From 447e4896c9b2487fb28c25f7564ebcb6733d2363 Mon Sep 17 00:00:00 2001
From: Stephen Finucane <stephen@that.guru>
Date: Tue, 19 Nov 2019 23:50:50 +0700
Subject: [PATCH 04/26] py3: Add aliases for removed symbols
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add aliases for symbols that have been removed in Python 3.x, namely
basestring, unicode, unichr and StandardError.
Signed-off-by: Stephen Finucane <stephen@that.guru>
small fixes by Günter Milde.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8348 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
---
docutils/__init__.py | 3 +-
docutils/frontend.py | 3 +
docutils/io.py | 3 +
docutils/nodes.py | 8 ++-
docutils/parsers/rst/directives/__init__.py | 3 +
docutils/statemachine.py | 10 +++-
docutils/transforms/frontmatter.py | 6 ++
docutils/transforms/universal.py | 5 ++
docutils/utils/__init__.py | 3 +
docutils/utils/error_reporting.py | 10 +++-
docutils/utils/math/math2html.py | 59 ++++---------------
docutils/writers/_html_base.py | 4 ++
docutils/writers/docutils_xml.py | 3 +
docutils/writers/latex2e/__init__.py | 4 ++
docutils/writers/manpage.py | 6 +-
test/DocutilsTestSupport.py | 4 ++
test/test__init__.py | 4 ++
test/test_error_reporting.py | 3 +
test/test_language.py | 7 ++-
test/test_nodes.py | 3 +
.../test_rst/test_directives/test_include.py | 5 ++
.../test_rst/test_directives/test_tables.py | 5 ++
.../test_rst/test_directives/test_unicode.py | 6 ++
tools/dev/create_unimap.py | 10 ++--
24 files changed, 115 insertions(+), 62 deletions(-)
diff --git a/docutils/__init__.py b/docutils/__init__.py
index 7d6a679..8178816 100644
--- a/docutils/__init__.py
+++ b/docutils/__init__.py
@@ -88,7 +88,8 @@ __version_details__ = 'release'
"""
-class ApplicationError(StandardError): pass
+class ApplicationError(Exception): pass
+
class DataError(ApplicationError): pass
diff --git a/docutils/frontend.py b/docutils/frontend.py
index 689d904..ebdbd6a 100644
--- a/docutils/frontend.py
+++ b/docutils/frontend.py
@@ -43,6 +43,9 @@ import docutils.nodes
from docutils.utils.error_reporting import (locale_encoding, SafeString,
ErrorOutput, ErrorString)
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
def store_multiple(option, opt, value, parser, *args, **kwargs):
"""
diff --git a/docutils/io.py b/docutils/io.py
index 4466fdb..3cdf00e 100644
--- a/docutils/io.py
+++ b/docutils/io.py
@@ -17,6 +17,9 @@ import codecs
from docutils import TransformSpec
from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
class InputError(IOError): pass
class OutputError(IOError): pass
diff --git a/docutils/nodes.py b/docutils/nodes.py
index 8a5b7bb..fa02c6e 100644
--- a/docutils/nodes.py
+++ b/docutils/nodes.py
@@ -30,6 +30,10 @@ import warnings
import types
import unicodedata
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+ basestring = str # noqa
+
# ==============================
# Functional Node Base Classes
# ==============================
@@ -61,7 +65,7 @@ class Node(object):
"""
return True
- if sys.version_info < (3,):
+ 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):
@@ -301,7 +305,7 @@ class Node(object):
except IndexError:
return None
-if sys.version_info < (3,):
+if sys.version_info < (3, 0):
class reprunicode(unicode):
"""
A unicode sub-class that removes the initial u from unicode's repr.
diff --git a/docutils/parsers/rst/directives/__init__.py b/docutils/parsers/rst/directives/__init__.py
index 8789346..7bccb5b 100644
--- a/docutils/parsers/rst/directives/__init__.py
+++ b/docutils/parsers/rst/directives/__init__.py
@@ -16,6 +16,9 @@ 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):
+ unichr = chr # noqa
+
_directive_registry = {
'attention': ('admonitions', 'Attention'),
diff --git a/docutils/statemachine.py b/docutils/statemachine.py
index 6a2322c..b56f3c5 100644
--- a/docutils/statemachine.py
+++ b/docutils/statemachine.py
@@ -114,6 +114,9 @@ import unicodedata
from docutils import utils
from docutils.utils.error_reporting import ErrorOutput
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
class StateMachine(object):
@@ -1124,7 +1127,12 @@ class ViewList(object):
def __ne__(self, other): return self.data != self.__cast(other)
def __gt__(self, other): return self.data > self.__cast(other)
def __ge__(self, other): return self.data >= self.__cast(other)
- def __cmp__(self, other): return cmp(self.data, self.__cast(other))
+
+ def __cmp__(self, other):
+ # from https://docs.python.org/3.0/whatsnew/3.0.html
+ mine = self.data
+ yours = self.__cast(other)
+ return (mine > yours) - (yours < mine)
def __cast(self, other):
if isinstance(other, ViewList):
diff --git a/docutils/transforms/frontmatter.py b/docutils/transforms/frontmatter.py
index f94c9da..1279f50 100644
--- a/docutils/transforms/frontmatter.py
+++ b/docutils/transforms/frontmatter.py
@@ -22,10 +22,16 @@ Transforms related to the front matter of a document or a section
__docformat__ = 'reStructuredText'
import re
+import sys
+
from docutils import nodes, utils
from docutils.transforms import TransformError, Transform
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
+
class TitlePromoter(Transform):
"""
diff --git a/docutils/transforms/universal.py b/docutils/transforms/universal.py
index 47e1276..49fb2c8 100644
--- a/docutils/transforms/universal.py
+++ b/docutils/transforms/universal.py
@@ -17,12 +17,17 @@ Transforms needed by most or all documents:
__docformat__ = 'reStructuredText'
import re
+import sys
import time
from docutils import nodes, utils
from docutils.transforms import TransformError, Transform
from docutils.utils import smartquotes
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
+
class Decorations(Transform):
"""
diff --git a/docutils/utils/__init__.py b/docutils/utils/__init__.py
index c71d508..77c70f8 100644
--- a/docutils/utils/__init__.py
+++ b/docutils/utils/__init__.py
@@ -22,6 +22,9 @@ from docutils.nodes import unescape
import docutils.io
from docutils.utils.error_reporting import ErrorOutput, SafeString
+if sys.version_info >= (3, 0):
+ unicode = str
+
class SystemMessage(ApplicationError):
diff --git a/docutils/utils/error_reporting.py b/docutils/utils/error_reporting.py
index 8ea7108..8fcc816 100644
--- a/docutils/utils/error_reporting.py
+++ b/docutils/utils/error_reporting.py
@@ -35,7 +35,8 @@ The `SafeString`, `ErrorString` and `ErrorOutput` classes handle
common exceptions.
"""
-import sys, codecs
+import codecs
+import sys
# Guess the locale's encoding.
# If no valid guess can be made, locale_encoding is set to `None`:
@@ -64,6 +65,9 @@ else:
locale_encoding = None
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
class SafeString(object):
"""
@@ -199,9 +203,9 @@ class ErrorOutput(object):
self.stream.write(data)
except UnicodeEncodeError:
self.stream.write(data.encode(self.encoding, self.encoding_errors))
- except TypeError:
+ except TypeError:
if isinstance(data, unicode): # passed stream may expect bytes
- self.stream.write(data.encode(self.encoding,
+ self.stream.write(data.encode(self.encoding,
self.encoding_errors))
return
if self.stream in (sys.stderr, sys.stdout):
diff --git a/docutils/utils/math/math2html.py b/docutils/utils/math/math2html.py
index 1f61e23..4967165 100644
--- a/docutils/utils/math/math2html.py
+++ b/docutils/utils/math/math2html.py
@@ -20,10 +20,21 @@
# Alex 20101110
# eLyXer standalone formula conversion to HTML.
+import codecs
+import datetime
+import gettext
+import io
+import os.path
+import sys
+import unicodedata
+import urllib
+if sys.version_info >= (3,0):
+ unicode = str #noqa
+ basestring = str # noqa
+ file = io.IOBase # noqa
-import sys
class Trace(object):
"A tracing class"
@@ -73,12 +84,6 @@ class Trace(object):
show = classmethod(show)
-
-
-import os.path
-import sys
-
-
class BibStylesConfig(object):
"Configuration class from elyxer.config file"
@@ -1305,17 +1310,6 @@ class BranchOptions(object):
return 'options for ' + self.name + ': ' + unicode(self.options)
-
-
-import urllib
-
-
-
-
-
-
-
-
class Cloner(object):
"An object used to clone other objects."
@@ -1699,15 +1693,6 @@ class StringOutput(ContainerOutput):
return [container.string]
-
-
-
-
-
-import sys
-import codecs
-
-
class LineReader(object):
"Reads a file line by line"
@@ -3094,24 +3079,6 @@ class FormulaFactory(object):
return whole
-
-
-import unicodedata
-
-
-
-
-
-
-
-
-
-
-
-
-import gettext
-
-
class Translator(object):
"Reads the configuration file and tries to find a translation."
"Otherwise falls back to the messages in the config file."
@@ -4589,8 +4556,6 @@ class BeginCommand(CommandBit):
FormulaCommand.types += [BeginCommand]
-import datetime
-
class CombiningFunction(OneParamFunction):
diff --git a/docutils/writers/_html_base.py b/docutils/writers/_html_base.py
index 23efeea..a7f3b53 100644
--- a/docutils/writers/_html_base.py
+++ b/docutils/writers/_html_base.py
@@ -40,6 +40,10 @@ from docutils.utils.math import (unichar2tex, pick_math_environment,
math2html, latex2mathml, tex2mathml_extern)
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
+
class Writer(writers.Writer):
supported = ('html', 'xhtml') # update in subclass
diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py
index e870ee1..34e810d 100644
--- a/docutils/writers/docutils_xml.py
+++ b/docutils/writers/docutils_xml.py
@@ -30,6 +30,9 @@ from StringIO import StringIO
import docutils
from docutils import frontend, writers, nodes
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
class RawXmlError(docutils.ApplicationError): pass
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
index 5eaa7f0..e21c74b 100644
--- a/docutils/writers/latex2e/__init__.py
+++ b/docutils/writers/latex2e/__init__.py
@@ -28,6 +28,10 @@ from docutils.transforms import writer_aux
from docutils.utils.math import pick_math_environment, unichar2tex
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
+
class Writer(writers.Writer):
supported = ('latex','latex2e')
diff --git a/docutils/writers/manpage.py b/docutils/writers/manpage.py
index 287c6f2..9c887c7 100644
--- a/docutils/writers/manpage.py
+++ b/docutils/writers/manpage.py
@@ -45,6 +45,10 @@ by the command whatis or apropos.
__docformat__ = 'reStructuredText'
import re
+import sys
+
+if sys.version_info < (3, 0):
+ range = xrange
import docutils
from docutils import nodes, writers, languages
@@ -255,7 +259,7 @@ class Translator(nodes.NodeVisitor):
# ensure we get a ".TH" as viewers require it.
self.append_header()
# filter body
- for i in xrange(len(self.body)-1, 0, -1):
+ for i in range(len(self.body)-1, 0, -1):
# remove superfluous vertical gaps.
if self.body[i] == '.sp\n':
if self.body[i - 1][:4] in ('.BI ','.IP '):
diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py
index e77447a..c6f5b9f 100644
--- a/test/DocutilsTestSupport.py
+++ b/test/DocutilsTestSupport.py
@@ -89,6 +89,10 @@ except:
import pdb
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
+
# Hack to make repr(StringList) look like repr(list):
StringList.__repr__ = StringList.__str__
diff --git a/test/test__init__.py b/test/test__init__.py
index 01a1c59..8f1d749 100644
--- a/test/test__init__.py
+++ b/test/test__init__.py
@@ -16,6 +16,10 @@ import docutils
import docutils.utils
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
+
class ApplicationErrorTests(unittest.TestCase):
def test_message(self):
diff --git a/test/test_error_reporting.py b/test/test_error_reporting.py
index bae9db5..893082c 100644
--- a/test/test_error_reporting.py
+++ b/test/test_error_reporting.py
@@ -46,6 +46,9 @@ 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):
+ unicode = str # noqa
+
# locales confirmed to use non-ASCII chars in the IOError message
# for a missing file (https://bugs.gentoo.org/show_bug.cgi?id=349101)
diff --git a/test/test_language.py b/test/test_language.py
index 0e05d44..30af81a 100755
--- a/test/test_language.py
+++ b/test/test_language.py
@@ -26,6 +26,9 @@ _reporter = docutils.utils.new_reporter('', _settings)
reference_language = 'en'
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
class LanguageTestSuite(DocutilsTestSupport.CustomTestSuite):
@@ -156,7 +159,7 @@ class LanguageTestCase(DocutilsTestSupport.CustomTestCase):
if failures:
text = ('Module docutils.parsers.rst.languages.%s:\n %s'
% (self.language, '\n '.join(failures)))
- if type(text) is unicode:
+ if isinstance(text, unicode):
text = text.encode('raw_unicode_escape')
self.fail(text)
@@ -191,7 +194,7 @@ class LanguageTestCase(DocutilsTestSupport.CustomTestCase):
if failures:
text = ('Module docutils.parsers.rst.languages.%s:\n %s'
% (self.language, '\n '.join(failures)))
- if type(text) is unicode:
+ if isinstance(text, unicode):
text = text.encode('raw_unicode_escape')
self.fail(text)
diff --git a/test/test_nodes.py b/test/test_nodes.py
index f6bc6b2..924569f 100755
--- a/test/test_nodes.py
+++ b/test/test_nodes.py
@@ -17,6 +17,9 @@ from DocutilsTestSupport import nodes, utils
debug = False
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+
class TextTests(unittest.TestCase):
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 2a6e5be..6e9dc84 100755
--- a/test/test_parsers/test_rst/test_directives/test_include.py
+++ b/test/test_parsers/test_rst/test_directives/test_include.py
@@ -14,6 +14,11 @@ from __init__ import DocutilsTestSupport
from docutils.parsers.rst import states
from docutils.utils.code_analyzer import with_pygments
+
+if sys.version_info >= (3, 0):
+ unichr = chr # noqa
+
+
def suite():
s = DocutilsTestSupport.ParserTestSuite()
if not with_pygments:
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 f7496ad..2c5f832 100755
--- a/test/test_parsers/test_rst/test_directives/test_tables.py
+++ b/test/test_parsers/test_rst/test_directives/test_tables.py
@@ -16,6 +16,11 @@ import platform
from docutils.parsers.rst.directives import tables
+if sys.version_info >= (3, 0):
+ unicode = str # noqa
+ unichr = chr # noqa
+
+
def suite():
s = DocutilsTestSupport.ParserTestSuite()
s.generateTests(totest)
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 b140050..5cdfd5a 100755
--- a/test/test_parsers/test_rst/test_directives/test_unicode.py
+++ b/test/test_parsers/test_rst/test_directives/test_unicode.py
@@ -8,9 +8,15 @@
Tests for misc.py "unicode" directive.
"""
+import sys
+
from __init__ import DocutilsTestSupport
+if sys.version_info >= (3, 0):
+ unichr = chr # noqa
+
+
def suite():
s = DocutilsTestSupport.ParserTestSuite()
s.generateTests(totest)
diff --git a/tools/dev/create_unimap.py b/tools/dev/create_unimap.py
index 85ac264..74e8bc7 100755
--- a/tools/dev/create_unimap.py
+++ b/tools/dev/create_unimap.py
@@ -14,15 +14,15 @@ from xml.dom import minidom
import sys
import pprint
-if sys.version_info >= (3,0):
- unicode = str
+if sys.version_info >= (3, 0):
+ unicode = str #noqa
else:
- bytes = str
- chr = unichr
+ bytes = str # noqa
+ chr = unichr # noqa
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)
--
2.24.0.375.geb5ae68d41