From 58119d0ce95c58258c8301944242fa10db8384d9 Mon Sep 17 00:00:00 2001 From: milde Date: Tue, 10 Jan 2023 13:13:17 +0000 Subject: [PATCH] `locale.getdefaultlocale()` is deprecated in Python 0.11 Let `smartquotes.py` to use `locale.getlocale` instead. (Only used if this module is called as standalone application.) Suppress warning in `docutils.io`: * Don't change current behaviour without advance warning. * The deprecated function is called inside a try-block with catchall, so this will not lead to errors once it is removed (if we were to keep the code until then). Fixes [bugs:#464]. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@9314 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 1 + docutils/docutils/io.py | 7 +++++-- docutils/docutils/utils/smartquotes.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 3007e5739..24b9d600c 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -158,6 +158,7 @@ Release 0.19 (2022-07-05) - Use "utf-8-sig" instead of Python's default encoding if the `input_encoding`_ setting is None. - Fix error when reading of UTF-16 encoded source without trailing newline. + - Suppress deprecation warning (fixes bug #464). * docutils/parsers/__init__.py diff --git a/docutils/docutils/io.py b/docutils/docutils/io.py index f8461a5b3..c291f40cb 100644 --- a/docutils/docutils/io.py +++ b/docutils/docutils/io.py @@ -27,8 +27,11 @@ from docutils import TransformSpec # 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() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + _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/. diff --git a/docutils/docutils/utils/smartquotes.py b/docutils/docutils/utils/smartquotes.py index 996b0b8d9..72022b473 100755 --- a/docutils/docutils/utils/smartquotes.py +++ b/docutils/docutils/utils/smartquotes.py @@ -897,7 +897,7 @@ if __name__ == "__main__": import locale try: locale.setlocale(locale.LC_ALL, '') # set to user defaults - defaultlanguage = locale.getdefaultlocale()[0] + defaultlanguage = locale.getlocale()[0] except: # noqa catchall defaultlanguage = 'en' -- 2.11.4.GIT