diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-06-17 11:31:40 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-06-17 11:31:40 +0000 |
| commit | 9630c3e4d94bc95a44b77d63b6827a56fa675244 (patch) | |
| tree | 4bab1487791bd4a5a5c216efb0f32a8abc992dd0 | |
| parent | 631508c04dd93d84f325ec4ce3885afe8e3f733d (diff) | |
| download | docutils-9630c3e4d94bc95a44b77d63b6827a56fa675244.tar.gz | |
Rename `io.locale_encoding` to mark it as internal.
The attribute was moved to "io" after the last release.
Backwards compatibility is ensured via `locale_encoding`
in the (deprecated) "utils.error_reporting" module.
Fix HISTORY entries.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9078 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/HISTORY.txt | 7 | ||||
| -rw-r--r-- | docutils/docutils/frontend.py | 3 | ||||
| -rw-r--r-- | docutils/docutils/io.py | 22 | ||||
| -rw-r--r-- | docutils/docutils/utils/error_reporting.py | 3 | ||||
| -rwxr-xr-x | docutils/test/test_io.py | 4 | ||||
| -rwxr-xr-x | docutils/test/test_parsers/test_rst/test_directives/test_date.py | 4 |
6 files changed, 23 insertions, 20 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 72afab754..4e8e66acd 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -31,6 +31,11 @@ Changes Since 0.18.1 Let `Publisher.publish()` print info and prompt when waiting for input from a terminal (cf. https://clig.dev/#interactivity). +* docutils/io.py + - New function `error_string()` + obsoletes `utils.error_reporting.ErrorString`. + - Class `ErrorOutput` moved here from `utils/error_reporting`. + * docutils/parsers/__init__.py - Aliases "markdown" and "commonmark" point to "commonmark_wrapper". @@ -76,8 +81,6 @@ Changes Since 0.18.1 * docutils/utils/__init__.py - `decode_path()` returns `str` instance instead of `nodes.reprunicode`. - - New function `error_string()` obsoletes utils.error_reporting.ErrorString. - - Class `ErrorOutput` moved here from docutils/utils/error_reporting.py * docutils/utils/error_reporting.py diff --git a/docutils/docutils/frontend.py b/docutils/docutils/frontend.py index 9960cfd85..b204aec8f 100644 --- a/docutils/docutils/frontend.py +++ b/docutils/docutils/frontend.py @@ -449,7 +449,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): """Lookup table for boolean configuration file settings.""" default_error_encoding = (getattr(sys.stderr, 'encoding', None) - or io.locale_encoding or 'ascii') + or io._locale_encoding # noqa + or 'ascii') default_error_encoding_error_handler = 'backslashreplace' diff --git a/docutils/docutils/io.py b/docutils/docutils/io.py index bd42c19c6..932ef2296 100644 --- a/docutils/docutils/io.py +++ b/docutils/docutils/io.py @@ -20,29 +20,29 @@ from docutils import TransformSpec # Guess the locale's preferred encoding. -# If no valid guess can be made, locale_encoding is set to `None`: +# If no valid guess can be made, _locale_encoding is set to `None`: # # TODO: check whether this is set correctly with every OS and Python version # or whether front-end tools need to call `locale.setlocale()` # before importing this module try: # Return locale encoding also in UTF-8 mode - locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] - locale_encoding = locale_encoding.lower() + _locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] + _locale_encoding = _locale_encoding.lower() except ValueError as error: # OS X may set UTF-8 without language code # See https://bugs.python.org/issue18378 fixed in 3.8 # and https://sourceforge.net/p/docutils/bugs/298/. # Drop the special case after requiring Python >= 3.8 if "unknown locale: UTF-8" in error.args: - locale_encoding = "utf-8" + _locale_encoding = "utf-8" else: - locale_encoding = None + _locale_encoding = None except: # noqa any other problems determining the locale -> use None - locale_encoding = None + _locale_encoding = None try: - codecs.lookup(locale_encoding) + codecs.lookup(_locale_encoding) except (LookupError, TypeError): - locale_encoding = None + _locale_encoding = None class InputError(OSError): pass @@ -139,8 +139,8 @@ class Input(TransformSpec): # no BOM found. Start with UTF-8, because that only matches # data that *IS* UTF-8: encodings = ['utf-8', 'latin-1'] - if locale_encoding: - encodings.insert(1, locale_encoding) + if _locale_encoding: + encodings.insert(1, _locale_encoding) for enc in encodings: try: decoded = str(data, enc, self.error_handler) @@ -267,7 +267,7 @@ class ErrorOutput: """Where warning output is sent.""" self.encoding = (encoding or getattr(destination, 'encoding', None) - or locale_encoding or 'ascii') + or _locale_encoding or 'ascii') """The output character encoding.""" self.encoding_errors = encoding_errors diff --git a/docutils/docutils/utils/error_reporting.py b/docutils/docutils/utils/error_reporting.py index 8f157f493..3a7bcfd1f 100644 --- a/docutils/docutils/utils/error_reporting.py +++ b/docutils/docutils/utils/error_reporting.py @@ -21,7 +21,6 @@ Deprecated module to handle Exceptions across Python versions. | SafeString -> str | ErrorString -> docutils.io.error_string() | ErrorOutput -> docutils.io.ErrorOutput - | locale_encoding -> docutils.io.locale_encoding Error reporting should be safe from encoding/decoding errors. However, implicit conversions of strings and exceptions like @@ -48,7 +47,7 @@ common exceptions. import sys import warnings -from docutils.io import locale_encoding +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' diff --git a/docutils/test/test_io.py b/docutils/test/test_io.py index e0fbc48c7..8ccf567f0 100755 --- a/docutils/test/test_io.py +++ b/docutils/test/test_io.py @@ -132,11 +132,11 @@ print("hello world") def test_heuristics_no_utf8(self): # if no encoding is given and decoding with 'utf-8' fails, # use either the locale encoding (if specified) or 'latin-1': - if io.locale_encoding not in ('utf-8', 'utf8'): + if io._locale_encoding not in ('utf-8', 'utf8'): # noqa # in Py3k, the locale encoding is used without --input-encoding # skipping the heuristic unless decoding fails. return - probed_encodings = (io.locale_encoding, 'latin-1') + probed_encodings = (io._locale_encoding, 'latin-1') # noqa input = io.FileInput(source_path='data/latin1.txt') data = input.read() if input.successful_encoding not in probed_encodings: diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_date.py b/docutils/test/test_parsers/test_rst/test_directives/test_date.py index ce07d7e8d..c4c70227c 100755 --- a/docutils/test/test_parsers/test_rst/test_directives/test_date.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_date.py @@ -13,7 +13,7 @@ if __name__ == '__main__': from test_parsers import DocutilsTestSupport import time -from docutils.io import locale_encoding +from docutils.io import _locale_encoding # noqa def suite(): @@ -63,7 +63,7 @@ Today's date is |date|. # some locales return non-ASCII characters for names of days or months # ensure the directive handles them correctly -if locale_encoding in ('utf-8', 'utf8', 'latin-1', 'iso-8859-1'): +if _locale_encoding in ('utf-8', 'utf8', 'latin-1', 'iso-8859-1'): totest['decode date'] = [ ["""\ .. |date| date:: täglich |
