|
From: <mi...@us...> - 2022-06-17 11:31:42
|
Revision: 9078
http://sourceforge.net/p/docutils/code/9078
Author: milde
Date: 2022-06-17 11:31:40 +0000 (Fri, 17 Jun 2022)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/frontend.py
trunk/docutils/docutils/io.py
trunk/docutils/docutils/utils/error_reporting.py
trunk/docutils/test/test_io.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2022-06-17 11:31:28 UTC (rev 9077)
+++ trunk/docutils/HISTORY.txt 2022-06-17 11:31:40 UTC (rev 9078)
@@ -31,6 +31,11 @@
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 @@
* 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
Modified: trunk/docutils/docutils/frontend.py
===================================================================
--- trunk/docutils/docutils/frontend.py 2022-06-17 11:31:28 UTC (rev 9077)
+++ trunk/docutils/docutils/frontend.py 2022-06-17 11:31:40 UTC (rev 9078)
@@ -449,7 +449,8 @@
"""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'
Modified: trunk/docutils/docutils/io.py
===================================================================
--- trunk/docutils/docutils/io.py 2022-06-17 11:31:28 UTC (rev 9077)
+++ trunk/docutils/docutils/io.py 2022-06-17 11:31:40 UTC (rev 9078)
@@ -20,7 +20,7 @@
# 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()`
@@ -27,22 +27,22 @@
# 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 @@
# 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 @@
"""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
Modified: trunk/docutils/docutils/utils/error_reporting.py
===================================================================
--- trunk/docutils/docutils/utils/error_reporting.py 2022-06-17 11:31:28 UTC (rev 9077)
+++ trunk/docutils/docutils/utils/error_reporting.py 2022-06-17 11:31:40 UTC (rev 9078)
@@ -21,7 +21,6 @@
| 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 @@
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'
Modified: trunk/docutils/test/test_io.py
===================================================================
--- trunk/docutils/test/test_io.py 2022-06-17 11:31:28 UTC (rev 9077)
+++ trunk/docutils/test/test_io.py 2022-06-17 11:31:40 UTC (rev 9078)
@@ -132,11 +132,11 @@
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:
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py 2022-06-17 11:31:28 UTC (rev 9077)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_date.py 2022-06-17 11:31:40 UTC (rev 9078)
@@ -13,7 +13,7 @@
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 @@
# 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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|