From: <mi...@us...> - 2012-01-19 11:32:05
|
Revision: 7316 http://docutils.svn.sourceforge.net/docutils/?rev=7316&view=rev Author: milde Date: 2012-01-19 11:31:58 +0000 (Thu, 19 Jan 2012) Log Message: ----------- SafeString: normalize filename quoting for EnvironmentError exceptions. Modified Paths: -------------- trunk/docutils/docutils/_compat.py trunk/docutils/docutils/error_reporting.py trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py Modified: trunk/docutils/docutils/_compat.py =================================================================== --- trunk/docutils/docutils/_compat.py 2012-01-18 10:16:20 UTC (rev 7315) +++ trunk/docutils/docutils/_compat.py 2012-01-19 11:31:58 UTC (rev 7316) @@ -10,7 +10,8 @@ * bytes (name of byte string type; str in 2.x, bytes in 3.x) * b (function converting a string literal to an ASCII byte string; can be also used to convert a Unicode string into a byte string) -* u_prefix (unicode repr prefix, 'u' in 2.x, nothing in 3.x) +* u_prefix (unicode repr prefix: 'u' in 2.x, '' in 3.x) + (Required in docutils/test/test_publisher.py) * BytesIO (a StringIO class that works with bytestrings) """ Modified: trunk/docutils/docutils/error_reporting.py =================================================================== --- trunk/docutils/docutils/error_reporting.py 2012-01-18 10:16:20 UTC (rev 7315) +++ trunk/docutils/docutils/error_reporting.py 2012-01-19 11:31:58 UTC (rev 7316) @@ -95,14 +95,17 @@ * else decode with `self.encoding` and `self.decoding_errors`. """ try: - return unicode(self.data) + u = unicode(self.data) + if isinstance(self.data, EnvironmentError): + u = u.replace(": u'", ": '") # normalize filename quoting + return u except UnicodeError, 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, - self.decoding_errors), + self.decoding_errors), SafeString(self.data.filename, self.encoding, - self.decoding_errors)) + self.decoding_errors)) if isinstance(self.data, Exception): args = [unicode(SafeString(arg, self.encoding, decoding_errors=self.decoding_errors)) 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-18 10:16:20 UTC (rev 7315) +++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2012-01-19 11:31:58 UTC (rev 7316) @@ -11,7 +11,7 @@ import os.path import sys from __init__ import DocutilsTestSupport -from docutils._compat import u_prefix, b +from docutils._compat import b def suite(): s = DocutilsTestSupport.ParserTestSuite() @@ -158,25 +158,14 @@ <system_message level="4" line="1" source="test data" type="SEVERE"> <paragraph> Problems with "raw" directive path: - IOError: [Errno 2] No such file or directory: %s'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 -""" % u_prefix], +"""], # note that this output is rewritten below for certain python versions ] -# Rewrite tests that depend on the output of IOError as it is -# platform-dependent before python 2.4 for a unicode path. -if sys.version_info < (2, 4): - # remove the unicode repr u except for py2.3 on windows: - if not sys.platform.startswith('win') or sys.version_info < (2, 3): - for i in range(len(totest['raw'])): - if totest['raw'][i][1].find("u'non-existent.file'") != -1: - totest['raw'][i][1] = totest['raw'][i][1].replace( - "u'non-existent.file'", "'non-existent.file'") - - if __name__ == '__main__': import unittest unittest.main(defaultTest='suite') Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py =================================================================== --- trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2012-01-18 10:16:20 UTC (rev 7315) +++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2012-01-19 11:31:58 UTC (rev 7316) @@ -12,7 +12,6 @@ import os import csv -from docutils._compat import u_prefix from docutils.parsers.rst.directives import tables @@ -558,11 +557,11 @@ <system_message level="4" line="1" source="test data" type="SEVERE"> <paragraph> Problems with "csv-table" directive path: - [Errno 2] No such file or directory: %s'bogus.csv'. + [Errno 2] No such file or directory: 'bogus.csv'. <literal_block xml:space="preserve"> .. csv-table:: no such file :file: bogus.csv -""" % u_prefix], +"""], # note that this output is rewritten below for certain python versions ["""\ .. csv-table:: bad URL This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |