From: <mi...@us...> - 2012-01-27 08:41:43
|
Revision: 7328 http://docutils.svn.sourceforge.net/docutils/?rev=7328&view=rev Author: milde Date: 2012-01-27 08:41:35 +0000 (Fri, 27 Jan 2012) Log Message: ----------- Revert "io.FileInput/io.FileOutput: No system-exit on IOError." This reverts commit 7326 on Davids order. Modified Paths: -------------- trunk/docutils/HISTORY.txt trunk/docutils/docutils/core.py trunk/docutils/docutils/io.py trunk/docutils/docutils/parsers/rst/directives/misc.py trunk/docutils/docutils/parsers/rst/directives/tables.py trunk/docutils/docutils/writers/html4css1/__init__.py trunk/docutils/docutils/writers/latex2e/__init__.py trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py Modified: trunk/docutils/HISTORY.txt =================================================================== --- trunk/docutils/HISTORY.txt 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/HISTORY.txt 2012-01-27 08:41:35 UTC (rev 7328) @@ -29,18 +29,9 @@ - Fix [ 2971827 ] and [ 3442827 ] extras/roman.py moved to docutils/utils/roman.py -* docutils/core.py: - - - Catch and report InputError/OutputError - (unless the configuration setting "traceback" is true). - * docutils/io.py - Fix [ 3395948 ] (Work around encoding problems in Py3k). - - FileInput/FileOutput: No system-exit on IOError. - Instead, the custom exceptions InputError/OutputError are raised - to allow handling by core.Publisher or a calling application. - The optional argument `handle_io_errors` (to be removed later) is ignored. * docutils/utils.py -> docutils/utils/__init__.py Modified: trunk/docutils/docutils/core.py =================================================================== --- trunk/docutils/docutils/core.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/docutils/core.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -135,7 +135,7 @@ if self.settings is None: defaults = (settings_overrides or {}).copy() # Propagate exceptions by default when used programmatically: - defaults.setdefault('traceback', True) + defaults.setdefault('traceback', 1) self.get_settings(settings_spec=settings_spec, config_section=config_section, **defaults) @@ -221,7 +221,7 @@ self.debugging_dumps() raise self.report_Exception(error) - exit = True + exit = 1 exit_status = 1 self.debugging_dumps() if (enable_exit_status and self.document @@ -260,10 +260,6 @@ self.report_SystemMessage(error) elif isinstance(error, UnicodeEncodeError): self.report_UnicodeError(error) - elif isinstance(error, io.InputError): - self.report_InputError(error) - elif isinstance(error, io.OutputError): - self.report_OutputError(error) else: print >>self._stderr, u'%s' % ErrorString(error) print >>self._stderr, ("""\ @@ -279,14 +275,6 @@ % (error.level, utils.Reporter.levels[error.level])) - def report_InputError(self, error): - self._stderr.write(u'Unable to open source file for reading:\n' - u' %s\n' % ErrorString(error)) - - def report_OutputError(self, error): - self._stderr.write(u'Unable to open destination file for writing:\n' - u' %s\n' % ErrorString(error)) - def report_UnicodeError(self, error): data = error.object[error.start:error.end] self._stderr.write( Modified: trunk/docutils/docutils/io.py =================================================================== --- trunk/docutils/docutils/io.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/docutils/io.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -17,11 +17,6 @@ from docutils._compat import b from docutils.error_reporting import locale_encoding, ErrorString, ErrorOutput - -class InputError(IOError): pass -class OutputError(IOError): pass - - class Input(TransformSpec): """ @@ -189,7 +184,7 @@ """ def __init__(self, source=None, source_path=None, encoding=None, error_handler='strict', - autoclose=True, handle_io_errors=False, mode='rU'): + autoclose=True, handle_io_errors=True, mode='rU'): """ :Parameters: - `source`: either a file-like object (which is read directly), or @@ -199,7 +194,7 @@ - `error_handler`: the encoding error handler to use. - `autoclose`: close automatically after read (except when `sys.stdin` is the source). - - `handle_io_errors`: ignored. + - `handle_io_errors`: summarize I/O errors here, and exit? - `mode`: how the file is to be opened (see standard function `open`). The default 'rU' provides universal newline support for text files. @@ -221,7 +216,12 @@ try: self.source = open(source_path, mode, **kwargs) except IOError, error: - raise InputError(error.errno, error.strerror, source_path) + if not handle_io_errors: + raise + print >>self._stderr, ErrorString(error) + print >>self._stderr, (u'Unable to open source' + u" file for reading ('%s'). Exiting." % source_path) + sys.exit(1) else: self.source = sys.stdin elif (sys.version_info >= (3,0) and @@ -286,7 +286,7 @@ def __init__(self, destination=None, destination_path=None, encoding=None, error_handler='strict', autoclose=True, - handle_io_errors=False): + handle_io_errors=True): """ :Parameters: - `destination`: either a file-like object (which is written @@ -294,11 +294,8 @@ `destination_path` given). - `destination_path`: a path to a file, which is opened and then written. - - `encoding`: the text encoding of the output file. - - `error_handler`: the encoding error handler to use. - `autoclose`: close automatically after write (except when `sys.stdout` or `sys.stderr` is the destination). - - `handle_io_errors`: ignored. """ Output.__init__(self, destination, destination_path, encoding, error_handler) @@ -329,8 +326,12 @@ try: self.destination = open(self.destination_path, 'w', **kwargs) except IOError, error: - raise OutputError(error.errno, error.strerror, - self.destination_path) + if not self.handle_io_errors: + raise + print >>self._stderr, ErrorString(error) + print >>self._stderr, (u'Unable to open destination file' + u" for writing ('%s'). Exiting." % self.destination_path) + sys.exit(1) self.opened = True def write(self, data): Modified: trunk/docutils/docutils/parsers/rst/directives/misc.py =================================================================== --- trunk/docutils/docutils/parsers/rst/directives/misc.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/docutils/parsers/rst/directives/misc.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -69,10 +69,10 @@ try: self.state.document.settings.record_dependencies.add(path) include_file = io.FileInput( - source_path=path, - encoding=encoding, - error_handler= - self.state.document.settings.input_encoding_error_handler) + source_path=path, encoding=encoding, + error_handler=(self.state.document.settings.\ + input_encoding_error_handler), + handle_io_errors=None) except IOError, error: raise self.severe(u'Problems with "%s" directive path:\n%s.' % (self.name, ErrorString(error))) @@ -198,10 +198,11 @@ self.options['file'])) path = utils.relative_path(None, path) try: - eh = self.state.document.settings.input_encoding_error_handler - raw_file = io.FileInput(source_path=path, - encoding=encoding, - error_handler=eh) + raw_file = io.FileInput( + source_path=path, encoding=encoding, + error_handler=(self.state.document.settings.\ + input_encoding_error_handler), + handle_io_errors=None) # 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) Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py =================================================================== --- trunk/docutils/docutils/parsers/rst/directives/tables.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -271,10 +271,10 @@ try: self.state.document.settings.record_dependencies.add(source) csv_file = io.FileInput( - source_path=source, - encoding=encoding, - error_handler= - self.state.document.settings.input_encoding_error_handler) + source_path=source, encoding=encoding, + error_handler=(self.state.document.settings.\ + input_encoding_error_handler), + handle_io_errors=None) csv_data = csv_file.read().splitlines() except IOError, error: severe = self.state_machine.reporter.severe( Modified: trunk/docutils/docutils/writers/html4css1/__init__.py =================================================================== --- trunk/docutils/docutils/writers/html4css1/__init__.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/docutils/writers/html4css1/__init__.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -373,7 +373,8 @@ if self.settings.embed_stylesheet: try: content = io.FileInput(source_path=path, - encoding='utf-8').read() + encoding='utf-8', + handle_io_errors=False).read() self.settings.record_dependencies.add(path) except IOError, err: msg = u"Cannot embed stylesheet '%s': %s." % ( Modified: trunk/docutils/docutils/writers/latex2e/__init__.py =================================================================== --- trunk/docutils/docutils/writers/latex2e/__init__.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/docutils/writers/latex2e/__init__.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -1179,7 +1179,8 @@ path = base + '.sty' # ensure extension try: content = io.FileInput(source_path=path, - encoding='utf-8').read() + encoding='utf-8', + handle_io_errors=False).read() self.settings.record_dependencies.add(path) except IOError, err: msg = u"Cannot embed stylesheet '%s':\n %s." % ( Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py =================================================================== --- trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -212,7 +212,7 @@ <system_message level="4" line="4" source="test data" type="SEVERE"> <paragraph> Problems with "include" directive path: - InputError: [Errno 2] No such file or directory: 'nonexistent.txt'. + IOError: [Errno 2] No such file or directory: 'nonexistent.txt'. <literal_block xml:space="preserve"> .. include:: nonexistent.txt <paragraph> @@ -414,7 +414,7 @@ <system_message level="4" line="3" source="test data" type="SEVERE"> <paragraph> Problems with "include" directive path: - InputError: [Errno 2] No such file or directory: '\u043c\u0438\u0440.txt'. + IOError: [Errno 2] No such file or directory: '\u043c\u0438\u0440.txt'. <literal_block xml:space="preserve"> .. include:: \u043c\u0438\u0440.txt """], @@ -458,7 +458,7 @@ <system_message level="4" line="12" source="%(source)s" type="SEVERE"> <paragraph> Problems with "include" directive path: - InputError: [Errno 2] No such file or directory: '%(nonexistent)s'. + IOError: [Errno 2] No such file or directory: '%(nonexistent)s'. <literal_block xml:space="preserve"> .. include:: <nonexistent> <system_message level="3" line="14" source="%(source)s" type="ERROR"> @@ -697,7 +697,7 @@ <system_message level="4" line="3" source="test data" type="SEVERE"> <paragraph> Problems with "include" directive path: - InputError: [Errno 2] No such file or directory: '%s'. + IOError: [Errno 2] No such file or directory: '%s'. <literal_block xml:space="preserve"> .. include:: <nonexistent> """ % nonexistent_rel], Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py =================================================================== --- trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2012-01-27 03:59:49 UTC (rev 7327) +++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2012-01-27 08:41:35 UTC (rev 7328) @@ -158,7 +158,7 @@ <system_message level="4" line="1" source="test data" type="SEVERE"> <paragraph> Problems with "raw" directive path: - InputError: [Errno 2] No such file or directory: 'non-existent.file'. + IOError: [Errno 2] No such file or directory: 'non-existent.file'. <literal_block xml:space="preserve"> .. raw:: html :file: non-existent.file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |