SF.net SVN: docutils:[9758] trunk/docutils

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9758
          http://sourceforge.net/p/docutils/code/9758
Author:   milde
Date:     2024-06-14 15:03:42 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `docutils.utils.error_reporting`.

Obsolete in Python 3

Modified Paths:
--------------
    trunk/docutils/HISTORY.txt
    trunk/docutils/RELEASE-NOTES.txt

Removed Paths:
-------------
    trunk/docutils/docutils/utils/error_reporting.py
    trunk/docutils/test/test_error_reporting.py

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/HISTORY.txt	2024-06-14 15:03:42 UTC (rev 9758)
@@ -81,6 +81,10 @@
 
   - `Messages` also handles "loose" system messages generated by the parser.
 
+* docutils/utils/error_reporting.py
+
+  - Removed. Obsolete in Python 3.
+
 * docutils/writers/_html_base.py
 
   - Make MathML the default math_output_.

Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt	2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/RELEASE-NOTES.txt	2024-06-14 15:03:42 UTC (rev 9758)
@@ -226,6 +226,8 @@
 
   `docutils.nodes.Element.set_class()`
      Obsolete. Append to Element['classes'] directly.
+  `docutils.utils.error_reporting`
+     Obsolete in Python 3
 
 * Removed files:
 

Deleted: trunk/docutils/docutils/utils/error_reporting.py
===================================================================
--- trunk/docutils/docutils/utils/error_reporting.py	2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/docutils/utils/error_reporting.py	2024-06-14 15:03:42 UTC (rev 9758)
@@ -1,222 +0,0 @@
-#!/usr/bin/env python3
-# :Id: $Id$
-# :Copyright: © 2011 Günter Milde.
-# :License: Released under the terms of the `2-Clause BSD license`_, in short:
-#
-#    Copying and distribution of this file, with or without modification,
-#    are permitted in any medium without royalty provided the copyright
-#    notice and this notice are preserved.
-#    This file is offered as-is, without any warranty.
-#
-# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
-
-"""
-Deprecated module to handle Exceptions across Python versions.
-
-.. warning::
-   This module is deprecated with the end of support for Python 2.7
-   and will be removed in Docutils 0.21 or later.
-
-   Replacements:
-     | SafeString  -> str
-     | ErrorString -> docutils.io.error_string()
-     | ErrorOutput -> docutils.io.ErrorOutput
-
-Error reporting should be safe from encoding/decoding errors.
-However, implicit conversions of strings and exceptions like
-
->>> u'%s world: %s' % ('H\xe4llo', Exception(u'H\xe4llo'))
-
-fail in some Python versions:
-
-* In Python <= 2.6, ``unicode(<exception instance>)`` uses
-  `__str__` and fails with non-ASCII chars in`unicode` arguments.
-  (work around http://bugs.python.org/issue2517):
-
-* In Python 2, unicode(<exception instance>) fails, with non-ASCII
-  chars in arguments. (Use case: in some locales, the errstr
-  argument of IOError contains non-ASCII chars.)
-
-* In Python 2, str(<exception instance>) fails, with non-ASCII chars
-  in `unicode` arguments.
-
-The `SafeString`, `ErrorString` and `ErrorOutput` classes handle
-common exceptions.
-"""
-
-import sys
-import warnings
-
-from docutils.io import _locale_encoding as locale_encoding  # noqa
-
-warnings.warn('The `docutils.utils.error_reporting` module is deprecated '
-              'and will be removed in Docutils 0.21 or later.\n'
-              'Details with help("docutils.utils.error_reporting").',
-              DeprecationWarning, stacklevel=2)
-
-
-if sys.version_info >= (3, 0):
-    unicode = str  # noqa
-
-
-class SafeString:
-    """
-    A wrapper providing robust conversion to `str` and `unicode`.
-    """
-
-    def __init__(self, data, encoding=None, encoding_errors='backslashreplace',
-                 decoding_errors='replace'):
-        self.data = data
-        self.encoding = (encoding or getattr(data, 'encoding', None)
-                         or locale_encoding or 'ascii')
-        self.encoding_errors = encoding_errors
-        self.decoding_errors = decoding_errors
-
-    def __str__(self):
-        try:
-            return str(self.data)
-        except UnicodeEncodeError:
-            if isinstance(self.data, Exception):
-                args = [str(SafeString(arg, self.encoding,
-                                       self.encoding_errors))
-                        for arg in self.data.args]
-                return ', '.join(args)
-            if isinstance(self.data, unicode):
-                if sys.version_info > (3, 0):
-                    return self.data
-                else:
-                    return self.data.encode(self.encoding,
-                                            self.encoding_errors)
-            raise
-
-    def __unicode__(self):
-        """
-        Return unicode representation of `self.data`.
-
-        Try ``unicode(self.data)``, catch `UnicodeError` and
-
-        * if `self.data` is an Exception instance, work around
-          http://bugs.python.org/issue2517 with an emulation of
-          Exception.__unicode__,
-
-        * else decode with `self.encoding` and `self.decoding_errors`.
-        """
-        try:
-            u = unicode(self.data)
-            if isinstance(self.data, EnvironmentError):
-                u = u.replace(": u'", ": '") # normalize filename quoting
-            return u
-        except UnicodeError as error: # catch ..Encode.. and ..Decode.. errors
-            if isinstance(self.data, EnvironmentError):
-                return "[Errno %s] %s: '%s'" % (
-                    self.data.errno,
-                    SafeString(self.data.strerror, self.encoding,
-                               self.decoding_errors),
-                    SafeString(self.data.filename, self.encoding,
-                               self.decoding_errors))
-            if isinstance(self.data, Exception):
-                args = [unicode(SafeString(
-                                    arg, self.encoding,
-                                    decoding_errors=self.decoding_errors))
-                        for arg in self.data.args]
-                return u', '.join(args)
-            if isinstance(error, UnicodeDecodeError):
-                return unicode(self.data, self.encoding, self.decoding_errors)
-            raise
-
-
-class ErrorString(SafeString):
-    """
-    Safely report exception type and message.
-    """
-    def __str__(self):
-        return '%s: %s' % (self.data.__class__.__name__,
-                           super(ErrorString, self).__str__())
-
-    def __unicode__(self):
-        return u'%s: %s' % (self.data.__class__.__name__,
-                            super(ErrorString, self).__unicode__())
-
-
-class ErrorOutput:
-    """
-    Wrapper class for file-like error streams with
-    failsafe de- and encoding of `str`, `bytes`, `unicode` and
-    `Exception` instances.
-    """
-
-    def __init__(self, stream=None, encoding=None,
-                 encoding_errors='backslashreplace',
-                 decoding_errors='replace'):
-        """
-        :Parameters:
-            - `stream`: a file-like object,
-                        a string (path to a file),
-                        `None` (write to `sys.stderr`, default), or
-                        evaluating to `False` (write() requests are ignored).
-            - `encoding`: `stream` text encoding. Guessed if None.
-            - `encoding_errors`: how to treat encoding errors.
-        """
-        if stream is None:
-            stream = sys.stderr
-        elif not stream:
-            stream = False
-        # if `stream` is a file name, open it
-        elif isinstance(stream, str):
-            stream = open(stream, 'w')
-        elif isinstance(stream, unicode):
-            stream = open(stream.encode(sys.getfilesystemencoding()), 'w')
-
-        self.stream = stream
-        """Where warning output is sent."""
-
-        self.encoding = (encoding or getattr(stream, 'encoding', None)
-                         or locale_encoding or 'ascii')
-        """The output character encoding."""
-
-        self.encoding_errors = encoding_errors
-        """Encoding error handler."""
-
-        self.decoding_errors = decoding_errors
-        """Decoding error handler."""
-
-    def write(self, data):
-        """
-        Write `data` to self.stream. Ignore, if self.stream is False.
-
-        `data` can be a `string`, `unicode`, or `Exception` instance.
-        """
-        if self.stream is False:
-            return
-        if isinstance(data, Exception):
-            data = unicode(SafeString(data, self.encoding,
-                                      self.encoding_errors,
-                                      self.decoding_errors))
-        try:
-            self.stream.write(data)
-        except UnicodeEncodeError:
-            self.stream.write(data.encode(self.encoding, self.encoding_errors))
-        except TypeError:
-            if isinstance(data, unicode): # passed stream may expect bytes
-                self.stream.write(data.encode(self.encoding,
-                                              self.encoding_errors))
-                return
-            if self.stream in (sys.stderr, sys.stdout):
-                self.stream.buffer.write(data) # write bytes to raw stream
-            else:
-                self.stream.write(unicode(data, self.encoding,
-                                          self.decoding_errors))
-
-    def close(self):
-        """
-        Close the error-output stream.
-
-        Ignored if the stream is` sys.stderr` or `sys.stdout` or has no
-        close() method.
-        """
-        if self.stream in (sys.stdout, sys.stderr):
-            return
-        try:
-            self.stream.close()
-        except AttributeError:
-            pass

