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

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9749
          http://sourceforge.net/p/docutils/code/9749
Author:   milde
Date:     2024-06-10 14:24:00 +0000 (Mon, 10 Jun 2024)
Log Message:
-----------
encoding settings: remove shortcuts `-i` and `-o`, default to UTF-8.

Drop short options ``-i`` and ``-o``.
Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
(See `command line interface`_ for the rationale.)

Change the default input encoding from auto-detect to "utf-8".

Update documentation and tests.

Modified Paths:
--------------
    trunk/docutils/FAQ.txt
    trunk/docutils/HISTORY.txt
    trunk/docutils/RELEASE-NOTES.txt
    trunk/docutils/docs/api/publisher.txt
    trunk/docutils/docs/howto/cmdline-tool.txt
    trunk/docutils/docs/ref/rst/directives.txt
    trunk/docutils/docs/ref/rst/restructuredtext.txt
    trunk/docutils/docs/user/config.txt
    trunk/docutils/docutils/frontend.py
    trunk/docutils/test/data/help/docutils.txt
    trunk/docutils/test/data/help/rst2html.txt
    trunk/docutils/test/data/help/rst2latex.txt
    trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
    trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
    trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
    trunk/docutils/test/test_publisher.py

Modified: trunk/docutils/FAQ.txt
===================================================================
--- trunk/docutils/FAQ.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/FAQ.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -1139,11 +1139,8 @@
   <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
 
 The common case is with the default output encoding (UTF-8), when
-either numbered sections are used (via the "sectnum_" directive) or
-symbol-footnotes.  Three non-breaking spaces are inserted in each numbered
-section title, between the generated number and the title text.  Most
-footnote symbols are not available in ASCII, nor are non-breaking
-spaces.  When encoded with UTF-8 and viewed with ordinary ASCII tools,
+using symbol-footnotes.  Most footnote symbols are not available in ASCII.
+When encoded with UTF-8 and viewed with ordinary ASCII tools,
 these characters will appear to be multi-character garbage.
 
 You may have an decoding problem in your browser (or editor, etc.).

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/HISTORY.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -27,6 +27,12 @@
   - Allow multiple <term> elements in a <definition_list_item>.
     Fixes feature-request #60
 
+* docutils/frontend.py
+
+  - Drop short options ``-i`` and ``-o`` for ``--input-encoding``
+    and ``--output-encoding``.
+  - Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+
 * docutils/nodes.py
 
   - Raise TypeError if the "rawsource" argument in `Element.__init__()`

Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/RELEASE-NOTES.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -30,9 +30,6 @@
        - COMMAND [OPTIONS] [SOURCE [DESTINATION]]
        + COMMAND [OPTIONS] [SOURCE [SOURCE2 [...]]] [>DESTINATION]
 
-  * Remove short options ``-i`` and ``-o`` in Docutils 0.22.
-    Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
-
   * Stop accepting the DESTINATION positional argument in Docutils 1.0.
     Use output redirection or the option ``--output=DESTINATION``
     (available since Docutils 0.20).
@@ -58,14 +55,6 @@
 
 .. _refname attribute: docs/ref/doctree.html#refname
 
-`Input encoding`_
------------------
-
-* Change the default input encoding from ``None`` (auto-detect) to
-  "utf-8" in Docutils 0.22.
-
-* Remove the input encoding auto-detection code in Docutils 1.0 or later.
-
 Writers
 -------
 
@@ -152,6 +141,8 @@
   .. _recommonmark parser: docs/user/config.html#recommonmark-parser
   .. _MyST parser: docs/user/config.html#myst-parser
 
+* Remove the input encoding auto-detection code in Docutils 1.0.
+
 * Remove the "rawsource" argument from `nodes.Text.__init__()`
   in Docutils 2.0.
 
@@ -217,6 +208,12 @@
 
   __ docs/ref/doctree.html#definition-list-item
 
+* Drop short options ``-i`` and ``-o``.
+  Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
+  (See `command line interface`_ for the rationale.)
+
+* Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+
 * New parser for `Docutils XML`_ (e.g., the output of the "xml" writer).
   Provisional.
 

Modified: trunk/docutils/docs/api/publisher.txt
===================================================================
--- trunk/docutils/docs/api/publisher.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/api/publisher.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -41,8 +41,8 @@
 publish_cmdline()
 -----------------
 
