From: <mi...@us...> - 2012-06-25 14:56:58
|
Revision: 7466 http://docutils.svn.sourceforge.net/docutils/?rev=7466&view=rev Author: milde Date: 2012-06-25 14:56:51 +0000 (Mon, 25 Jun 2012) Log Message: ----------- io.FileInput/io.FileOutput: no system-exit on IOError. The `handle_io_errors` option is ignored and will be removed in a future release. Modified Paths: -------------- trunk/docutils/HISTORY.txt trunk/docutils/RELEASE-NOTES.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 Modified: trunk/docutils/HISTORY.txt =================================================================== --- trunk/docutils/HISTORY.txt 2012-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/HISTORY.txt 2012-06-25 14:56:51 UTC (rev 7466) @@ -22,7 +22,12 @@ - ``docutils/math``, ``docutils/error_reporting.py``, and ``docutils/urischemes.py`` moved to the utils package. +* docutils/io.py + - FileInput/FileOutput: no system-exit on IOError. The `handle_io_errors` + option is ignored and will be removed in a future release. + + Release 0.9.1 (2012-06-17) ========================== Modified: trunk/docutils/RELEASE-NOTES.txt =================================================================== --- trunk/docutils/RELEASE-NOTES.txt 2012-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/RELEASE-NOTES.txt 2012-06-25 14:56:51 UTC (rev 7466) @@ -19,21 +19,9 @@ Future changes ============== -* docutils.io.FileInput/FileOutput will no longer do a - system-exit on IOError by default. + :0.10 + n: remove the `handle_io_errors` option from io.FileInput/Output. - Roadmap: - :0.10: change of default behaviour to the equivalent of - ``handle_io_errors=False``, - ignore and deprecate the `handle_io_errors` option. - (allows us to clean up Docutils code and remove the error handling - code from the FileInput/FileOutput classes) - :0.10 + n: deprecation warning to stderr if FileInput/FileOutput - is called with `handle_io_errors`, - :0.10 + n+1: remove the `handle_io_errors` option. - - Changes Since 0.9.1 =================== @@ -55,6 +43,11 @@ except ImportError: import docutils.utils.math as math +* docutils/io.py + + - FileInput/FileOutput: no system-exit on IOError. + The `handle_io_errors` option is ignored. + .. _Python 3 compatibility: README.html#python-3-compatibility Modified: trunk/docutils/docutils/core.py =================================================================== --- trunk/docutils/docutils/core.py 2012-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/docutils/core.py 2012-06-25 14:56:51 UTC (rev 7466) @@ -176,8 +176,7 @@ try: self.source = self.source_class( source=source, source_path=source_path, - encoding=self.settings.input_encoding, - handle_io_errors=False) + encoding=self.settings.input_encoding) except TypeError: self.source = self.source_class( source=source, source_path=source_path, @@ -192,9 +191,6 @@ destination=destination, destination_path=destination_path, encoding=self.settings.output_encoding, error_handler=self.settings.output_encoding_error_handler) - # Raise IOError instead of system exit with `tracback == True` - # TODO: change io.FileInput's default behaviour and remove this hack - self.destination.handle_io_errors=False def apply_transforms(self): self.document.transformer.populate_from_components( Modified: trunk/docutils/docutils/io.py =================================================================== --- trunk/docutils/docutils/io.py 2012-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/docutils/io.py 2012-06-25 14:56:51 UTC (rev 7466) @@ -4,7 +4,7 @@ """ I/O classes provide a uniform API for low-level input and output. Subclasses -will exist for a variety of input/output mechanisms. +exist for a variety of input/output mechanisms. """ __docformat__ = 'reStructuredText' @@ -204,7 +204,7 @@ """ def __init__(self, source=None, source_path=None, encoding=None, error_handler='strict', - autoclose=True, handle_io_errors=True, mode='rU'): + autoclose=True, handle_io_errors=None, mode='rU'): """ :Parameters: - `source`: either a file-like object (which is read directly), or @@ -214,14 +214,13 @@ - `error_handler`: the encoding error handler to use. - `autoclose`: close automatically after read (except when `sys.stdin` is the source). - - `handle_io_errors`: summarize I/O errors here, and exit? + - `handle_io_errors`: ignored, deprecated, will be removed. - `mode`: how the file is to be opened (see standard function `open`). The default 'rU' provides universal newline support for text files. """ Input.__init__(self, source, source_path, encoding, error_handler) self.autoclose = autoclose - self.handle_io_errors = handle_io_errors self._stderr = ErrorOutput() if source is None: @@ -236,12 +235,6 @@ try: self.source = open(source_path, mode, **kwargs) except IOError, error: - if handle_io_errors: - print >>self._stderr, ErrorString(error) - print >>self._stderr, ( - u'Unable to open source file for reading ("%s").' - u'Exiting.' % source_path) - sys.exit(1) raise InputError(error.errno, error.strerror, source_path) else: self.source = sys.stdin @@ -310,7 +303,7 @@ def __init__(self, destination=None, destination_path=None, encoding=None, error_handler='strict', autoclose=True, - handle_io_errors=True, mode=None): + handle_io_errors=None, mode=None): """ :Parameters: - `destination`: either a file-like object (which is written @@ -322,7 +315,7 @@ - `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`: summarize I/O errors here, and exit? + - `handle_io_errors`: ignored, deprecated, will be removed. - `mode`: how the file is to be opened (see standard function `open`). The default is 'w', providing universal newline support for text files. @@ -331,7 +324,6 @@ encoding, error_handler) self.opened = True self.autoclose = autoclose - self.handle_io_errors = handle_io_errors if mode is not None: self.mode = mode self._stderr = ErrorOutput() @@ -377,11 +369,6 @@ try: self.destination = open(self.destination_path, self.mode, **kwargs) except IOError, error: - if self.handle_io_errors: - 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) raise OutputError(error.errno, error.strerror, self.destination_path) self.opened = True Modified: trunk/docutils/docutils/parsers/rst/directives/misc.py =================================================================== --- trunk/docutils/docutils/parsers/rst/directives/misc.py 2012-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/docutils/parsers/rst/directives/misc.py 2012-06-25 14:56:51 UTC (rev 7466) @@ -64,15 +64,14 @@ path = nodes.reprunicode(path) encoding = self.options.get( 'encoding', self.state.document.settings.input_encoding) + e_handler=self.state.document.settings.input_encoding_error_handler tab_width = self.options.get( 'tab-width', self.state.document.settings.tab_width) 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), - handle_io_errors=None) + include_file = io.FileInput(source_path=path, + encoding=encoding, + error_handler=e_handler) except UnicodeEncodeError, error: raise self.severe(u'Problems with "%s" directive path:\n' 'Cannot encode input file path "%s" ' @@ -186,6 +185,7 @@ attributes = {'format': ' '.join(self.arguments[0].lower().split())} encoding = self.options.get( 'encoding', self.state.document.settings.input_encoding) + e_handler=self.state.document.settings.input_encoding_error_handler if self.content: if 'file' in self.options or 'url' in self.options: raise self.error( @@ -203,11 +203,9 @@ self.options['file'])) path = utils.relative_path(None, path) try: - raw_file = io.FileInput( - source_path=path, encoding=encoding, - error_handler=(self.state.document.settings.\ - input_encoding_error_handler), - handle_io_errors=None) + raw_file = io.FileInput(source_path=path, + encoding=encoding, + error_handler=e_handler) # 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) @@ -231,10 +229,9 @@ except (urllib2.URLError, IOError, OSError), 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, encoding=encoding, - error_handler=(self.state.document.settings.\ - input_encoding_error_handler)) + raw_file = io.StringInput(source=raw_text, source_path=source, + encoding=encoding, + error_handler=e_handler) try: text = raw_file.read() except UnicodeError, error: Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py =================================================================== --- trunk/docutils/docutils/parsers/rst/directives/tables.py 2012-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2012-06-25 14:56:51 UTC (rev 7466) @@ -244,6 +244,7 @@ """ encoding = self.options.get( 'encoding', self.state.document.settings.input_encoding) + error_handler = self.state.document.settings.input_encoding_error_handler if self.content: # CSV data is from directive content. if 'file' in self.options or 'url' in self.options: @@ -270,11 +271,9 @@ source = utils.relative_path(None, source) 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), - handle_io_errors=None) + csv_file = io.FileInput(source_path=source, + encoding=encoding, + error_handler=error_handler) 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-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/docutils/writers/html4css1/__init__.py 2012-06-25 14:56:51 UTC (rev 7466) @@ -373,8 +373,7 @@ if self.settings.embed_stylesheet: try: content = io.FileInput(source_path=path, - encoding='utf-8', - handle_io_errors=False).read() + encoding='utf-8').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-06-25 14:32:15 UTC (rev 7465) +++ trunk/docutils/docutils/writers/latex2e/__init__.py 2012-06-25 14:56:51 UTC (rev 7466) @@ -1333,8 +1333,7 @@ path = base + '.sty' # ensure extension try: content = io.FileInput(source_path=path, - encoding='utf-8', - handle_io_errors=False).read() + encoding='utf-8').read() self.settings.record_dependencies.add(path) except IOError, err: msg = u"Cannot embed stylesheet '%s':\n %s." % ( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |