|
From: <mi...@us...> - 2022-01-26 19:03:23
|
Revision: 8973
http://sourceforge.net/p/docutils/code/8973
Author: milde
Date: 2022-01-26 19:03:19 +0000 (Wed, 26 Jan 2022)
Log Message:
-----------
Small fixes and clean-ups by Adam Turner.
Remove duplicate definitions in language modules.
Import locale_encoding from `docutils.io`
Use decorator for staticmethod
Use True/False over 1/0.
`collections.OrderedDict` no longer required,
all dictionaries are ordered from Python 3.7
Remove obsolete `__cmp__` method
cf. https://docs.python.org/3/whatsnew/3.0.html#ordering-comparisons
Use str instead of type('').
Zero-argument ``super()``
Simplify test support module as
"u" prefix isn't used by repr in Python 3.
Modified Paths:
--------------
trunk/docutils/docutils/__init__.py
trunk/docutils/docutils/parsers/rst/directives/tables.py
trunk/docutils/docutils/parsers/rst/languages/ar.py
trunk/docutils/docutils/parsers/rst/languages/es.py
trunk/docutils/docutils/parsers/rst/states.py
trunk/docutils/docutils/statemachine.py
trunk/docutils/docutils/transforms/writer_aux.py
trunk/docutils/docutils/utils/math/latex2mathml.py
trunk/docutils/docutils/writers/html5_polyglot/__init__.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/DocutilsTestSupport.py
trunk/docutils/test/test_functional.py
trunk/docutils/test/test_io.py
trunk/docutils/test/test_language.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py
trunk/docutils/test/test_settings.py
trunk/docutils/test/test_utils.py
trunk/docutils/test/test_viewlist.py
trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
trunk/docutils/test/test_writers/test_odt.py
Modified: trunk/docutils/docutils/__init__.py
===================================================================
--- trunk/docutils/docutils/__init__.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/__init__.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -90,8 +90,8 @@
if serial != 0:
raise ValueError('"serial" must be 0 for final releases')
- return super(VersionInfo, cls).__new__(cls, major, minor, micro,
- releaselevel, serial, release)
+ return super().__new__(cls, major, minor, micro,
+ releaselevel, serial, release)
def __lt__(self, other):
if isinstance(other, tuple):
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -358,6 +358,7 @@
raise SystemMessagePropagation(error)
return csv_data, source
+ @staticmethod
def decode_from_csv(s):
warnings.warn('CSVTable.decode_from_csv()'
' is not required with Python 3'
@@ -364,6 +365,8 @@
' and will be removed in Docutils 0.21 or later.',
DeprecationWarning, stacklevel=2)
return s
+
+ @staticmethod
def encode_for_csv(s):
warnings.warn('CSVTable.encode_from_csv()'
' is not required with Python 3'
@@ -370,8 +373,6 @@
' and will be removed in Docutils 0.21 or later.',
DeprecationWarning, stacklevel=2)
return s
- decode_from_csv = staticmethod(decode_from_csv)
- encode_for_csv = staticmethod(encode_for_csv)
def parse_csv_data_into_rows(self, csv_data, dialect, source):
csv_reader = csv.reader([line + '\n' for line in csv_data],
Modified: trunk/docutils/docutils/parsers/rst/languages/ar.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/languages/ar.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/parsers/rst/languages/ar.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -14,14 +14,11 @@
__docformat__ = 'reStructuredText'
-
directives = {
# language-dependent: fixed
u'تنبيه': u'attention',
u'احتیاط': u'caution',
u'كود': u'code',
- u'كود': u'code',
- u'كود': u'code',
u'خطر': u'danger',
u'خطأ': u'error',
u'تلميح': u'hint',
Modified: trunk/docutils/docutils/parsers/rst/languages/es.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/languages/es.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/parsers/rst/languages/es.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -14,7 +14,6 @@
__docformat__ = 'reStructuredText'
-
directives = {
u'atenci\u00f3n': 'attention',
u'atencion': 'attention',
@@ -85,7 +84,6 @@
u'abreviatura': 'abbreviation',
u'ab': 'abbreviation',
u'acronimo': 'acronym',
- u'acronimo': 'acronym',
u'ac': 'acronym',
u'code (translation required)': 'code',
u'indice': 'index',
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/parsers/rst/states.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -986,7 +986,7 @@
return (string[:matchstart], [referencenode], string[matchend:], [])
def anonymous_reference(self, match, lineno):
- return self.reference(match, lineno, anonymous=1)
+ return self.reference(match, lineno, anonymous=True)
def standalone_uri(self, match, lineno):
if (not match.group('scheme')
Modified: trunk/docutils/docutils/statemachine.py
===================================================================
--- trunk/docutils/docutils/statemachine.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/statemachine.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -1,4 +1,4 @@
- # $Id$
+# $Id$
# Author: David Goodger <go...@py...>
# Copyright: This module has been placed in the public domain.
@@ -720,11 +720,10 @@
name string, or a 1- or 2-tuple (transition name, optional next state
name).
"""
- stringtype = type('')
names = []
transitions = {}
for namestate in name_list:
- if isinstance(namestate, stringtype):
+ if isinstance(namestate, str):
transitions[namestate] = self.make_transition(namestate)
names.append(namestate)
else:
@@ -1114,12 +1113,6 @@
def __gt__(self, other): return self.data > self.__cast(other)
def __ge__(self, other): return 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):
return other.data
Modified: trunk/docutils/docutils/transforms/writer_aux.py
===================================================================
--- trunk/docutils/docutils/transforms/writer_aux.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/transforms/writer_aux.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -46,7 +46,7 @@
warnings.warn('docutils.transforms.writer_aux.Compound is deprecated'
' and will be removed in Docutils 0.21 or later.',
DeprecationWarning, stacklevel=2)
- super(Compound, self).__init__(document, startnode)
+ super().__init__(document, startnode)
def apply(self):
for compound in self.document.findall(nodes.compound):
Modified: trunk/docutils/docutils/utils/math/latex2mathml.py
===================================================================
--- trunk/docutils/docutils/utils/math/latex2mathml.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/utils/math/latex2mathml.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -24,7 +24,6 @@
#
# >>> from latex2mathml import *
-import collections
import copy
import re
import sys
@@ -340,7 +339,7 @@
self.children = []
self.extend(children)
- self.attributes = collections.OrderedDict()
+ self.attributes = {}
# sort attributes for predictable functional tests
# as self.attributes.update(attributes) does not keep order in Python < 3.6
for key in sorted(attributes.keys()):
@@ -472,7 +471,7 @@
self.children[0].parent = parent
except (AttributeError, ValueError):
return self.children[0]
- return super(mrow, self).close()
+ return super().close()
# >>> mrow(displaystyle=False)
# mrow(displaystyle=False)
@@ -509,7 +508,7 @@
def __init__(self, data, **attributes):
self.data = data
- super(MathToken, self).__init__(**attributes)
+ super().__init__(**attributes)
def _xml_body(self, level=0):
return [str(self.data).translate(self.xml_entities)]
@@ -538,7 +537,7 @@
math.__init__(self, *children, **kwargs)
def append(self, child):
- current_node = super(MathSchema, self).append(child)
+ current_node = super().append(child)
# normalize order if full
if self.switch and self.full():
self.children[-1], self.children[-2] = self.children[-2], self.children[-1]
Modified: trunk/docutils/docutils/writers/html5_polyglot/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -273,7 +273,7 @@
uri = node['uri']
mimetype = mimetypes.guess_type(uri)[0]
if mimetype not in self.videotypes:
- return super(HTMLTranslator, self).visit_image(node)
+ return super().visit_image(node)
# image size
if 'width' in node:
atts['width'] = node['width'].replace('px', '')
@@ -438,8 +438,7 @@
# append self-link
def section_title_tags(self, node):
- start_tag, close_tag = super(HTMLTranslator,
- self).section_title_tags(node)
+ start_tag, close_tag = super().section_title_tags(node)
ids = node.parent['ids']
if (ids and getattr(self.settings, 'section_self_link', None)
and not isinstance(node.parent, nodes.document)):
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -1154,7 +1154,7 @@
alltt = False # inside `alltt` environment
def __init__(self, document, babel_class=Babel):
- nodes.NodeVisitor.__init__(self, document) # TODO: use super()
+ super().__init__(document)
# Reporter
# ~~~~~~~~
self.warn = self.document.reporter.warning
Modified: trunk/docutils/test/DocutilsTestSupport.py
===================================================================
--- trunk/docutils/test/DocutilsTestSupport.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/DocutilsTestSupport.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -210,8 +210,8 @@
print('\n%s\ninput:' % (self,), file=sys.stderr)
print(input, file=sys.stderr)
try:
- comparison = ''.join(self.compare(expected.splitlines(1),
- output.splitlines(1)))
+ comparison = ''.join(self.compare(expected.splitlines(True),
+ output.splitlines(True)))
print('-: expected\n+: output', file=sys.stderr)
print(comparison, file=sys.stderr)
except AttributeError: # expected or output not a string
@@ -841,15 +841,11 @@
return_tuple = []
for i in args:
r = repr(i)
- if ( (isinstance(i, bytes) or isinstance(i, str))
- and '\n' in i):
+ if isinstance(i, (str, bytes)) and '\n' in i:
stripped = ''
- if isinstance(i, str) and r.startswith('u'):
+ if isinstance(i, bytes) and r.startswith('b'):
stripped = r[0]
r = r[1:]
- elif isinstance(i, bytes) and r.startswith('b'):
- stripped = r[0]
- r = r[1:]
# quote_char = "'" or '"'
quote_char = r[0]
assert quote_char in ("'", '"'), quote_char
Modified: trunk/docutils/test/test_functional.py
===================================================================
--- trunk/docutils/test/test_functional.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_functional.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -34,7 +34,7 @@
def __init__(self):
"""Process all config files in functional/tests/."""
- DocutilsTestSupport.CustomTestSuite.__init__(self)
+ super().__init__()
os.chdir(DocutilsTestSupport.testroot)
self.clear_output_directory()
self.added = 0
Modified: trunk/docutils/test/test_io.py
===================================================================
--- trunk/docutils/test/test_io.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_io.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -22,7 +22,7 @@
def write(self, data):
if isinstance(data, str):
data.encode('ascii', 'strict')
- super(BBuf, self).write(data)
+ super().write(data)
# Stub: Buffer expecting unicode string:
@@ -31,7 +31,7 @@
# emulate Python 3 handling of stdout, stderr
if isinstance(data, bytes):
raise TypeError('must be unicode, not bytes')
- super(UBuf, self).write(data)
+ super().write(data)
class mock_stdout(UBuf):
@@ -39,7 +39,7 @@
def __init__(self):
self.buffer = BBuf()
- UBuf.__init__(self)
+ super().__init__()
class HelperTests(unittest.TestCase):
Modified: trunk/docutils/test/test_language.py
===================================================================
--- trunk/docutils/test/test_language.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_language.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -32,7 +32,7 @@
language_module_pattern = re.compile(r'^([a-z]{2,3}(_[a-z]{2,8})*)\.py$')
def __init__(self, languages=None):
- DocutilsTestSupport.CustomTestSuite.__init__(self)
+ super().__init__()
if languages:
self.languages = languages
else:
@@ -170,16 +170,11 @@
self.fail(text)
def test_roles(self):
- try:
- module = docutils.parsers.rst.languages.get_language(
- self.language)
- if not module:
- raise ImportError
- module.roles
- except ImportError:
+ module = docutils.parsers.rst.languages.get_language(self.language)
+ if not module:
self.fail('No docutils.parsers.rst.languages.%s module.'
% self.language)
- except AttributeError:
+ if not hasattr(module, "roles"):
self.fail('No "roles" mapping in docutils.parsers.rst.languages.'
'%s module.' % self.language)
failures = []
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -13,7 +13,7 @@
from test_parsers import DocutilsTestSupport
import time
-from docutils.utils.error_reporting import locale_encoding
+from docutils.io import locale_encoding
def suite():
s = DocutilsTestSupport.ParserTestSuite()
Modified: trunk/docutils/test/test_settings.py
===================================================================
--- trunk/docutils/test/test_settings.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_settings.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -130,8 +130,8 @@
except AssertionError:
print('\n%s\n' % (self,), file=sys.stderr)
print('-: expected\n+: result', file=sys.stderr)
- print(''.join(self.compare(expected.splitlines(1),
- result.splitlines(1))), file=sys.stderr)
+ print(''.join(self.compare(expected.splitlines(True),
+ result.splitlines(True))), file=sys.stderr)
raise
def test_nofiles(self):
Modified: trunk/docutils/test/test_utils.py
===================================================================
--- trunk/docutils/test/test_utils.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_utils.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -1,5 +1,4 @@
#! /usr/bin/env python3
-# -*- coding: utf-8 -*-
# $Id$
# Author: David Goodger <go...@py...>
Modified: trunk/docutils/test/test_viewlist.py
===================================================================
--- trunk/docutils/test/test_viewlist.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_viewlist.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -192,7 +192,7 @@
def setUp(self):
- self.a_list = self.text.splitlines(1)
+ self.a_list = self.text.splitlines(True)
self.a = statemachine.StringList(self.a_list, 'a')
def test_trim_left(self):
Modified: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_parts.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -599,7 +599,6 @@
</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
-])
["""\
.. figure:: dummy.png
@@ -620,6 +619,7 @@
</main>\\n''',
'html_head': '''...<title><string></title>\\n'''}
"""],
+])
totest['lazy loading'] = ({'image_loading': 'lazy',
Modified: trunk/docutils/test/test_writers/test_odt.py
===================================================================
--- trunk/docutils/test/test_writers/test_odt.py 2022-01-26 19:03:02 UTC (rev 8972)
+++ trunk/docutils/test/test_writers/test_odt.py 2022-01-26 19:03:19 UTC (rev 8973)
@@ -118,8 +118,7 @@
sep, first, sep, second, sep, )
#msg2 = '%s\n%s' % (msg1, msg, )
msg2 = '%s' % (msg, )
- DocutilsTestSupport.StandardTestCase.assertEqual(self,
- first, second, msg2)
+ super().assertEqual(first, second, msg2)
#
# Unit test methods
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|