summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2023-01-10 13:13:17 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2023-01-10 13:13:17 +0000
commit7c60a59d1b5e83d9f5fba0e87ad71ec5ec8b02cf (patch)
tree69dbe3cb9e9bd74193b31556c277323cc8e35b0e /docutils
parent8e47f6296b2a24ab76d304ae44fcdba233828a31 (diff)
downloaddocutils-7c60a59d1b5e83d9f5fba0e87ad71ec5ec8b02cf.tar.gz
`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: https://svn.code.sf.net/p/docutils/code/trunk@9314 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/HISTORY.txt1
-rw-r--r--docutils/docutils/io.py7
-rwxr-xr-xdocutils/docutils/utils/smartquotes.py2
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'