diff options
51 files changed, 151 insertions, 369 deletions
diff --git a/docutils/test/DocutilsTestSupport.py b/docutils/test/DocutilsTestSupport.py index c25f3dbb1..4483df91e 100644 --- a/docutils/test/DocutilsTestSupport.py +++ b/docutils/test/DocutilsTestSupport.py @@ -82,9 +82,6 @@ try: 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__ @@ -192,21 +189,13 @@ class CustomTestCase(StandardTestCase): self.clear_roles() def compare_output(self, input, output, expected): - """`input`, `output`, and `expected` should all be strings.""" - if isinstance(input, unicode): + """`input` should by bytes, `output` and `expected` strings.""" + if isinstance(input, str): input = input.encode('raw_unicode_escape') - 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): - expected = expected.decode('utf-8') - if isinstance(output, bytes): - output = output.decode('utf-8') - else: - if isinstance(expected, unicode): - expected = expected.encode('raw_unicode_escape') - if isinstance(output, unicode): - output = output.encode('raw_unicode_escape') + if isinstance(expected, bytes): + expected = expected.decode('utf-8') + if isinstance(output, bytes): + output = output.decode('utf-8') # Normalize line endings: if expected: expected = '\n'.join(expected.splitlines()) @@ -847,10 +836,10 @@ def _format_str(*args): return_tuple = [] for i in args: r = repr(i) - if ( (isinstance(i, bytes) or isinstance(i, unicode)) + if ( (isinstance(i, bytes) or isinstance(i, str)) and '\n' in i): stripped = '' - if isinstance(i, unicode) and r.startswith('u'): + if isinstance(i, str) and r.startswith('u'): stripped = r[0] r = r[1:] elif isinstance(i, bytes) and r.startswith('b'): diff --git a/docutils/test/alltests.py b/docutils/test/alltests.py index 669e3da0b..16973c827 100755 --- a/docutils/test/alltests.py +++ b/docutils/test/alltests.py @@ -1,5 +1,5 @@ #!/bin/sh -''''exec python -u "$0" "$@" #''' +''''exec python3 -u "$0" "$@" #''' # $Id$ # Author: David Goodger <goodger@python.org> @@ -30,10 +30,7 @@ class Tee(object): """Write to a file and a stream (default: stdout) simultaneously.""" def __init__(self, filename, stream=sys.__stdout__): - if sys.version_info >= (3, 0): - self.file = open(filename, 'w', errors='backslashreplace') - else: - self.file = open(filename, 'w') + self.file = open(filename, 'w', errors='backslashreplace') atexit.register(self.close) self.stream = stream self.encoding = getattr(stream, 'encoding', None) diff --git a/docutils/test/test__init__.py b/docutils/test/test__init__.py index 6370b4167..c56175fd3 100644 --- a/docutils/test/test__init__.py +++ b/docutils/test/test__init__.py @@ -16,19 +16,15 @@ import docutils.utils from docutils import VersionInfo -if sys.version_info >= (3, 0): - unicode = str # noqa - - class ApplicationErrorTests(unittest.TestCase): def test_message(self): err = docutils.ApplicationError('the message') - self.assertEqual(unicode(err), u'the message') + self.assertEqual(str(err), u'the message') def test_non_ASCII_message(self): err = docutils.ApplicationError(u'\u0169') - self.assertEqual(unicode(err), u'\u0169') + self.assertEqual(str(err), u'\u0169') class VersionInfoTests(unittest.TestCase): diff --git a/docutils/test/test_command_line.py b/docutils/test/test_command_line.py index 61c5ab673..a24605269 100644 --- a/docutils/test/test_command_line.py +++ b/docutils/test/test_command_line.py @@ -32,10 +32,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): - sys.argv.append(u'--title=Dornröschen'.encode(argv_encoding)) - else: - sys.argv.append(u'--title=Dornröschen') + sys.argv.append(u'--title=Dornröschen') publisher = docutils.core.Publisher() publisher.process_command_line() self.assertEqual(publisher.settings.source_url, 'test.txt') diff --git a/docutils/test/test_dependencies.py b/docutils/test/test_dependencies.py index a2dde0ff0..78ed5c394 100755 --- a/docutils/test/test_dependencies.py +++ b/docutils/test/test_dependencies.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Lea Wiemann <LeWiemann@gmail.com> diff --git a/docutils/test/test_error_reporting.py b/docutils/test/test_error_reporting.py index 4829fd849..878d44042 100644 --- a/docutils/test/test_error_reporting.py +++ b/docutils/test/test_error_reporting.py @@ -34,55 +34,14 @@ from docutils import core, parsers, frontend, utils from docutils.utils.error_reporting import SafeString, ErrorString, ErrorOutput -oldlocale = None -if sys.version_info < (3, 0): # problems solved in py3k - try: - import locale # module missing in Jython - oldlocale = locale.getlocale() - except ImportError: - 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) -# TODO: add more confirmed problematic locales -problematic_locales = ['cs_CZ', 'cs_CZ.UTF8', - 'el_GR', 'el_GR.UTF-8', - # 'fr_FR.UTF-8', # only OSError - 'ja_JP.UTF-8', - 'ru_RU', 'ru_RU.KOI8-R', - 'ru_RU.UTF-8', - # '', # default locale: might be non-problematic - ] - -if oldlocale is not None: - # find a supported problematic locale: - for testlocale in problematic_locales: - try: - locale.setlocale(locale.LC_ALL, testlocale) - except locale.Error: - testlocale = None - else: - break - locale.setlocale(locale.LC_ALL, oldlocale) # reset -else: - testlocale = None - class SafeStringTests(unittest.TestCase): - # the error message in EnvironmentError instances comes from the OS - # and in some locales (e.g. ru_RU), contains high bit chars. - # -> see the test in test_error_reporting.py # test data: - bs = b'\xc3\xbc' # unicode(bs) fails, str(bs) in Python 3 returns repr(bs) - us = u'\xfc' # bytes(us) fails; str(us) fails in Python 2 - be = Exception(bs) # unicode(be) fails - ue = Exception(us) # bytes(ue) fails, str(ue) fails in Python 2; + bs = b'\xc3\xbc' # str(bs) returns repr(bs) + us = u'\xfc' # bytes(us) fails (requires encoding argument) + be = Exception(bs) + ue = Exception(us) # bytes(ue) fails # wrapped test data: wbs = SafeString(bs) wus = SafeString(us) @@ -96,36 +55,28 @@ class SafeStringTests(unittest.TestCase): us7 = u'foo' be7 = Exception(bs7) ue7 = Exception(us7) - self.assertEqual(str(42), str(SafeString(42))) self.assertEqual(str(bs7), str(SafeString(bs7))) self.assertEqual(str(us7), str(SafeString(us7))) self.assertEqual(str(be7), str(SafeString(be7))) self.assertEqual(str(ue7), str(SafeString(ue7))) - self.assertEqual(unicode(7), unicode(SafeString(7))) - self.assertEqual(unicode(bs7), unicode(SafeString(bs7))) - self.assertEqual(unicode(us7), unicode(SafeString(us7))) - self.assertEqual(unicode(be7), unicode(SafeString(be7))) - self.assertEqual(unicode(ue7), unicode(SafeString(ue7))) def test_ustr(self): """Test conversion to a unicode-string.""" # unicode(self.bs) fails - self.assertEqual(unicode, type(unicode(self.wbs))) - self.assertEqual(unicode(self.us), unicode(self.wus)) + self.assertEqual(str, type(str(self.wbs))) + self.assertEqual(str(self.us), str(self.wus)) # unicode(self.be) fails - self.assertEqual(unicode, type(unicode(self.wbe))) - self.assertEqual(unicode, type(unicode(self.ue))) - self.assertEqual(unicode, type(unicode(self.wue))) - self.assertEqual(self.us, unicode(self.wue)) + self.assertEqual(str, type(str(self.wbe))) + self.assertEqual(str, type(str(self.ue))) + self.assertEqual(str, type(str(self.wue))) + self.assertEqual(self.us, str(self.wue)) def test_str(self): """Test conversion to a string (bytes in Python 2, unicode in Python 3).""" self.assertEqual(str(self.bs), str(self.wbs)) - self.assertEqual(str(self.be), str(self.be)) - # str(us) fails in Python 2 - self.assertEqual(str, type(str(self.wus))) - # str(ue) fails in Python 2 - self.assertEqual(str, type(str(self.wue))) + self.assertEqual(str(self.be), str(self.wbe)) + self.assertEqual(str(self.us), str(self.wus)) + self.assertEqual(str(self.ue), str(self.wue)) class ErrorStringTests(unittest.TestCase): @@ -142,11 +93,11 @@ class ErrorStringTests(unittest.TestCase): def test_unicode(self): self.assertEqual(u'Exception: spam', - unicode(ErrorString(Exception(u'spam')))) + str(ErrorString(Exception(u'spam')))) self.assertEqual(u'IndexError: '+self.us, - unicode(ErrorString(IndexError(self.us)))) + str(ErrorString(IndexError(self.us)))) self.assertEqual(u'ImportError: %s' % SafeString(self.bs), - unicode(ErrorString(ImportError(self.bs)))) + str(ErrorString(ImportError(self.bs)))) # ErrorOutput tests @@ -155,7 +106,7 @@ class ErrorStringTests(unittest.TestCase): # Stub: Buffer with 'strict' auto-conversion of input to byte string: class BBuf(BytesIO): def write(self, data): - if isinstance(data, unicode): + if isinstance(data, str): data.encode('ascii', 'strict') super(BBuf, self).write(data) @@ -215,8 +166,6 @@ class SafeStringTests_locale(unittest.TestCase): The error message in `EnvironmentError` instances comes from the OS and in some locales (e.g. ru_RU), contains high bit chars. """ - if testlocale: - locale.setlocale(locale.LC_ALL, testlocale) # test data: bs = b'\xc3\xbc' us = u'\xfc' @@ -251,17 +200,14 @@ class SafeStringTests_locale(unittest.TestCase): wuioe = SafeString(uioe) wbose = SafeString(bose) wuose = SafeString(uose) - # reset locale - if testlocale: - locale.setlocale(locale.LC_ALL, oldlocale) def test_ustr(self): """Test conversion to a unicode-string.""" # unicode(bioe) fails with e.g. 'ru_RU.utf8' locale - self.assertEqual(unicode, type(unicode(self.wbioe))) - self.assertEqual(unicode, type(unicode(self.wuioe))) - self.assertEqual(unicode, type(unicode(self.wbose))) - self.assertEqual(unicode, type(unicode(self.wuose))) + self.assertEqual(str, type(str(self.wbioe))) + self.assertEqual(str, type(str(self.wuioe))) + self.assertEqual(str, type(str(self.wbose))) + self.assertEqual(str, type(str(self.wuose))) def test_str(self): """Test conversion to a string (bytes in Python 2, unicode in Python 3).""" @@ -293,14 +239,6 @@ class ErrorReportingTests(unittest.TestCase): settings.warning_stream = '' document = utils.new_document('test data', settings) - def setUp(self): - if testlocale: - locale.setlocale(locale.LC_ALL, testlocale) - - def tearDown(self): - if testlocale: - locale.setlocale(locale.LC_ALL, oldlocale) - def test_include(self): source = ('.. include:: bogus.txt') self.assertRaises(utils.SystemMessage, diff --git a/docutils/test/test_functional.py b/docutils/test/test_functional.py index b7f2ab92a..81025887d 100755 --- a/docutils/test/test_functional.py +++ b/docutils/test/test_functional.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - # $Id$ # Author: Lea Wiemann <LeWiemann@gmail.com> # Copyright: This module has been placed in the public domain. @@ -143,30 +142,17 @@ 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): - try: - output = output.decode(output_encoding) - except UnicodeDecodeError: - # failsafe - output = output.decode('latin1', 'replace') # Normalize line endings: output = '\n'.join(output.splitlines()) # Get the expected output *after* writing the actual output. 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): - 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') + # 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): - try: - expected = expected.decode(output_encoding) - except UnicodeDecodeError: - expected = expected.decode('latin1', 'replace') diff = self.expected_output_differs_template % { 'exp': expected_path, 'out': params['destination_path']} @@ -176,8 +162,6 @@ 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): - diff = diff.encode(sys.stderr.encoding or 'ascii', 'replace') print('\n%s:' % (self,), file=sys.stderr) print(diff, file=sys.stderr) raise diff --git a/docutils/test/test_io.py b/docutils/test/test_io.py index 6ff6f4055..66643e8e7 100755 --- a/docutils/test/test_io.py +++ b/docutils/test/test_io.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Lea Wiemann <LeWiemann@gmail.com> @@ -102,19 +102,10 @@ print("hello world") data = input.readlines() self.assertEqual(data, [u'Some include text.\n']) - def test_heuristics_utf8(self): - # 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): - # in Py3k, the locale encoding is used without --input-encoding - # skipping the heuristic - self.assertEqual(input.successful_encoding, 'utf-8') - 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 locale_encoding != "utf8": # in Py3k, the locale encoding is used without --input-encoding # skipping the heuristic unless decoding fails. return @@ -157,16 +148,10 @@ class OutputTests(unittest.TestCase): self.assertEqual(self.udrain.getvalue(), self.udata) def test_write_utf8(self): - if sys.version_info >= (3, 0): - fo = io.FileOutput(destination=self.udrain, encoding='utf8', - autoclose=False) - fo.write(self.udata) - self.assertEqual(self.udrain.getvalue(), self.udata) - else: - fo = io.FileOutput(destination=self.bdrain, encoding='utf8', - autoclose=False) - fo.write(self.udata) - self.assertEqual(self.bdrain.getvalue(), self.udata.encode('utf8')) + fo = io.FileOutput(destination=self.udrain, encoding='utf8', + autoclose=False) + fo.write(self.udata) + self.assertEqual(self.udrain.getvalue(), self.udata) def test_FileOutput_hande_io_errors_deprection_warning(self): with warnings.catch_warnings(record=True) as wng: @@ -183,28 +168,26 @@ class OutputTests(unittest.TestCase): fo.write(self.bdata) self.assertEqual(self.bdrain.getvalue(), self.bdata) - # Test for Python 3 features: - 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: - fo = io.FileOutput(destination=self.mock_stdout) - fo.write(self.bdata) - self.assertEqual(self.mock_stdout.buffer.getvalue(), - self.bdata) - - def test_encoding_clash_resolved(self): - fo = io.FileOutput(destination=self.mock_stdout, - encoding='latin1', autoclose=False) - fo.write(self.udata) - self.assertEqual(self.mock_stdout.buffer.getvalue(), - self.udata.encode('latin1')) - - def test_encoding_clash_nonresolvable(self): - del(self.mock_stdout.buffer) - fo = io.FileOutput(destination=self.mock_stdout, - encoding='latin1', autoclose=False) - self.assertRaises(ValueError, fo.write, self.udata) + def test_write_bytes_to_stdout(self): + # try writing data to `destination.buffer`, if data is + # instance of `bytes` and writing to `destination` fails: + fo = io.FileOutput(destination=self.mock_stdout) + fo.write(self.bdata) + self.assertEqual(self.mock_stdout.buffer.getvalue(), + self.bdata) + + def test_encoding_clash_resolved(self): + fo = io.FileOutput(destination=self.mock_stdout, + encoding='latin1', autoclose=False) + fo.write(self.udata) + self.assertEqual(self.mock_stdout.buffer.getvalue(), + self.udata.encode('latin1')) + + def test_encoding_clash_nonresolvable(self): + del(self.mock_stdout.buffer) + fo = io.FileOutput(destination=self.mock_stdout, + encoding='latin1', autoclose=False) + self.assertRaises(ValueError, fo.write, self.udata) if __name__ == '__main__': diff --git a/docutils/test/test_language.py b/docutils/test/test_language.py index af717ccf9..1f32f6ae8 100755 --- a/docutils/test/test_language.py +++ b/docutils/test/test_language.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Authors: Engelbert Gruber <grubert@users.sourceforge.net>; @@ -26,9 +26,6 @@ _reporter = docutils.utils.new_reporter('', _settings) reference_language = 'en' -if sys.version_info >= (3, 0): - unicode = str # noqa - class LanguageTestSuite(DocutilsTestSupport.CustomTestSuite): @@ -158,7 +155,7 @@ class LanguageTestCase(DocutilsTestSupport.CustomTestCase): if failures: text = ('Module docutils.parsers.rst.languages.%s:\n %s' % (self.language, '\n '.join(failures))) - if isinstance(text, unicode): + if isinstance(text, str): text = text.encode('raw_unicode_escape') self.fail(text) @@ -192,7 +189,7 @@ class LanguageTestCase(DocutilsTestSupport.CustomTestCase): if failures: text = ('Module docutils.parsers.rst.languages.%s:\n %s' % (self.language, '\n '.join(failures))) - if isinstance(text, unicode): + if isinstance(text, str): text = text.encode('raw_unicode_escape') self.fail(text) diff --git a/docutils/test/test_nodes.py b/docutils/test/test_nodes.py index 7360945e0..3f354a85d 100755 --- a/docutils/test/test_nodes.py +++ b/docutils/test/test_nodes.py @@ -1,5 +1,4 @@ #! /usr/bin/env python3 - # $Id$ # Author: David Goodger <goodger@python.org> # Copyright: This module has been placed in the public domain. @@ -17,9 +16,6 @@ from DocutilsTestSupport import nodes, utils debug = False -if sys.version_info >= (3, 0): - unicode = str # noqa - class TextTests(unittest.TestCase): @@ -36,25 +32,22 @@ 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): - self.assertEqual(repr(self.unicode_text), r"<#text: 'M\xf6hren'>") - else: - self.assertEqual(repr(self.unicode_text), u"<#text: 'Möhren'>") + self.assertEqual(repr(self.unicode_text), u"<#text: 'Möhren'>") def test_str(self): self.assertEqual(str(self.text), 'Line 1.\nLine 2.') def test_unicode(self): - self.assertEqual(unicode(self.unicode_text), u'Möhren') + self.assertEqual(str(self.unicode_text), u'Möhren') self.assertEqual(str(self.unicode_text), 'M\xf6hren') def test_astext(self): - self.assertTrue(isinstance(self.text.astext(), unicode)) + self.assertTrue(isinstance(self.text.astext(), str)) self.assertEqual(self.text.astext(), u'Line 1.\nLine 2.') self.assertEqual(self.unicode_text.astext(), u'Möhren') def test_pformat(self): - self.assertTrue(isinstance(self.text.pformat(), unicode)) + self.assertTrue(isinstance(self.text.pformat(), str)) self.assertEqual(self.text.pformat(), u'Line 1.\nLine 2.\n') def test_strip(self): @@ -65,12 +58,8 @@ class TextTests(unittest.TestCase): self.assertEqual(stripped2, u's noc') def test_asciirestriction(self): - if sys.version_info < (3, 0): - self.assertRaises(UnicodeDecodeError, nodes.Text, - b'hol%s' % chr(224)) - else: - # no bytes at all allowed - self.assertRaises(TypeError, nodes.Text, b'hol') + # no bytes at all allowed + self.assertRaises(TypeError, nodes.Text, b'hol') def test_longrepr(self): self.assertEqual(repr(self.longtext), r"<#text: 'Mary had a " @@ -106,29 +95,19 @@ class ElementTests(unittest.TestCase): del element['attr'] element['mark'] = u'\u2022' self.assertEqual(repr(element), '<Element: >') - if sys.version_info < (3, 0): - self.assertEqual(str(element), '<Element mark="\\u2022"/>') - else: - self.assertEqual(str(element), u'<Element mark="\u2022"/>') + self.assertEqual(str(element), u'<Element mark="\u2022"/>') dom = element.asdom() self.assertEqual(dom.toxml(), u'<Element mark="\u2022"/>') dom.unlink() element['names'] = ['nobody', u'имя', u'näs'] - if sys.version_info < (3, 0): - self.assertEqual(repr(element), - '<Element "nobody; \\u0438\\u043c\\u044f; n\\xe4s": >') - else: - self.assertEqual(repr(element), u'<Element "nobody; имя; näs": >') + self.assertEqual(repr(element), u'<Element "nobody; имя; näs": >') self.assertTrue(isinstance(repr(element), str)) def test_withtext(self): 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): - self.assertEqual(repr(uelement), "<Element: <#text: 'gr\\xfcn'>>") - else: - self.assertEqual(repr(uelement), u"<Element: <#text: 'grün'>>") + self.assertEqual(repr(uelement), u"<Element: <#text: 'grün'>>") self.assertTrue(isinstance(repr(uelement), str)) self.assertEqual(str(element), '<Element>text\nmore</Element>') self.assertEqual(str(uelement), '<Element>gr\xfcn</Element>') @@ -339,29 +318,23 @@ class ElementTests(unittest.TestCase): def test_unicode(self): node = nodes.Element(u'Möhren', nodes.Text(u'Möhren')) - self.assertEqual(unicode(node), u'<Element>Möhren</Element>') + self.assertEqual(str(node), u'<Element>Möhren</Element>') class MiscTests(unittest.TestCase): def test_reprunicode(self): # return `unicode` instance - self.assertTrue(isinstance(nodes.reprunicode('foo'), unicode)) + self.assertTrue(isinstance(nodes.reprunicode('foo'), str)) 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 - self.assertEqual(repr(nodes.reprunicode(u'Möhre')), - repr(u'Möhre')[1:]) - else: # no change to `unicode` under Python 3k - self.assertEqual(repr(nodes.reprunicode(u'Möhre')), repr(u'Möhre')) + # no change to `unicode` under Python 3k + self.assertEqual(repr(nodes.reprunicode(u'Möhre')), repr(u'Möhre')) 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 - self.assertEqual(nodes.ensure_str(u'über'), r'\xfcber') - else: - self.assertEqual(nodes.ensure_str(u'über'), r'über') + self.assertEqual(nodes.ensure_str(u'über'), r'über') def test_node_class_names(self): node_class_names = [] @@ -553,7 +526,7 @@ class MiscTests(unittest.TestCase): if failures: self.fail("%d failures in %d\n%s" % (len(failures), len(self.ids), "\n".join(failures))) - def test_traverse(self): + def test_findall(self): e = nodes.Element() e += nodes.Element() e[0] += nodes.Element() @@ -561,33 +534,33 @@ class MiscTests(unittest.TestCase): e[0][1] += nodes.Text('some text') e += nodes.Element() e += nodes.Element() - self.assertEqual(list(e.traverse()), + self.assertEqual(list(e.findall()), [e, e[0], e[0][0], e[0][1], e[0][1][0], e[1], e[2]]) - self.assertEqual(list(e.traverse(include_self=False)), + self.assertEqual(list(e.findall(include_self=False)), [e[0], e[0][0], e[0][1], e[0][1][0], e[1], e[2]]) - self.assertEqual(list(e.traverse(descend=False)), + self.assertEqual(list(e.findall(descend=False)), [e]) - self.assertEqual(list(e[0].traverse(descend=False, ascend=True)), + self.assertEqual(list(e[0].findall(descend=False, ascend=True)), [e[0], e[1], e[2]]) - self.assertEqual(list(e[0][0].traverse(descend=False, ascend=True)), + self.assertEqual(list(e[0][0].findall(descend=False, ascend=True)), [e[0][0], e[0][1], e[1], e[2]]) - self.assertEqual(list(e[0][0].traverse(descend=False, siblings=True)), + self.assertEqual(list(e[0][0].findall(descend=False, siblings=True)), [e[0][0], e[0][1]]) self.testlist = e[0:2] - self.assertEqual(list(e.traverse(condition=self.not_in_testlist)), + self.assertEqual(list(e.findall(condition=self.not_in_testlist)), [e, e[0][0], e[0][1], e[0][1][0], e[2]]) # Return siblings despite siblings=False because ascend is true. - self.assertEqual(list(e[1].traverse(ascend=True, siblings=False)), + self.assertEqual(list(e[1].findall(ascend=True, siblings=False)), [e[1], e[2]]) - self.assertEqual(list(e[0].traverse()), + self.assertEqual(list(e[0].findall()), [e[0], e[0][0], e[0][1], e[0][1][0]]) self.testlist = [e[0][0], e[0][1]] - self.assertEqual(list(e[0].traverse(condition=self.not_in_testlist)), + self.assertEqual(list(e[0].findall(condition=self.not_in_testlist)), [e[0], e[0][1][0]]) self.testlist.append(e[0][1][0]) - self.assertEqual(list(e[0].traverse(condition=self.not_in_testlist)), + self.assertEqual(list(e[0].findall(condition=self.not_in_testlist)), [e[0]]) - self.assertEqual(list(e.traverse(nodes.TextElement)), [e[0][1]]) + self.assertEqual(list(e.findall(nodes.TextElement)), [e[0][1]]) def test_next_node(self): e = nodes.Element() diff --git a/docutils/test/test_parsers/test_parser.py b/docutils/test/test_parsers/test_parser.py index 3cabe6264..3a9ca9630 100644 --- a/docutils/test/test_parsers/test_parser.py +++ b/docutils/test/test_parsers/test_parser.py @@ -1,5 +1,4 @@ -#! /usr/bin/env python - +#! /usr/bin/env python3 # $Id$ # Author: Stefan Rank <strank(AT)strank(DOT)info> # Copyright: This module has been placed in the public domain. @@ -10,6 +9,9 @@ Tests for basic functionality of parser classes. import sys import unittest + +if __name__ == '__main__': + import __init__ import DocutilsTestSupport # must be imported before docutils import docutils from docutils import parsers, utils, frontend @@ -22,14 +24,8 @@ class RstParserTests(unittest.TestCase): parser = parser_class() document = utils.new_document('test data', frontend.OptionParser( components=(parser, )).get_default_values()) - - 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) - else: - # input must be unicode at all times - self.assertRaises(TypeError, parser.parse, b'hol', document) + # input must be unicode at all times + self.assertRaises(TypeError, parser.parse, b'hol', document) if __name__ == '__main__': diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions.py b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions.py index 01e6a815f..d521b08c7 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_de.py b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_de.py index 3d96797f5..de8bc4336 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_de.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_de.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py index 94653a968..005c95a48 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py b/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py index bf20f3f1a..6298c7d16 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Lea Wiemann <LeWiemann@gmail.com> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py index 0237ef72c..92277a77b 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Guenter Milde diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py index aa4acded5..52f226124 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Guenter Milde diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_container.py b/docutils/test/test_parsers/test_rst/test_directives/test_container.py index a1a62883a..7630adba8 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_container.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_container.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py b/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py index 62068d1e9..d49f9a198 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py b/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py index 1bb4b6879..eb7206f7e 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_include.py b/docutils/test/test_parsers/test_rst/test_directives/test_include.py index 4e99144a1..659b5a3e5 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_include.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_include.py @@ -1,5 +1,4 @@ #! /usr/bin/env python3 - # $Id$ # Author: David Goodger <goodger@python.org> # Copyright: This module has been placed in the public domain. @@ -16,9 +15,6 @@ from test_parsers 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() @@ -51,10 +47,6 @@ include_md = mydir('include.md') 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): - utf_16_error_str = ("UnicodeError: Unable to decode input data. " - "Tried the following encodings: 'ascii'.\n" - " (%s)" % utf_16_error_str) nonexistent = os.path.join(os.path.dirname(states.__file__), 'include', 'nonexistent') nonexistent_rel = DocutilsTestSupport.utils.relative_path( @@ -814,7 +806,7 @@ Testing errors in included file: .. end of inclusion from "test_parsers/test_rst/test_directives/include10.txt" """ % {'source': reldir(include10), 'nonexistent': reldir(nonexistent), 'unichr_exception': - DocutilsTestSupport.exception_data(unichr, int("11111111", 16))[2] + DocutilsTestSupport.exception_data(chr, int("11111111", 16))[2] }], ["""\ Include file with whitespace in the path: diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py b/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py index f585595f2..5c67ba77e 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py b/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py index 539daf02c..218940de7 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Lea Wiemann <LeWiemann@gmail.com> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_raw.py b/docutils/test/test_parsers/test_rst/test_directives/test_raw.py index 8d4dad1f2..7ba6774b2 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_raw.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_raw.py @@ -27,10 +27,6 @@ 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): - utf_16_error_str = ("UnicodeError: Unable to decode input data. " - "Tried the following encodings: 'ascii'.\n" - " (%s)" % utf_16_error_str) totest = {} diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py b/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py index 53980d663..b93b711f6 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id: test_replace.py 4667 2006-07-12 21:40:56Z wiemann $ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_tables.py b/docutils/test/test_parsers/test_rst/test_directives/test_tables.py index 9aa5495f4..0aa46f4f5 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_tables.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_tables.py @@ -19,11 +19,6 @@ from test_parsers import DocutilsTestSupport 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) @@ -35,30 +30,23 @@ utf_16_csv_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_csv) empty_txt = os.path.join(mydir, 'empty.txt') unichr_exception = DocutilsTestSupport.exception_data( - unichr, int("9999999999999", 16))[0] + chr, int("9999999999999", 16))[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: unichr_exception_string = str(unichr_exception) -# some error messages changed in Python 3.3, CPython has backported to 2.7.4, -# PyPy has not csv_eod_error_str = 'unexpected end of data' -if sys.version_info < (2,7,4) or (platform.python_implementation() == 'PyPy' - and sys.version_info < (3,0)): - csv_eod_error_str = 'newline inside string' # pypy adds a line number if platform.python_implementation() == 'PyPy': csv_eod_error_str = 'line 1: ' + csv_eod_error_str csv_unknown_url = "'bogus.csv'" -if sys.version_info < (3, 0): - csv_unknown_url = "bogus.csv" def null_bytes(): with open(utf_16_csv, 'rb') as f: csv_data = f.read() - csv_data = unicode(csv_data, 'latin1').splitlines() + csv_data = str(csv_data, 'latin1').splitlines() reader = csv.reader([tables.CSVTable.encode_for_csv(line + '\n') for line in csv_data]) next(reader) @@ -897,11 +885,11 @@ u"""\ <system_message level="4" line="1" source="test data" type="SEVERE"> <paragraph> Problems with "csv-table" directive URL "bogus.csv": - unknown url type: %s. + unknown url type: 'bogus.csv'. <literal_block xml:space="preserve"> .. csv-table:: bad URL :url: bogus.csv -""" % csv_unknown_url], +"""], ["""\ .. csv-table:: column mismatch :widths: 10,20 diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py b/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py index 7e922eefd..5629debae 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py b/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py index df71576b4..0201b0d0f 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py b/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py index 7764bf91c..26860fff5 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py @@ -15,17 +15,13 @@ if __name__ == '__main__': from test_parsers import DocutilsTestSupport -if sys.version_info >= (3, 0): - unichr = chr # noqa - - def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s unichr_exception = DocutilsTestSupport.exception_data( - unichr, int("111111111111111111", 16))[0] + chr, int("111111111111111111", 16))[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: @@ -171,7 +167,7 @@ u"""\ <literal_block xml:space="preserve"> .. |too big for unicode| unicode:: 0x11111111 """ % (unichr_exception_string, - DocutilsTestSupport.exception_data(unichr, int("11111111", 16))[2])] + DocutilsTestSupport.exception_data(chr, int("11111111", 16))[2])] ] diff --git a/docutils/test/test_pickle.py b/docutils/test/test_pickle.py index b1a987f16..19348febf 100755 --- a/docutils/test/test_pickle.py +++ b/docutils/test/test_pickle.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> # Copyright: This module has been placed in the public domain. diff --git a/docutils/test/test_publisher.py b/docutils/test/test_publisher.py index 181197188..1180e6c68 100755 --- a/docutils/test/test_publisher.py +++ b/docutils/test/test_publisher.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: Martin Blais <blais@furius.ca> @@ -15,10 +15,7 @@ import DocutilsTestSupport # must be imported before docutils import docutils from docutils import core, nodes, io -if sys.version_info < (3, 0): - u_prefix = 'u' -else: - u_prefix = b'' +u_prefix = b'' test_document = """\ diff --git a/docutils/test/test_transforms/test_substitution_expansion_length_limit.py b/docutils/test/test_transforms/test_substitution_expansion_length_limit.py index 2218c8d83..698c297af 100644 --- a/docutils/test/test_transforms/test_substitution_expansion_length_limit.py +++ b/docutils/test/test_transforms/test_substitution_expansion_length_limit.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_traversals.py b/docutils/test/test_traversals.py index b0a65107d..f220c43ee 100755 --- a/docutils/test/test_traversals.py +++ b/docutils/test/test_traversals.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: Martin Blais <blais@furius.ca> diff --git a/docutils/test/test_utils.py b/docutils/test/test_utils.py index 7d148c971..30a549b80 100755 --- a/docutils/test/test_utils.py +++ b/docutils/test/test_utils.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # $Id$ @@ -15,11 +15,7 @@ import unittest from DocutilsTestSupport import docutils, utils, nodes -if sys.version_info >= (3, 0): - from io import StringIO - unicode = str -else: - from StringIO import StringIO +from io import StringIO class ReporterTests(unittest.TestCase): @@ -293,8 +289,8 @@ class HelperFunctionTests(unittest.TestCase): self.assertEqual(unipath, u'späm') self.assertEqual(defaultpath, u'') self.assertTrue(isinstance(bytespath, nodes.reprunicode)) - self.assertTrue(isinstance(unipath, unicode)) - self.assertTrue(isinstance(defaultpath, unicode)) + self.assertTrue(isinstance(unipath, str)) + self.assertTrue(isinstance(defaultpath, str)) self.assertRaises(ValueError, utils.decode_path, 13) def test_relative_path(self): diff --git a/docutils/test/test_viewlist.py b/docutils/test/test_viewlist.py index 00f36a255..bfa6604c7 100755 --- a/docutils/test/test_viewlist.py +++ b/docutils/test/test_viewlist.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/test/test_writers/test_docutils_xml.py b/docutils/test/test_writers/test_docutils_xml.py index 5b3b93308..d4b9179f7 100755 --- a/docutils/test/test_writers/test_docutils_xml.py +++ b/docutils/test/test_writers/test_docutils_xml.py @@ -22,10 +22,7 @@ from test_writers import DocutilsTestSupport # before importing docutils! import docutils import docutils.core -if sys.version_info >= (3, 0): - from io import StringIO -else: - from StringIO import StringIO +from io import StringIO # sample strings # -------------- diff --git a/docutils/tools/buildhtml.py b/docutils/tools/buildhtml.py index 7d3280852..e638187e5 100755 --- a/docutils/tools/buildhtml.py +++ b/docutils/tools/buildhtml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/dev/create_unimap.py b/docutils/tools/dev/create_unimap.py index eba354208..9bc7fa595 100755 --- a/docutils/tools/dev/create_unimap.py +++ b/docutils/tools/dev/create_unimap.py @@ -13,17 +13,6 @@ from xml.dom import minidom import sys import pprint -if sys.version_info >= (3, 0): - unicode = str #noqa -else: - bytes = str # noqa - chr = unichr # noqa - - -def w(s): - if sys.version_info >= (3, 0) and isinstance(s, unicode): - s = s.encode('utf8') - sys.stdout.write(s) text_map = {} math_map = {} diff --git a/docutils/tools/dev/generate_punctuation_chars.py b/docutils/tools/dev/generate_punctuation_chars.py index 08d2a11c9..16df487b5 100644 --- a/docutils/tools/dev/generate_punctuation_chars.py +++ b/docutils/tools/dev/generate_punctuation_chars.py @@ -35,12 +35,6 @@ import sys import unicodedata -if sys.version_info >= (3, 0): - unichr = chr # unichr not available in Py3k -else: - import codecs - sys.stdout = codecs.getwriter('UTF-8')(sys.stdout) - # Template for utils.punctuation_chars # ------------------------------------ @@ -174,12 +168,12 @@ def unicode_charlists(categories, cp_min=0, cp_max=None): # categories with not too high characters): if cp_max is None: cp_max = max(x for x in range(sys.maxunicode+1) - if unicodedata.category(unichr(x)) in categories) + if unicodedata.category(chr(x)) in categories) # print(cp_max) # => 74867 for unicode_punctuation_categories charlists = {} for cat in categories: - charlists[cat] = [unichr(x) for x in range(cp_min, cp_max+1) - if unicodedata.category(unichr(x)) == cat] + charlists[cat] = [chr(x) for x in range(cp_min, cp_max+1) + if unicodedata.category(chr(x)) == cat] return charlists @@ -277,7 +271,7 @@ def mark_intervals(s): l2 = [] for i in l: - i = [unichr(n) for n in i] + i = [chr(n) for n in i] if len(i) > 2: i = i[0], u'-', i[-1] l2.extend(i) @@ -357,10 +351,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): - sys.path.insert(0, '../../docutils') - else: - sys.path.insert(0, '../../build/lib') + sys.path.insert(0, '../../docutils') from docutils.utils.punctuation_chars import (openers, closers, delimiters, closing_delimiters) @@ -371,16 +362,10 @@ if __name__ == '__main__': print_differences(openers, o, 'openers') if o_wide: - if sys.version_info < (3, 0): - print('+ openers-wide = ur"""%s"""' % o_wide.encode('utf8')) - else: - print('+ openers-wide = r"""%s"""' % o_wide.encode('utf8')) + print('+ openers-wide = r"""%s"""' % o_wide.encode('utf8')) print_differences(closers, c, 'closers') if c_wide: - if sys.version_info < (3, 0): - print('+ closers-wide = ur"""%s"""' % c_wide.encode('utf8')) - else: - print('+ closers-wide = r"""%s"""' % c_wide.encode('utf8')) + print('+ closers-wide = r"""%s"""' % c_wide.encode('utf8')) print_differences(delimiters, d + d_wide, 'delimiters') print_differences(closing_delimiters, cd, 'closing_delimiters') diff --git a/docutils/tools/dev/unicode2rstsubs.py b/docutils/tools/dev/unicode2rstsubs.py index d202c93d5..6bc30acf6 100755 --- a/docutils/tools/dev/unicode2rstsubs.py +++ b/docutils/tools/dev/unicode2rstsubs.py @@ -1,5 +1,4 @@ #! /usr/bin/env python3 - # $Id$ # Author: David Goodger <goodger@python.org> # Copyright: This program has been placed in the public domain. @@ -47,10 +46,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): - infile = open(inpath, mode='rb') - else: - infile = open(inpath) + infile = open(inpath, mode='rb') process(infile) def process(infile): diff --git a/docutils/tools/rst2html.py b/docutils/tools/rst2html.py index 77185df2b..fc8bf3751 100755 --- a/docutils/tools/rst2html.py +++ b/docutils/tools/rst2html.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/rst2html4.py b/docutils/tools/rst2html4.py index a91f96a3f..a32368e6e 100755 --- a/docutils/tools/rst2html4.py +++ b/docutils/tools/rst2html4.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/rst2latex.py b/docutils/tools/rst2latex.py index 94b8bfa96..07975aee0 100755 --- a/docutils/tools/rst2latex.py +++ b/docutils/tools/rst2latex.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/rst2man.py b/docutils/tools/rst2man.py index 5bb178270..2aafbaf06 100755 --- a/docutils/tools/rst2man.py +++ b/docutils/tools/rst2man.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Author: # Contact: grubert@users.sf.net diff --git a/docutils/tools/rst2odt.py b/docutils/tools/rst2odt.py index 369fa386f..3c5ec896b 100755 --- a/docutils/tools/rst2odt.py +++ b/docutils/tools/rst2odt.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: Dave Kuhlman <dkuhlman@rexx.com> diff --git a/docutils/tools/rst2pseudoxml.py b/docutils/tools/rst2pseudoxml.py index b3111f4d0..a7b7a02cc 100755 --- a/docutils/tools/rst2pseudoxml.py +++ b/docutils/tools/rst2pseudoxml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/rst2s5.py b/docutils/tools/rst2s5.py index 3fd046f22..de1861fb9 100755 --- a/docutils/tools/rst2s5.py +++ b/docutils/tools/rst2s5.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: Chris Liechti <cliechti@gmx.net> diff --git a/docutils/tools/rst2xetex.py b/docutils/tools/rst2xetex.py index 2460c4d11..80e82c05c 100755 --- a/docutils/tools/rst2xetex.py +++ b/docutils/tools/rst2xetex.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: Guenter Milde diff --git a/docutils/tools/rst2xml.py b/docutils/tools/rst2xml.py index 20eb35e9a..522c024ce 100755 --- a/docutils/tools/rst2xml.py +++ b/docutils/tools/rst2xml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/rstpep2html.py b/docutils/tools/rstpep2html.py index 9a3d615cb..4ef81f6b2 100755 --- a/docutils/tools/rstpep2html.py +++ b/docutils/tools/rstpep2html.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: David Goodger <goodger@python.org> diff --git a/docutils/tools/test/test_buildhtml.py b/docutils/tools/test/test_buildhtml.py index 833187579..b362239ec 100644 --- a/docutils/tools/test/test_buildhtml.py +++ b/docutils/tools/test/test_buildhtml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # $Id$ # Author: engelbert gruber <grubert@users.sourceforge.net> |
