summaryrefslogtreecommitdiff
path: root/docutils/io.py
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2012-01-27 08:41:35 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2012-01-27 08:41:35 +0000
commit964596a362d2625e428a465d0d1d5b5bc24f45f1 (patch)
tree0981618d0e0d090f20bbdd0b4aaf0da399c214f1 /docutils/io.py
parent0803b15202da5c73a525393e6a8044fcf9172bc4 (diff)
downloaddocutils-964596a362d2625e428a465d0d1d5b5bc24f45f1.tar.gz
Revert "io.FileInput/io.FileOutput: No system-exit on IOError."
This reverts commit 7326 on Davids order. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7328 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/io.py')
-rw-r--r--docutils/io.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/docutils/io.py b/docutils/io.py
index 7da07faad..40630af55 100644
--- a/docutils/io.py
+++ b/docutils/io.py
@@ -17,11 +17,6 @@ from docutils import TransformSpec
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 @@ class FileInput(Input):
"""
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 @@ class FileInput(Input):
- `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 @@ class FileInput(Input):
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 @@ class FileOutput(Output):
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 @@ class FileOutput(Output):
`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 @@ class FileOutput(Output):
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):