Deleted: trunk/docutils/test/test_error_reporting.py
===================================================================
--- trunk/docutils/test/test_error_reporting.py	2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/test/test_error_reporting.py	2024-06-14 15:03:42 UTC (rev 9758)
@@ -1,264 +0,0 @@
-#! /usr/bin/env python3
-# $Id$
-# Author: Günter Milde <[email protected]>
-# Copyright: This module has been placed in the public domain.
-
-"""
-Test `EnvironmentError` reporting.
-
-In some locales, the `errstr` argument of IOError and OSError contains
-non-ASCII chars.
-
-In Python 2, converting an exception instance to `str` or `unicode`
-might fail, with non-ASCII chars in arguments and the default encoding
-and errors ('ascii', 'strict').
-
-Therefore, Docutils must not use string interpolation with exception
-instances like, e.g., ::
-
-  try:
-    something
-  except IOError as error:
-    print('Found %s' % error)
-
-unless the minimal required Python version has this problem fixed.
-"""
-
-from io import StringIO, BytesIO
-from pathlib import Path
-import sys
-import unittest
-import warnings
-
-if __name__ == '__main__':
-    # prepend the "docutils root" to the Python library path
-    # so we import the local `docutils` package.
-    sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
-
-from docutils import frontend, utils
-import docutils.parsers.rst
-warnings.filterwarnings('ignore', category=DeprecationWarning,
-                        module='.*error_reporting')
-from docutils.utils.error_reporting import SafeString, ErrorString, ErrorOutput  # noqa: E402, E501
-
-
-class SafeStringTests(unittest.TestCase):
-
-    # test data:
-    bs = b'\xc3\xbc'   # str(bs) returns repr(bs)
-    us = u'\xfc'       # bytes(us) fails (requires encoding argument)
-    be = Exception(bs)
-    ue = Exception(us) # bytes(ue) fails
-    # wrapped test data:
-    wbs = SafeString(bs)
-    wus = SafeString(us)
-    wbe = SafeString(be)
-    wue = SafeString(ue)
-
-    def test_7bit(self):
-        # wrapping (not required with 7-bit chars) must not change the
-        # result of conversions:
-        bs7 = b'foo'
-        us7 = u'foo'
-        be7 = Exception(bs7)
-        ue7 = Exception(us7)
-        self.assertEqual(str(bs7), str(SafeString(bs7)))
-        self.assertEqual(str(us7), str(SafeString(us7)))
-        self.assertEqual(str(be7), str(SafeString(be7)))
-        self.assertEqual(str(ue7), str(SafeString(ue7)))
-
-    def test_ustr(self):
-        """Test conversion to a unicode-string."""
-        # unicode(self.bs) fails
-        self.assertEqual(str, type(str(self.wbs)))
-        self.assertEqual(str(self.us), str(self.wus))
-        # unicode(self.be) fails
-        self.assertEqual(str, type(str(self.wbe)))
-        self.assertEqual(str, type(str(self.ue)))
-        self.assertEqual(str, type(str(self.wue)))
-        self.assertEqual(self.us, str(self.wue))
-
-    def test_str(self):
-        """Test conversion to a string
-
-        (bytes in Python 2, unicode in Python 3).
-        """
-        self.assertEqual(str(self.bs), str(self.wbs))
-        self.assertEqual(str(self.be), str(self.wbe))
-        self.assertEqual(str(self.us), str(self.wus))
-        self.assertEqual(str(self.ue), str(self.wue))
-
-
-class ErrorStringTests(unittest.TestCase):
-    bs = b'\xc3\xbc' # unicode(bs) fails, str(bs) in Python 3 return repr()
-    us = u'\xfc'     # bytes(us) fails; str(us) fails in Python 2
-
-    def test_str(self):
-        self.assertEqual('Exception: spam',
-                         str(ErrorString(Exception('spam'))))
-        self.assertEqual('IndexError: '+str(self.bs),
-                         str(ErrorString(IndexError(self.bs))))
-        self.assertEqual('ImportError: %s' % SafeString(self.us),
-                         str(ErrorString(ImportError(self.us))))
-
-    def test_unicode(self):
-        self.assertEqual(u'Exception: spam',
-                         str(ErrorString(Exception(u'spam'))))
-        self.assertEqual(u'IndexError: '+self.us,
-                         str(ErrorString(IndexError(self.us))))
-        self.assertEqual(u'ImportError: %s' % SafeString(self.bs),
-                         str(ErrorString(ImportError(self.bs))))
-
-
-# ErrorOutput tests
-# -----------------
-
-# Stub: Buffer with 'strict' auto-conversion of input to byte string:
-class BBuf(BytesIO):
-    def write(self, data):
-        if isinstance(data, str):
-            data.encode('ascii', 'strict')
-        super(BBuf, self).write(data)
-
-
-# Stub: Buffer expecting unicode string:
-class UBuf(StringIO):
-    def write(self, data):
-        # emulate Python 3 handling of stdout, stderr
-        if isinstance(data, bytes):
-            raise TypeError('must be unicode, not bytes')
-        super(UBuf, self).write(data)
-
-
-class ErrorOutputTests(unittest.TestCase):
-    def test_defaults(self):
-        e = ErrorOutput()
-        self.assertEqual(e.stream, sys.stderr)
-
-    def test_bbuf(self):
-        buf = BBuf() # buffer storing byte string
-        e = ErrorOutput(buf, encoding='ascii')
-        # write byte-string as-is
-        e.write(b'b\xfc')
-        self.assertEqual(buf.getvalue(), b'b\xfc')
-        # encode unicode data with backslashescape fallback replacement:
-        e.write(u' u\xfc')
-        self.assertEqual(buf.getvalue(), b'b\xfc u\\xfc')
-        # handle Exceptions with Unicode string args
-        # unicode(Exception(u'e\xfc')) # fails in Python < 2.6
-        e.write(AttributeError(u' e\xfc'))
-        self.assertEqual(buf.getvalue(), b'b\xfc u\\xfc e\\xfc')
-        # encode with `encoding` attribute
-        e.encoding = 'utf-8'
-        e.write(u' u\xfc')
-        self.assertEqual(buf.getvalue(), b'b\xfc u\\xfc e\\xfc u\xc3\xbc')
-
-    def test_ubuf(self):
-        buf = UBuf() # buffer only accepting unicode string
-        # decode of binary strings
-        e = ErrorOutput(buf, encoding='ascii')
-        e.write(b'b\xfc')
-        self.assertEqual(buf.getvalue(), u'b\ufffd') # REPLACEMENT CHARACTER
-        # write Unicode string and Exceptions with Unicode args
-        e.write(u' u\xfc')
-        self.assertEqual(buf.getvalue(), u'b\ufffd u\xfc')
-        e.write(AttributeError(u' e\xfc'))
-        self.assertEqual(buf.getvalue(), u'b\ufffd u\xfc e\xfc')
-        # decode with `encoding` attribute
-        e.encoding = 'latin1'
-        e.write(b' b\xfc')
-        self.assertEqual(buf.getvalue(), u'b\ufffd u\xfc e\xfc b\xfc')
-
-
-class SafeStringTests_locale(unittest.TestCase):
-    """
-    Test docutils.SafeString with 'problematic' locales.
-
-    The error message in `EnvironmentError` instances comes from the OS
-    and in some locales (e.g. ru_RU), contains high bit chars.
-    """
-    # test data:
-    bs = b'\xc3\xbc'
-    us = u'\xfc'
-    try:
-        open(b'\xc3\xbc')
-    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 as e:
-        uioe = e
-    except UnicodeEncodeError:
-        try:
-            open(u'\xfc'.encode(sys.getfilesystemencoding(), 'replace'))
-        except IOError as e:
-            uioe = e
-    bose = FileNotFoundError(2, 'The system cannot find the file specified')
-    bose.filename = b'\xc3\xbc'
-    uose = FileNotFoundError(2, 'The system cannot find the file specified')
-    uose.filename = '\xfc'
-    # wrapped test data:
-    wbioe = SafeString(bioe)
-    wuioe = SafeString(uioe)
-    wbose = SafeString(bose)
-    wuose = SafeString(uose)
-
-    def test_ustr(self):
-        """Test conversion to a unicode-string."""
-        # unicode(bioe) fails with e.g. 'ru_RU.utf8' locale
-        self.assertEqual(str, type(str(self.wbioe)))
-        self.assertEqual(str, type(str(self.wuioe)))
-        self.assertEqual(str, type(str(self.wbose)))
-        self.assertEqual(str, type(str(self.wuose)))
-
-    def test_str(self):
-        """Test conversion to a string
-
-        (bytes in Python 2, unicode in Python 3).
-        """
-        self.assertEqual(str(self.bioe), str(self.wbioe))
-        self.assertEqual(str(self.uioe), str(self.wuioe))
-        self.assertEqual(str(self.bose), str(self.wbose))
-        self.assertEqual(str(self.uose), str(self.wuose))
-
-
-class ErrorReportingTests(unittest.TestCase):
-    """
-    Test cases where error reporting can go wrong.
-
-    Do not test the exact output (as this varies with the locale), just
-    ensure that the correct exception is thrown.
-    """
-
-    # These tests fail with a 'problematic locale',
-    # Docutils revision < 7035, and Python 2:
-
-    parser = docutils.parsers.rst.Parser()
-    """Parser shared by all ParserTestCases."""
-
-    settings = frontend.get_default_settings(parser)
-    settings.report_level = 1
-    settings.halt_level = 1
-    settings.warning_stream = ''
-    document = utils.new_document('test data', settings)
-
-    def test_include(self):
-        source = '.. include:: bogus.txt'
-        self.assertRaises(utils.SystemMessage,
-                          self.parser.parse, source, self.document)
-
-    def test_raw_file(self):
-        source = ('.. raw:: html\n'
-                  '   :file: bogus.html\n')
-        self.assertRaises(utils.SystemMessage,
-                          self.parser.parse, source, self.document)
-
-    def test_csv_table(self):
-        source = ('.. csv-table:: external file\n'
-                  '   :file: bogus.csv\n')
-        self.assertRaises(utils.SystemMessage,
-                          self.parser.parse, source, self.document)
-
-
-if __name__ == '__main__':
-    unittest.main()

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.