-Function for custom `command-line front-end tools`_ 
-(like ``tools/rst2html.py``) or "console_scripts" `entry points`_ 
+Function for custom `command-line front-end tools`_
+(like ``tools/rst2html.py``) or "console_scripts" `entry points`_
 (like `core.rst2html()`) with file I/O.
 In addition to writing the output document to a file-like object, also
 returns it as `str` instance (rsp. `bytes` for binary output document
@@ -71,11 +71,16 @@
   `bytes` are decoded with input_encoding_.
 
 Output
-  * is a `bytes` instance, if output_encoding_ is set to an encoding
+  is handled similar to `xml.etree.ElementTree.tostring()`__:
+
+  * return a `bytes` instance, if output_encoding_ is set to an encoding
     registered with Python's "codecs_" module (default: "utf-8"),
-  * a `str` instance, if output_encoding_ is set to the special value
+  * return `str` instance, if output_encoding_ is set to the special value
     ``"unicode"``.
 
+__ https://docs.python.org/3/library/xml.etree.elementtree.html
+   #xml.etree.ElementTree.tostring
+
 .. Caution::
    The "output_encoding" and "output_encoding_error_handler" `runtime
    settings`_ may affect the content of the output document:
@@ -439,33 +444,38 @@
 Encodings
 =========
 
-.. important:: Details will change over the next Docutils versions.
-   See RELEASE-NOTES_
+Docutils supports all `standard encodings`_ and encodings registered__
+with the codecs_ module.
+The special value "unicode" can be used with `publish_string()`_ to skip
+encoding and return a `str` instance instead of `bytes`.
 
-The **input encoding** can be specified with the `input_encoding`_ setting.
+__ https://docs.python.org/3/library/codecs.html#codecs.register
 
-By default, the input encoding is detected from a
-`Unicode byte order mark` (BOM_) or a "magic comment" [#magic-comment]_
-similar to :PEP:`263`. The fallback is "utf-8".
-The default behaviour differs from Python's `open()`:
 
-- An `explicit encoding declaration` ((BOM_) or a "magic comment"
-  [#magic-comment]_) in the source takes precedence over
-  the `preferred encoding`_.
-- An optional BOM_ is removed from sources.
+The **input encoding** can be specified with the `input_encoding`_ setting.
+The default is "utf-8".
+The **output encoding** can be specified with the `output_encoding`_ setting.
+The default is "utf-8", too.
 
-The default will change to "utf-8" in Docutils 0.22,
-the input encoding detection will be removed in Docutils 1.0.
-
-
-The default **output encoding** is UTF-8.
-A different encoding can be specified with the `output_encoding`_ setting.
-
 .. Caution:: Docutils may introduce non-ASCII text if you use
-   `auto-symbol footnotes`_ or the `"contents" directive`_.
+   `auto-symbol footnotes`_.
    In non-English documents, also auto-generated labels
    may contain non-ASCII characters.
 
+auto-detection
+--------------
+
+Up to Docutils 0.21, the input encoding was detected from a `Unicode byte
+order mark` (BOM_) or an *encoding declaration* [#magic-comment]_ in the
+source unless an input_encoding_ was specified.
+
+The default input encoding changed to "utf-8" in Docutils 0.22.
+Currently, auto-detection can be selected with an input_encoding_ value
+``None`` (rsp. an empty string in a configuration file).
+However, input encoding "auto-detection_" is deprecated and **will be
+removed** in Docutils 1.0. See the `inspecting_codecs`_ package for a
+possible replacement.
+
 .. [#magic-comment] A comment like ::
 
      .. text encoding: <encoding name>
@@ -490,15 +500,12 @@
    The first group of this expression is then interpreted as encoding name.
    If the first line matches the second line is ignored.
 
-   This feature is scheduled to be removed in Docutils 1.0.
-   See the `inspecting_codecs`_ package for a possible replacement.
 
 
-.. _Inside A Docutils Command-Line Front-End Tool: ../howto/cmdline-tool.html
-.. _RELEASE-NOTES: ../../RELEASE-NOTES.html#future-changes
+.. _codecs: https://docs.python.org/3/library/codecs.html
+.. _standard encodings:
+    https://docs.python.org/3/library/codecs.html#standard-encodings
 .. _input_encoding: ../user/config.html#input-encoding
-.. _preferred encoding:
-   https://docs.python.org/3/library/locale.html#locale.getpreferredencoding
 .. _BOM: https://docs.python.org/3/library/codecs.html#codecs.BOM
 .. _output_encoding: ../user/config.html#output-encoding
 .. _output_encoding_error_handler:
@@ -505,8 +512,6 @@
    ../user/config.html#output-encoding-error-handler
 .. _auto-symbol footnotes:
    ../ref/rst/restructuredtext.html#auto-symbol-footnotes
-.. _"contents" directive:
-   ../ref/rst/directives.html#table-of-contents
 .. _document tree:
 .. _Docutils document tree: ../ref/doctree.html
 .. _Docutils Runtime Settings: ./runtime-settings.html

Modified: trunk/docutils/docs/howto/cmdline-tool.txt
===================================================================
--- trunk/docutils/docs/howto/cmdline-tool.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/howto/cmdline-tool.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -44,7 +44,7 @@
     """
 
 This next block attempts to invoke locale support for
-internationalization services, specifically text encoding.  It's not
+internationalization services.  It's not
 supported on all platforms though, so it's forgiving::
 
     try:

Modified: trunk/docutils/docs/ref/rst/directives.txt
===================================================================
--- trunk/docutils/docs/ref/rst/directives.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/ref/rst/directives.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -1700,7 +1700,7 @@
 
 ``encoding`` : encoding_
     The text encoding of the external raw data (with ``file`` or ``url``).
-    Defaults to the main document's `input_encoding`_ (if specified).
+    Defaults to the main document's `input_encoding`_.
 
 ``file`` : path_
     The local filesystem path of a raw data file to be included.

Modified: trunk/docutils/docs/ref/rst/restructuredtext.txt
===================================================================
--- trunk/docutils/docs/ref/rst/restructuredtext.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/ref/rst/restructuredtext.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -1812,7 +1812,7 @@
 
 .. Note:: When using auto-symbol footnotes, the choice of output
    encoding is important.  Many of the symbols used are not encodable
-   in certain common text encodings such as Latin-1 (ISO 8859-1).  The
+   in 8-bit text encodings such as Latin-1 (ISO 8859-1).  The
    use of UTF-8 for the output encoding is recommended.  An
    alternative for HTML and XML output is to use the
    "xmlcharrefreplace" `output encoding error handler`_.

Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/user/config.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -415,17 +415,17 @@
 input_encoding
 --------------
 
-The text encoding for input (use the empty string to restore the default).
+The text encoding for input.
 
-*Default*: None (auto-detect_). [#]_
-*Options*: ``--input-encoding``, ``-i``. [#i-o-options]_
+*Default*: utf-8. [#]_
+*Option*: ``--input-encoding`` [#i-o-options]_
 
-.. [#] The default will change to "utf-8" in Docutils 0.22.
-.. [#i-o-options] The short options ``-i`` and ``-o`` `will be removed`__
+.. [#] The default changed from None (auto-detect_) to "utf-8" in
+       Docutils 0.22.
+.. [#i-o-options] The short options ``-i`` and ``-o`` were removed
                   in Docutils 0.22.
 
 .. _auto-detect: ../api/publisher.html#encodings
-__ ../../RELEASE-NOTES.html#command-line-interface
 
 
 input_encoding_error_handler
@@ -504,7 +504,7 @@
 
 This setting is ignored by the `ODF/ODT Writer`_ which always usues UTF-8.
 
-*Default*: "utf-8".  *Options*: ``--output-encoding``, ``-o``. [#i-o-options]_
+*Default*: "utf-8".  *Option*: ``--output-encoding``. [#i-o-options]_
 
 
 output_encoding_error_handler

Modified: trunk/docutils/docutils/frontend.py
===================================================================
--- trunk/docutils/docutils/frontend.py	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docutils/frontend.py	2024-06-10 14:24:00 UTC (rev 9749)
@@ -99,12 +99,14 @@
     if value is None:
         value = setting
     if value == '':
-        return None  # allow overwriting a config file value
+        warnings.warn('Input encoding detection will be removed '
+                      'in Docutils 1.0.', DeprecationWarning, stacklevel=2)
+        return None
     try:
         codecs.lookup(value)
     except LookupError:
-        raise LookupError('setting "%s": unknown encoding: "%s"'
-                          % (setting, value))
+        prefix = f'setting "{setting}":' if setting else ''
+        raise LookupError(f'{prefix} unknown encoding: "{value}"')
     return value
 
 
@@ -674,9 +676,9 @@
          ('Disable Python tracebacks.  (default)',
           ['--no-traceback'], {'dest': 'traceback', 'action': 'store_false'}),
          ('Specify the encoding and optionally the '
-          'error handler of input text.  Default: <auto-detect>:strict.',
-          ['--input-encoding', '-i'],
-          {'metavar': '<name[:handler]>',
+          'error handler of input text.  Default: utf-8.',
+          ['--input-encoding'],
+          {'metavar': '<name[:handler]>', 'default': 'utf-8',
            'validator': validate_encoding_and_error_handler}),
          ('Specify the error handler for undecodable characters.  '
           'Choices: "strict" (default), "ignore", and "replace".',
@@ -683,8 +685,8 @@
           ['--input-encoding-error-handler'],
           {'default': 'strict', 'validator': validate_encoding_error_handler}),
          ('Specify the text encoding and optionally the error handler for '
-          'output.  Default: utf-8:strict.',
-          ['--output-encoding', '-o'],
+          'output.  Default: utf-8.',
+          ['--output-encoding'],
           {'metavar': '<name[:handler]>', 'default': 'utf-8',
            'validator': validate_encoding_and_error_handler}),
          ('Specify error handler for unencodable output characters; '

Modified: trunk/docutils/test/data/help/docutils.txt
===================================================================
--- trunk/docutils/test/data/help/docutils.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/data/help/docutils.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -57,15 +57,15 @@
 --warnings=<file>       Send the output of system messages to <file>.
 --traceback             Enable Python tracebacks when Docutils is halted.
 --no-traceback          Disable Python tracebacks.  (default)
---input-encoding=<name[:handler]>, -i <name[:handler]>
+--input-encoding=<name[:handler]>
                         Specify the encoding and optionally the error handler
-                        of input text.  Default: <auto-detect>:strict.
+                        of input text.  Default: utf-8.
 --input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
                         Specify the error handler for undecodable characters.
                         Choices: "strict" (default), "ignore", and "replace".
---output-encoding=<name[:handler]>, -o <name[:handler]>
+--output-encoding=<name[:handler]>
                         Specify the text encoding and optionally the error
-                        handler for output.  Default: utf-8:strict.
+                        handler for output.  Default: utf-8.
 --output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
                         Specify error handler for unencodable output
                         characters; "strict" (default), "ignore", "replace",

Modified: trunk/docutils/test/data/help/rst2html.txt
===================================================================
--- trunk/docutils/test/data/help/rst2html.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/data/help/rst2html.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -58,15 +58,15 @@
 --warnings=<file>       Send the output of system messages to <file>.
 --traceback             Enable Python tracebacks when Docutils is halted.
 --no-traceback          Disable Python tracebacks.  (default)
---input-encoding=<name[:handler]>, -i <name[:handler]>
+--input-encoding=<name[:handler]>
                         Specify the encoding and optionally the error handler
-                        of input text.  Default: <auto-detect>:strict.
+                        of input text.  Default: utf-8.
 --input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
                         Specify the error handler for undecodable characters.
                         Choices: "strict" (default), "ignore", and "replace".
---output-encoding=<name[:handler]>, -o <name[:handler]>
+--output-encoding=<name[:handler]>
                         Specify the text encoding and optionally the error
-                        handler for output.  Default: utf-8:strict.
+                        handler for output.  Default: utf-8.
 --output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
                         Specify error handler for unencodable output
                         characters; "strict" (default), "ignore", "replace",

Modified: trunk/docutils/test/data/help/rst2latex.txt
===================================================================
--- trunk/docutils/test/data/help/rst2latex.txt	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/data/help/rst2latex.txt	2024-06-10 14:24:00 UTC (rev 9749)
@@ -58,15 +58,15 @@
 --warnings=<file>       Send the output of system messages to <file>.
 --traceback             Enable Python tracebacks when Docutils is halted.
 --no-traceback          Disable Python tracebacks.  (default)
---input-encoding=<name[:handler]>, -i <name[:handler]>
+--input-encoding=<name[:handler]>
                         Specify the encoding and optionally the error handler
-                        of input text.  Default: <auto-detect>:strict.
+                        of input text.  Default: utf-8.
 --input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
                         Specify the error handler for undecodable characters.
                         Choices: "strict" (default), "ignore", and "replace".
---output-encoding=<name[:handler]>, -o <name[:handler]>
+--output-encoding=<name[:handler]>
                         Specify the text encoding and optionally the error
-                        handler for output.  Default: utf-8:strict.
+                        handler for output.  Default: utf-8.
 --output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
                         Specify error handler for unencodable output
                         characters; "strict" (default), "ignore", "replace",

Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py	2024-06-10 14:24:00 UTC (rev 9749)
@@ -549,32 +549,6 @@
         Grüße
 """],
 [f"""\
-Default encoding: auto-determine (here via BOM).
-
-.. include:: {utf_16_file}
-""",
-"""\
-<document source="test data">
-    <paragraph>
-        Default encoding: auto-determine (here via BOM).
-    <paragraph>
-        Grüße
-"""],
-[f"""\
-Default encoding: auto-determine (via encoding declaration).
-
-.. include:: {latin2}
-""",
-"""\
-<document source="test data">
-    <paragraph>
-        Default encoding: auto-determine (via encoding declaration).
-    <comment xml:space="preserve">
-        -*- encoding: latin2 -*-
-    <paragraph>
-        škoda
-"""],
-[f"""\
 Include file is UTF-16-encoded, and is not valid ASCII.
 
 .. include:: {utf_16_file}

Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py	2024-06-10 14:24:00 UTC (rev 9749)
@@ -126,19 +126,6 @@
         Grüße
 """],
 [f"""\
-Default encoding: auto-determine (here via BOM).
-
-.. raw:: html
-   :file: {utf_16_file}
-""",
-f"""\
-<document source="test data">
-    <paragraph>
-        Default encoding: auto-determine (here via BOM).
-    <raw format="html" source="{utf_16_file}" xml:space="preserve">
-        Grüße
-"""],
-[f"""\
 Raw input file is UTF-16-encoded, and is not valid ASCII.
 
 .. raw:: html

Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py	2024-06-10 14:24:00 UTC (rev 9749)
@@ -1198,64 +1198,6 @@
                             \u00bfOn a \u03c3\u03c4\u03b9\u03ba?
 """],
 ["""\
-.. csv-table:: auto encoding
-   :file: %s
-   :header-rows: 1
-""" % utf_16_csv,
-"""\
-<document source="test data">
-    <table>
-        <title>
-            auto encoding
-        <tgroup cols="3">
-            <colspec colwidth="33">
-            <colspec colwidth="33">
-            <colspec colwidth="33">
-            <thead>
-                <row>
-                    <entry>
-                        <paragraph>
-                            Treat
-                    <entry>
-                        <paragraph>
-                            Quantity
-                    <entry>
-                        <paragraph>
-                            Description
-            <tbody>
-                <row>
-                    <entry>
-                        <paragraph>
-                            Albatr\u00b0\u00df
-                    <entry>
-                        <paragraph>
-                            2.99
-                    <entry>
-                        <paragraph>
-                            \u00a1On a \u03c3\u03c4\u03b9\u03ba!
-                <row>
-                    <entry>
-                        <paragraph>
-                            Crunchy Frog
-                    <entry>
-                        <paragraph>
-                            1.49
-                    <entry>
-                        <paragraph>
-                            If we took the b\u00f6nes out, it wouldn\u2019t be
-                            crunchy, now would it?
-                <row>
-                    <entry>
-                        <paragraph>
-                            Gannet Ripple
-                    <entry>
-                        <paragraph>
-                            1.99
-                    <entry>
-                        <paragraph>
-                            \u00bfOn a \u03c3\u03c4\u03b9\u03ba?
-"""],
-["""\
 .. csv-table:: no CSV data
    :file: %s
 """ % empty_txt,

Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py	2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_publisher.py	2024-06-10 14:24:00 UTC (rev 9749)
@@ -105,22 +105,23 @@
     def test_publish_string_input_encoding(self):
         """Test handling of encoded input."""
         # Transparently decode `bytes` source (with "input_encoding" setting)
-        # default: auto-detect, fallback utf-8
+        # default: utf-8
         # Output is encoded according to "output_encoding" setting.
-        settings = dict(self.settings)
+        settings = self.settings | {'input_encoding': 'utf-16',
+                                    'output_encoding': 'unicode'}
         source = 'test → me'
         expected = ('<document source="<string>">\n'
                     '    <paragraph>\n'
-                    '        test → me\n').encode('utf-8')
+                    '        test → me\n')
         output = core.publish_string(source.encode('utf-16'),
                                      settings_overrides=settings)
         self.assertEqual(expected, output)
 
-        # encoding declaration in source
+        # encoding declaration in source (used if input_encoding is None)
+        # input encoding detection will be removed in Docutils 1.0
         source = '.. encoding: latin1\n\nGrüße'
-        # don't encode output (return `str`)
-        settings['output_encoding'] = 'unicode'
-        output = core.publish_string(source.encode('utf-16'),
+        settings['input_encoding'] = None
+        output = core.publish_string(source.encode('latin1'),
                                      settings_overrides=settings)
         self.assertTrue(output.endswith('Grüße\n'))
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins
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.