6b24f153d7
All of those patches are picked from upstream. xbps-src check python3-docutils works fine now!
719 lines
33 KiB
Diff
719 lines
33 KiB
Diff
From c361270fb4ee9172a337f5e9c0b014b362fb0b71 Mon Sep 17 00:00:00 2001
|
|
From: Stephen Finucane <stephen@that.guru>
|
|
Date: Tue, 19 Nov 2019 23:49:35 +0700
|
|
Subject: [PATCH 03/26] py3: Switch to 'except foo as bar' syntax
|
|
|
|
This is the only form supported in Python 3.x.
|
|
|
|
Signed-off-by: Stephen Finucane <stephen@that.guru>
|
|
|
|
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8347 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
|
|
Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
|
|
---
|
|
docutils/core.py | 4 ++--
|
|
docutils/frontend.py | 8 ++++----
|
|
docutils/io.py | 12 ++++++------
|
|
docutils/parsers/rst/directives/__init__.py | 6 +++---
|
|
docutils/parsers/rst/directives/body.py | 2 +-
|
|
docutils/parsers/rst/directives/html.py | 2 +-
|
|
docutils/parsers/rst/directives/misc.py | 20 ++++++++++----------
|
|
docutils/parsers/rst/directives/tables.py | 10 +++++-----
|
|
docutils/parsers/rst/roles.py | 4 ++--
|
|
docutils/parsers/rst/states.py | 20 ++++++++++----------
|
|
docutils/statemachine.py | 6 +++---
|
|
docutils/utils/__init__.py | 2 +-
|
|
docutils/utils/error_reporting.py | 4 ++--
|
|
docutils/writers/_html_base.py | 4 ++--
|
|
docutils/writers/docutils_xml.py | 2 +-
|
|
docutils/writers/latex2e/__init__.py | 2 +-
|
|
test/DocutilsTestSupport.py | 8 ++++----
|
|
test/package_unittest.py | 2 +-
|
|
test/test_error_reporting.py | 14 +++++++-------
|
|
test/test_language.py | 4 ++--
|
|
test/test_publisher.py | 4 ++--
|
|
test/test_utils.py | 2 +-
|
|
22 files changed, 71 insertions(+), 71 deletions(-)
|
|
|
|
diff --git a/docutils/core.py b/docutils/core.py
|
|
index 6a99020..12a0c93 100644
|
|
--- a/docutils/core.py
|
|
+++ b/docutils/core.py
|
|
@@ -219,10 +219,10 @@ class Publisher(object):
|
|
self.apply_transforms()
|
|
output = self.writer.write(self.document, self.destination)
|
|
self.writer.assemble_parts()
|
|
- except SystemExit, error:
|
|
+ except SystemExit as error:
|
|
exit = 1
|
|
exit_status = error.code
|
|
- except Exception, error:
|
|
+ except Exception as error:
|
|
if not self.settings: # exception too early to report nicely
|
|
raise
|
|
if self.settings.traceback: # Propagate exceptions?
|
|
diff --git a/docutils/frontend.py b/docutils/frontend.py
|
|
index 1aeae5c..689d904 100644
|
|
--- a/docutils/frontend.py
|
|
+++ b/docutils/frontend.py
|
|
@@ -62,7 +62,7 @@ def read_config_file(option, opt, value, parser):
|
|
"""
|
|
try:
|
|
new_settings = parser.get_config_file_settings(value)
|
|
- except ValueError, error:
|
|
+ except ValueError as error:
|
|
parser.error(error)
|
|
parser.values.update(new_settings, parser)
|
|
|
|
@@ -346,7 +346,7 @@ class Option(optparse.Option):
|
|
value = getattr(values, setting)
|
|
try:
|
|
new_value = self.validator(setting, value, parser)
|
|
- except Exception, error:
|
|
+ except Exception as error:
|
|
raise (optparse.OptionValueError(
|
|
'Error in option "%s":\n %s'
|
|
% (opt, ErrorString(error))),
|
|
@@ -605,7 +605,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
|
|
if read_config_files and not self.defaults['_disable_config']:
|
|
try:
|
|
config_settings = self.get_standard_config_settings()
|
|
- except ValueError, error:
|
|
+ except ValueError as error:
|
|
self.error(SafeString(error))
|
|
self.set_defaults_from_dict(config_settings.__dict__)
|
|
|
|
@@ -826,7 +826,7 @@ Skipping "%s" configuration file.
|
|
new_value = option.validator(
|
|
setting, value, option_parser,
|
|
config_parser=self, config_section=section)
|
|
- except Exception, error:
|
|
+ except Exception as error:
|
|
raise (ValueError(
|
|
'Error in config file "%s", section "[%s]":\n'
|
|
' %s\n'
|
|
diff --git a/docutils/io.py b/docutils/io.py
|
|
index 3b0f93e..4466fdb 100644
|
|
--- a/docutils/io.py
|
|
+++ b/docutils/io.py
|
|
@@ -114,7 +114,7 @@ class Input(TransformSpec):
|
|
self.successful_encoding = enc
|
|
# Return decoded, removing BOMs.
|
|
return decoded.replace(u'\ufeff', u'')
|
|
- except (UnicodeError, LookupError), err:
|
|
+ except (UnicodeError, LookupError) as err:
|
|
error = err # in Python 3, the <exception instance> is
|
|
# local to the except clause
|
|
raise UnicodeError(
|
|
@@ -244,7 +244,7 @@ class FileInput(Input):
|
|
|
|
try:
|
|
self.source = open(source_path, mode, **kwargs)
|
|
- except IOError, error:
|
|
+ except IOError as error:
|
|
raise InputError(error.errno, error.strerror, source_path)
|
|
else:
|
|
self.source = sys.stdin
|
|
@@ -272,7 +272,7 @@ class FileInput(Input):
|
|
data = b'\n'.join(data.splitlines()) + b'\n'
|
|
else:
|
|
data = self.source.read()
|
|
- except (UnicodeError, LookupError), err: # (in Py3k read() decodes)
|
|
+ except (UnicodeError, LookupError) as err: # (in Py3k read() decodes)
|
|
if not self.encoding and self.source_path:
|
|
# re-read in binary mode and decode with heuristics
|
|
b_source = open(self.source_path, 'rb')
|
|
@@ -362,7 +362,7 @@ class FileOutput(Output):
|
|
kwargs = {}
|
|
try:
|
|
self.destination = open(self.destination_path, self.mode, **kwargs)
|
|
- except IOError, error:
|
|
+ except IOError as error:
|
|
raise OutputError(error.errno, error.strerror,
|
|
self.destination_path)
|
|
self.opened = True
|
|
@@ -384,7 +384,7 @@ class FileOutput(Output):
|
|
|
|
try:
|
|
self.destination.write(data)
|
|
- except TypeError, e:
|
|
+ except TypeError as e:
|
|
if sys.version_info >= (3,0) and isinstance(data, bytes):
|
|
try:
|
|
self.destination.buffer.write(data)
|
|
@@ -397,7 +397,7 @@ class FileOutput(Output):
|
|
self.destination.encoding, self.encoding))
|
|
else:
|
|
raise e
|
|
- except (UnicodeError, LookupError), err:
|
|
+ except (UnicodeError, LookupError) as err:
|
|
raise UnicodeError(
|
|
'Unable to encode output data. output-encoding is: '
|
|
'%s.\n(%s)' % (self.encoding, ErrorString(err)))
|
|
diff --git a/docutils/parsers/rst/directives/__init__.py b/docutils/parsers/rst/directives/__init__.py
|
|
index e0d09fc..8789346 100644
|
|
--- a/docutils/parsers/rst/directives/__init__.py
|
|
+++ b/docutils/parsers/rst/directives/__init__.py
|
|
@@ -86,7 +86,7 @@ def directive(directive_name, language_module, document):
|
|
canonicalname = None
|
|
try:
|
|
canonicalname = language_module.directives[normname]
|
|
- except AttributeError, error:
|
|
+ except AttributeError as error:
|
|
msg_text.append('Problem retrieving directive entry from language '
|
|
'module %r: %s.' % (language_module, error))
|
|
except KeyError:
|
|
@@ -113,7 +113,7 @@ def directive(directive_name, language_module, document):
|
|
return None, messages
|
|
try:
|
|
module = __import__(modulename, globals(), locals(), level=1)
|
|
- except ImportError, detail:
|
|
+ except ImportError as detail:
|
|
messages.append(document.reporter.error(
|
|
'Error importing directive module "%s" (directive "%s"):\n%s'
|
|
% (modulename, directive_name, detail),
|
|
@@ -309,7 +309,7 @@ def unicode_code(code):
|
|
return unichr(int(value, 16))
|
|
else: # other text
|
|
return code
|
|
- except OverflowError, detail:
|
|
+ except OverflowError as detail:
|
|
raise ValueError('code too large (%s)' % detail)
|
|
|
|
def single_char_or_unicode(argument):
|
|
diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py
|
|
index b60c3ad..eef1df5 100644
|
|
--- a/docutils/parsers/rst/directives/body.py
|
|
+++ b/docutils/parsers/rst/directives/body.py
|
|
@@ -147,7 +147,7 @@ class CodeBlock(Directive):
|
|
try:
|
|
tokens = Lexer(u'\n'.join(self.content), language,
|
|
self.state.document.settings.syntax_highlight)
|
|
- except LexerError, error:
|
|
+ except LexerError as error:
|
|
raise self.warning(error)
|
|
|
|
if 'number-lines' in self.options:
|
|
diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py
|
|
index 78671e8..ea36936 100644
|
|
--- a/docutils/parsers/rst/directives/html.py
|
|
+++ b/docutils/parsers/rst/directives/html.py
|
|
@@ -55,7 +55,7 @@ class MetaBody(states.SpecializedBody):
|
|
try:
|
|
attname, val = utils.extract_name_value(token)[0]
|
|
node[attname.lower()] = val
|
|
- except utils.NameValueError, detail:
|
|
+ except utils.NameValueError as detail:
|
|
line = self.state_machine.line
|
|
msg = self.reporter.error(
|
|
'Error parsing meta tag attribute "%s": %s.'
|
|
diff --git a/docutils/parsers/rst/directives/misc.py b/docutils/parsers/rst/directives/misc.py
|
|
index 7672de6..0fc3610 100644
|
|
--- a/docutils/parsers/rst/directives/misc.py
|
|
+++ b/docutils/parsers/rst/directives/misc.py
|
|
@@ -73,12 +73,12 @@ class Include(Directive):
|
|
include_file = io.FileInput(source_path=path,
|
|
encoding=encoding,
|
|
error_handler=e_handler)
|
|
- except UnicodeEncodeError, error:
|
|
+ except UnicodeEncodeError as error:
|
|
raise self.severe(u'Problems with "%s" directive path:\n'
|
|
'Cannot encode input file path "%s" '
|
|
'(wrong locale?).' %
|
|
(self.name, SafeString(path)))
|
|
- except IOError, error:
|
|
+ except IOError as error:
|
|
raise self.severe(u'Problems with "%s" directive path:\n%s.' %
|
|
(self.name, ErrorString(error)))
|
|
startline = self.options.get('start-line', None)
|
|
@@ -89,7 +89,7 @@ class Include(Directive):
|
|
rawtext = ''.join(lines[startline:endline])
|
|
else:
|
|
rawtext = include_file.read()
|
|
- except UnicodeError, error:
|
|
+ except UnicodeError as error:
|
|
raise self.severe(u'Problem with "%s" directive:\n%s' %
|
|
(self.name, ErrorString(error)))
|
|
# start-after/end-before: no restrictions on newlines in match-text,
|
|
@@ -213,12 +213,12 @@ class Raw(Directive):
|
|
# TODO: currently, raw input files are recorded as
|
|
# dependencies even if not used for the chosen output format.
|
|
self.state.document.settings.record_dependencies.add(path)
|
|
- except IOError, error:
|
|
+ except IOError as error:
|
|
raise self.severe(u'Problems with "%s" directive path:\n%s.'
|
|
% (self.name, ErrorString(error)))
|
|
try:
|
|
text = raw_file.read()
|
|
- except UnicodeError, error:
|
|
+ except UnicodeError as error:
|
|
raise self.severe(u'Problem with "%s" directive:\n%s'
|
|
% (self.name, ErrorString(error)))
|
|
attributes['source'] = path
|
|
@@ -230,7 +230,7 @@ class Raw(Directive):
|
|
import urllib2
|
|
try:
|
|
raw_text = urllib2.urlopen(source).read()
|
|
- except (urllib2.URLError, IOError, OSError), error:
|
|
+ except (urllib2.URLError, IOError, OSError) as error:
|
|
raise self.severe(u'Problems with "%s" directive URL "%s":\n%s.'
|
|
% (self.name, self.options['url'], ErrorString(error)))
|
|
raw_file = io.StringInput(source=raw_text, source_path=source,
|
|
@@ -238,7 +238,7 @@ class Raw(Directive):
|
|
error_handler=e_handler)
|
|
try:
|
|
text = raw_file.read()
|
|
- except UnicodeError, error:
|
|
+ except UnicodeError as error:
|
|
raise self.severe(u'Problem with "%s" directive:\n%s'
|
|
% (self.name, ErrorString(error)))
|
|
attributes['source'] = source
|
|
@@ -320,7 +320,7 @@ class Unicode(Directive):
|
|
for code in codes:
|
|
try:
|
|
decoded = directives.unicode_code(code)
|
|
- except ValueError, error:
|
|
+ except ValueError as error:
|
|
raise self.error(u'Invalid character code: %s\n%s'
|
|
% (code, ErrorString(error)))
|
|
element += nodes.Text(utils.unescape(decoded), decoded)
|
|
@@ -406,7 +406,7 @@ class Role(Directive):
|
|
self.state.parse_directive_block(
|
|
self.content[1:], self.content_offset, converted_role,
|
|
option_presets={}))
|
|
- except states.MarkupError, detail:
|
|
+ except states.MarkupError as detail:
|
|
error = self.state_machine.reporter.error(
|
|
'Error in "%s" directive:\n%s.' % (self.name, detail),
|
|
nodes.literal_block(self.block_text, self.block_text),
|
|
@@ -415,7 +415,7 @@ class Role(Directive):
|
|
if 'class' not in options:
|
|
try:
|
|
options['class'] = directives.class_option(new_role_name)
|
|
- except ValueError, detail:
|
|
+ except ValueError as detail:
|
|
error = self.state_machine.reporter.error(
|
|
u'Invalid argument for "%s" directive:\n%s.'
|
|
% (self.name, SafeString(detail)), nodes.literal_block(
|
|
diff --git a/docutils/parsers/rst/directives/tables.py b/docutils/parsers/rst/directives/tables.py
|
|
index 83b7b53..b0a4eac 100644
|
|
--- a/docutils/parsers/rst/directives/tables.py
|
|
+++ b/docutils/parsers/rst/directives/tables.py
|
|
@@ -259,9 +259,9 @@ class CSVTable(Table):
|
|
col_widths = self.get_column_widths(max_cols)
|
|
self.extend_short_rows_with_empty_cells(max_cols,
|
|
(table_head, table_body))
|
|
- except SystemMessagePropagation, detail:
|
|
+ except SystemMessagePropagation as detail:
|
|
return [detail.args[0]]
|
|
- except csv.Error, detail:
|
|
+ except csv.Error as detail:
|
|
message = str(detail)
|
|
if sys.version_info < (3,) and '1-character string' in message:
|
|
message += '\nwith Python 2.x this must be an ASCII character.'
|
|
@@ -320,7 +320,7 @@ class CSVTable(Table):
|
|
encoding=encoding,
|
|
error_handler=error_handler)
|
|
csv_data = csv_file.read().splitlines()
|
|
- except IOError, error:
|
|
+ except IOError as error:
|
|
severe = self.state_machine.reporter.severe(
|
|
u'Problems with "%s" directive path:\n%s.'
|
|
% (self.name, SafeString(error)),
|
|
@@ -336,7 +336,7 @@ class CSVTable(Table):
|
|
source = self.options['url']
|
|
try:
|
|
csv_text = urllib2.urlopen(source).read()
|
|
- except (urllib2.URLError, IOError, OSError, ValueError), error:
|
|
+ except (urllib2.URLError, IOError, OSError, ValueError) as error:
|
|
severe = self.state_machine.reporter.severe(
|
|
'Problems with "%s" directive URL "%s":\n%s.'
|
|
% (self.name, self.options['url'], SafeString(error)),
|
|
@@ -424,7 +424,7 @@ class ListTable(Table):
|
|
header_rows = self.options.get('header-rows', 0)
|
|
stub_columns = self.options.get('stub-columns', 0)
|
|
self.check_table_dimensions(table_data, header_rows, stub_columns)
|
|
- except SystemMessagePropagation, detail:
|
|
+ except SystemMessagePropagation as detail:
|
|
return [detail.args[0]]
|
|
table_node = self.build_table_from_list(table_data, col_widths,
|
|
header_rows, stub_columns)
|
|
diff --git a/docutils/parsers/rst/roles.py b/docutils/parsers/rst/roles.py
|
|
index bf786b7..49b61dc 100644
|
|
--- a/docutils/parsers/rst/roles.py
|
|
+++ b/docutils/parsers/rst/roles.py
|
|
@@ -109,7 +109,7 @@ def role(role_name, language_module, lineno, reporter):
|
|
canonicalname = None
|
|
try:
|
|
canonicalname = language_module.roles[normname]
|
|
- except AttributeError, error:
|
|
+ except AttributeError as error:
|
|
msg_text.append('Problem retrieving role entry from language '
|
|
'module %r: %s.' % (language_module, error))
|
|
except KeyError:
|
|
@@ -333,7 +333,7 @@ def code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
|
try:
|
|
tokens = Lexer(utils.unescape(text, True), language,
|
|
inliner.document.settings.syntax_highlight)
|
|
- except LexerError, error:
|
|
+ except LexerError as error:
|
|
msg = inliner.reporter.warning(error)
|
|
prb = inliner.problematic(rawtext, rawtext, msg)
|
|
return [prb], [msg]
|
|
diff --git a/docutils/parsers/rst/states.py b/docutils/parsers/rst/states.py
|
|
index a2970c8..c9b4fa3 100644
|
|
--- a/docutils/parsers/rst/states.py
|
|
+++ b/docutils/parsers/rst/states.py
|
|
@@ -1497,7 +1497,7 @@ class Body(RSTState):
|
|
(optionlist.source, optionlist.line) = self.state_machine.get_source_and_line()
|
|
try:
|
|
listitem, blank_finish = self.option_list_item(match)
|
|
- except MarkupError, error:
|
|
+ except MarkupError as error:
|
|
# This shouldn't happen; pattern won't match.
|
|
msg = self.reporter.error(u'Invalid option list marker: %s' %
|
|
error)
|
|
@@ -1686,7 +1686,7 @@ class Body(RSTState):
|
|
+ 1)
|
|
table = self.build_table(tabledata, tableline)
|
|
nodelist = [table] + messages
|
|
- except tableparser.TableMarkupError, err:
|
|
+ except tableparser.TableMarkupError as err:
|
|
nodelist = self.malformed_table(block, ' '.join(err.args),
|
|
offset=err.offset) + messages
|
|
else:
|
|
@@ -1698,7 +1698,7 @@ class Body(RSTState):
|
|
blank_finish = 1
|
|
try:
|
|
block = self.state_machine.get_text_block(flush_left=True)
|
|
- except statemachine.UnexpectedIndentationError, err:
|
|
+ except statemachine.UnexpectedIndentationError as err:
|
|
block, src, srcline = err.args
|
|
messages.append(self.reporter.error('Unexpected indentation.',
|
|
source=src, line=srcline))
|
|
@@ -2135,7 +2135,7 @@ class Body(RSTState):
|
|
arguments, options, content, content_offset = (
|
|
self.parse_directive_block(indented, line_offset,
|
|
directive, option_presets))
|
|
- except MarkupError, detail:
|
|
+ except MarkupError as detail:
|
|
error = self.reporter.error(
|
|
'Error in "%s" directive:\n%s.' % (type_name,
|
|
' '.join(detail.args)),
|
|
@@ -2146,7 +2146,7 @@ class Body(RSTState):
|
|
content_offset, block_text, self, self.state_machine)
|
|
try:
|
|
result = directive_instance.run()
|
|
- except docutils.parsers.rst.DirectiveError, error:
|
|
+ except docutils.parsers.rst.DirectiveError as error:
|
|
msg_node = self.reporter.system_message(error.level, error.msg,
|
|
line=lineno)
|
|
msg_node += nodes.literal_block(block_text, block_text)
|
|
@@ -2263,11 +2263,11 @@ class Body(RSTState):
|
|
return 0, 'invalid option block'
|
|
try:
|
|
options = utils.extract_extension_options(node, option_spec)
|
|
- except KeyError, detail:
|
|
+ except KeyError as detail:
|
|
return 0, ('unknown option: "%s"' % detail.args[0])
|
|
- except (ValueError, TypeError), detail:
|
|
+ except (ValueError, TypeError) as detail:
|
|
return 0, ('invalid option value: %s' % ' '.join(detail.args))
|
|
- except utils.ExtensionOptionError, detail:
|
|
+ except utils.ExtensionOptionError as detail:
|
|
return 0, ('invalid option data: %s' % ' '.join(detail.args))
|
|
if blank_finish:
|
|
return 1, options
|
|
@@ -2354,7 +2354,7 @@ class Body(RSTState):
|
|
if expmatch:
|
|
try:
|
|
return method(self, expmatch)
|
|
- except MarkupError, error:
|
|
+ except MarkupError as error:
|
|
lineno = self.state_machine.abs_line_number()
|
|
message = ' '.join(error.args)
|
|
errors.append(self.reporter.warning(message, line=lineno))
|
|
@@ -2777,7 +2777,7 @@ class Text(RSTState):
|
|
msg = None
|
|
try:
|
|
block = self.state_machine.get_text_block(flush_left=True)
|
|
- except statemachine.UnexpectedIndentationError, err:
|
|
+ except statemachine.UnexpectedIndentationError as err:
|
|
block, src, srcline = err.args
|
|
msg = self.reporter.error('Unexpected indentation.',
|
|
source=src, line=srcline)
|
|
diff --git a/docutils/statemachine.py b/docutils/statemachine.py
|
|
index 6714a04..6a2322c 100644
|
|
--- a/docutils/statemachine.py
|
|
+++ b/docutils/statemachine.py
|
|
@@ -248,7 +248,7 @@ class StateMachine(object):
|
|
break
|
|
else:
|
|
results.extend(result)
|
|
- except TransitionCorrection, exception:
|
|
+ except TransitionCorrection as exception:
|
|
self.previous_line() # back up for another try
|
|
transitions = (exception.args[0],)
|
|
if self.debug:
|
|
@@ -257,7 +257,7 @@ class StateMachine(object):
|
|
'state "%s", transition %s.'
|
|
% (state.__class__.__name__, transitions[0])), file=self._stderr)
|
|
continue
|
|
- except StateCorrection, exception:
|
|
+ except StateCorrection as exception:
|
|
self.previous_line() # back up for another try
|
|
next_state = exception.args[0]
|
|
if len(exception.args) == 1:
|
|
@@ -413,7 +413,7 @@ class StateMachine(object):
|
|
flush_left)
|
|
self.next_line(len(block) - 1)
|
|
return block
|
|
- except UnexpectedIndentationError, err:
|
|
+ except UnexpectedIndentationError as err:
|
|
block = err.args[0]
|
|
self.next_line(len(block) - 1) # advance to last line of block
|
|
raise
|
|
diff --git a/docutils/utils/__init__.py b/docutils/utils/__init__.py
|
|
index 692335a..c71d508 100644
|
|
--- a/docutils/utils/__init__.py
|
|
+++ b/docutils/utils/__init__.py
|
|
@@ -326,7 +326,7 @@ def assemble_option_dict(option_list, options_spec):
|
|
raise DuplicateOptionError('duplicate option "%s"' % name)
|
|
try:
|
|
options[name] = convertor(value)
|
|
- except (ValueError, TypeError), detail:
|
|
+ except (ValueError, TypeError) as detail:
|
|
raise detail.__class__('(option: "%s"; value: %r)\n%s'
|
|
% (name, value, ' '.join(detail.args)))
|
|
return options
|
|
diff --git a/docutils/utils/error_reporting.py b/docutils/utils/error_reporting.py
|
|
index 02e62eb..8ea7108 100644
|
|
--- a/docutils/utils/error_reporting.py
|
|
+++ b/docutils/utils/error_reporting.py
|
|
@@ -49,7 +49,7 @@ else:
|
|
# locale.getpreferredencoding([do_setlocale=True|False])
|
|
# has side-effects | might return a wrong guess.
|
|
# (cf. Update 1 in http://stackoverflow.com/questions/4082645/using-python-2-xs-locale-module-to-format-numbers-and-currency)
|
|
- except ValueError, error: # OS X may set UTF-8 without language code
|
|
+ except ValueError as error: # OS X may set UTF-8 without language code
|
|
# see http://bugs.python.org/issue18378
|
|
# and https://sourceforge.net/p/docutils/bugs/298/
|
|
if "unknown locale: UTF-8" in error.args:
|
|
@@ -113,7 +113,7 @@ class SafeString(object):
|
|
if isinstance(self.data, EnvironmentError):
|
|
u = u.replace(": u'", ": '") # normalize filename quoting
|
|
return u
|
|
- except UnicodeError, error: # catch ..Encode.. and ..Decode.. errors
|
|
+ except UnicodeError as error: # catch ..Encode.. and ..Decode.. errors
|
|
if isinstance(self.data, EnvironmentError):
|
|
return u"[Errno %s] %s: '%s'" % (self.data.errno,
|
|
SafeString(self.data.strerror, self.encoding,
|
|
diff --git a/docutils/writers/_html_base.py b/docutils/writers/_html_base.py
|
|
index fa27911..23efeea 100644
|
|
--- a/docutils/writers/_html_base.py
|
|
+++ b/docutils/writers/_html_base.py
|
|
@@ -302,7 +302,7 @@ class HTMLTranslator(nodes.NodeVisitor):
|
|
content = io.FileInput(source_path=path,
|
|
encoding='utf-8').read()
|
|
self.settings.record_dependencies.add(path)
|
|
- except IOError, err:
|
|
+ except IOError as err:
|
|
msg = u"Cannot embed stylesheet '%s': %s." % (
|
|
path, SafeString(err.strerror))
|
|
self.document.reporter.error(msg)
|
|
@@ -1159,7 +1159,7 @@ class HTMLTranslator(nodes.NodeVisitor):
|
|
'with math-output "MathML"')
|
|
except OSError:
|
|
raise OSError('is "latexmlmath" in your PATH?')
|
|
- except SyntaxError, err:
|
|
+ except SyntaxError as err:
|
|
err_node = self.document.reporter.error(err, base_node=node)
|
|
self.visit_system_message(err_node)
|
|
self.body.append(self.starttag(node, 'p'))
|
|
diff --git a/docutils/writers/docutils_xml.py b/docutils/writers/docutils_xml.py
|
|
index 148041a..e870ee1 100644
|
|
--- a/docutils/writers/docutils_xml.py
|
|
+++ b/docutils/writers/docutils_xml.py
|
|
@@ -186,7 +186,7 @@ class XMLTranslator(nodes.GenericNodeVisitor):
|
|
xml_string = xml_string.encode('utf8')
|
|
try:
|
|
self.xmlparser.parse(StringIO(xml_string))
|
|
- except xml.sax._exceptions.SAXParseException, error:
|
|
+ except xml.sax._exceptions.SAXParseException as error:
|
|
col_num = self.the_handle.locator.getColumnNumber()
|
|
line_num = self.the_handle.locator.getLineNumber()
|
|
srcline = node.line
|
|
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
|
|
index 5c33d0a..5eaa7f0 100644
|
|
--- a/docutils/writers/latex2e/__init__.py
|
|
+++ b/docutils/writers/latex2e/__init__.py
|
|
@@ -1416,7 +1416,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|
content = io.FileInput(source_path=path,
|
|
encoding='utf-8').read()
|
|
self.settings.record_dependencies.add(path)
|
|
- except IOError, err:
|
|
+ except IOError as err:
|
|
msg = u"Cannot embed stylesheet '%s':\n %s." % (
|
|
path, SafeString(err.strerror))
|
|
self.document.reporter.error(msg)
|
|
diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py
|
|
index 25196ec..e77447a 100644
|
|
--- a/test/DocutilsTestSupport.py
|
|
+++ b/test/DocutilsTestSupport.py
|
|
@@ -230,7 +230,7 @@ class CustomTestCase(StandardTestCase):
|
|
output = '\n'.join(output.splitlines())
|
|
try:
|
|
self.assertEqual(output, expected)
|
|
- except AssertionError, error:
|
|
+ except AssertionError as error:
|
|
print('\n%s\ninput:' % (self,), file=sys.stderr)
|
|
print(input, file=sys.stderr)
|
|
try:
|
|
@@ -543,7 +543,7 @@ class GridTableParserTestCase(CustomTestCase):
|
|
self.parser.find_head_body_sep()
|
|
self.parser.parse_table()
|
|
output = self.parser.cells
|
|
- except Exception, details:
|
|
+ except Exception as details:
|
|
output = '%s: %s' % (details.__class__.__name__, details)
|
|
self.compare_output(self.input, pformat(output) + '\n',
|
|
pformat(self.expected) + '\n')
|
|
@@ -552,7 +552,7 @@ class GridTableParserTestCase(CustomTestCase):
|
|
try:
|
|
output = self.parser.parse(StringList(string2lines(self.input),
|
|
'test data'))
|
|
- except Exception, details:
|
|
+ except Exception as details:
|
|
output = '%s: %s' % (details.__class__.__name__, details)
|
|
self.compare_output(self.input, pformat(output) + '\n',
|
|
pformat(self.expected) + '\n')
|
|
@@ -865,7 +865,7 @@ def exception_data(func, *args, **kwds):
|
|
"""
|
|
try:
|
|
func(*args, **kwds)
|
|
- except Exception, detail:
|
|
+ except Exception as detail:
|
|
return (detail, detail.args,
|
|
'%s: %s' % (detail.__class__.__name__, detail))
|
|
|
|
diff --git a/test/package_unittest.py b/test/package_unittest.py
|
|
index daf11f4..16b00dc 100644
|
|
--- a/test/package_unittest.py
|
|
+++ b/test/package_unittest.py
|
|
@@ -64,7 +64,7 @@ def parseArgs(argv=sys.argv):
|
|
debug =1
|
|
if len(args) != 0:
|
|
usageExit("No command-line arguments supported yet.")
|
|
- except getopt.error, msg:
|
|
+ except getopt.error as msg:
|
|
usageExit(msg)
|
|
|
|
def loadTestModules(path, name='', packages=None):
|
|
diff --git a/test/test_error_reporting.py b/test/test_error_reporting.py
|
|
index c4eae40..bae9db5 100644
|
|
--- a/test/test_error_reporting.py
|
|
+++ b/test/test_error_reporting.py
|
|
@@ -19,7 +19,7 @@ instances like, e.g., ::
|
|
|
|
try:
|
|
something
|
|
- except IOError, error:
|
|
+ except IOError as error:
|
|
print('Found %s' % error)
|
|
|
|
unless the minimal required Python version has this problem fixed.
|
|
@@ -223,29 +223,29 @@ class SafeStringTests_locale(unittest.TestCase):
|
|
us = u'\xfc'
|
|
try:
|
|
open(b'\xfc')
|
|
- except IOError, e: # in Python 3 the name for the exception instance
|
|
+ except IOError as e: # in Python 3 the name for the exception instance
|
|
bioe = e # is local to the except clause
|
|
try:
|
|
open(u'\xfc')
|
|
- except IOError, e:
|
|
+ except IOError as e:
|
|
uioe = e
|
|
except UnicodeEncodeError:
|
|
try:
|
|
open(u'\xfc'.encode(sys.getfilesystemencoding(), 'replace'))
|
|
- except IOError, e:
|
|
+ except IOError as e:
|
|
uioe = e
|
|
try:
|
|
os.chdir(b'\xfc')
|
|
- except OSError, e:
|
|
+ except OSError as e:
|
|
bose = e
|
|
try:
|
|
os.chdir(u'\xfc')
|
|
- except OSError, e:
|
|
+ except OSError as e:
|
|
uose = e
|
|
except UnicodeEncodeError:
|
|
try:
|
|
os.chdir(u'\xfc'.encode(sys.getfilesystemencoding(), 'replace'))
|
|
- except OSError, e:
|
|
+ except OSError as e:
|
|
uose = e
|
|
# wrapped test data:
|
|
wbioe = SafeString(bioe)
|
|
diff --git a/test/test_language.py b/test/test_language.py
|
|
index 70a497e..0e05d44 100755
|
|
--- a/test/test_language.py
|
|
+++ b/test/test_language.py
|
|
@@ -144,7 +144,7 @@ class LanguageTestCase(DocutilsTestSupport.CustomTestCase):
|
|
func, msg = directives.directive(d, module, None)
|
|
if not func:
|
|
failures.append('"%s": unknown directive' % d)
|
|
- except Exception, error:
|
|
+ except Exception as error:
|
|
failures.append('"%s": %s' % (d, error))
|
|
inverted = self._invert(module.directives)
|
|
canonical = directives._directive_registry.keys()
|
|
@@ -179,7 +179,7 @@ class LanguageTestCase(DocutilsTestSupport.CustomTestCase):
|
|
method = roles._role_registry[d]
|
|
#if not method:
|
|
# failures.append('"%s": unknown role' % d)
|
|
- except KeyError, error:
|
|
+ except KeyError as error:
|
|
failures.append('"%s": %s' % (d, error))
|
|
inverted = self._invert(module.roles)
|
|
canonical = roles._role_registry.keys()
|
|
diff --git a/test/test_publisher.py b/test/test_publisher.py
|
|
index f04ebf7..04d9c71 100755
|
|
--- a/test/test_publisher.py
|
|
+++ b/test/test_publisher.py
|
|
@@ -65,7 +65,7 @@ class PublisherTests(DocutilsTestSupport.StandardTestCase):
|
|
try:
|
|
core.publish_cmdline(argv=['nonexisting/path'],
|
|
settings_overrides={'traceback': True})
|
|
- except IOError, e:
|
|
+ except IOError as e:
|
|
self.assertTrue(isinstance(e, io.InputError))
|
|
|
|
|
|
@@ -74,7 +74,7 @@ class PublisherTests(DocutilsTestSupport.StandardTestCase):
|
|
try:
|
|
core.publish_cmdline(argv=['data/include.txt', 'nonexisting/path'],
|
|
settings_overrides={'traceback': True})
|
|
- except IOError, e:
|
|
+ except IOError as e:
|
|
self.assertTrue(isinstance(e, io.OutputError))
|
|
|
|
|
|
diff --git a/test/test_utils.py b/test/test_utils.py
|
|
index e1fcc8f..59e29c8 100755
|
|
--- a/test/test_utils.py
|
|
+++ b/test/test_utils.py
|
|
@@ -88,7 +88,7 @@ class ReporterTests(unittest.TestCase):
|
|
and hence fails with unicode message"""
|
|
try:
|
|
raise Exception(u'mesidʒ')
|
|
- except Exception, err:
|
|
+ except Exception as err:
|
|
sw = self.reporter.system_message(0, err)
|
|
self.assertEqual(sw.pformat(), u"""\
|
|
<system_message level="0" source="test data" type="DEBUG">
|
|
--
|
|
2.24.0.375.geb5ae68d41
|
|
|