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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9974
          http://sourceforge.net/p/docutils/code/9974
Author:   milde
Date:     2024-10-28 22:18:58 +0000 (Mon, 28 Oct 2024)
Log Message:
-----------
Wrap setting the default "locale" in try/except, report locale.Error as warning.

Docutils command line tools use `locale.setlocale()` to set the locale to the user's
default locale. This may lead to a `locale.Error` if there are problems in the
systems locale setup. As locale settings are not critical for the working of
Docutils (but may affect the output in certain instances), we now clear the
exception and report a WARNING.

Fixes bug #495.

Modified Paths:
--------------
    trunk/docutils/docutils/__main__.py
    trunk/docutils/docutils/core.py

Modified: trunk/docutils/docutils/__main__.py
===================================================================
--- trunk/docutils/docutils/__main__.py	2024-10-26 15:14:09 UTC (rev 9973)
+++ trunk/docutils/docutils/__main__.py	2024-10-28 22:18:58 UTC (rev 9974)
@@ -56,7 +56,10 @@
 def main() -> None:
     """Generic command line interface for the Docutils Publisher.
     """
-    locale.setlocale(locale.LC_ALL, '')
+    try:
+        locale.setlocale(locale.LC_ALL, '')
+    except locale.Error as e:
+        sys.stderr.write(f'WARNING: Cannot set the default locale: {e}.\n')
 
     description = ('Convert documents into useful formats.  '
                    + default_description)

Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py	2024-10-26 15:14:09 UTC (rev 9973)
+++ trunk/docutils/docutils/core.py	2024-10-28 22:18:58 UTC (rev 9974)
@@ -799,7 +799,10 @@
         'from standalone reStructuredText sources '
         f'<https://docutils.sourceforge.io/docs/{doc_path}>.  '
         + default_description)
-    locale.setlocale(locale.LC_ALL, '')
+    try:
+        locale.setlocale(locale.LC_ALL, '')
+    except locale.Error as e:
+        sys.stderr.write(f'WARNING: Cannot set the default locale: {e}.\n')
     publish_cmdline(writer=writer, description=description)
 
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
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.