diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-12-02 23:07:33 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-12-02 23:07:33 +0000 |
commit | 3e13d7f352d386507f11cbacae27e27c29da9aac (patch) | |
tree | 362815ef34bf33611b3c70593efe6fc21d0c7858 | |
parent | b020c76a6954fec5f093cdcd2c1991c2485cec04 (diff) | |
download | docutils-3e13d7f352d386507f11cbacae27e27c29da9aac.tar.gz |
Allow empty string as encoding value (to re-activate default).
Value `None` cannot be specified on the command line.
Use ``--input-encoding=""`` go back to Docutil's default behaviur
(use encoding indicated in the file or fallbacks)
if a config file sets "input_encoding" to another value.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9303 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | docutils/docutils/frontend.py | 2 | ||||
-rwxr-xr-x | docutils/test/test_io.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/docutils/docutils/frontend.py b/docutils/docutils/frontend.py index 2f4ca405f..62769aa30 100644 --- a/docutils/docutils/frontend.py +++ b/docutils/docutils/frontend.py @@ -92,6 +92,8 @@ def read_config_file(option, opt, value, parser): def validate_encoding(setting, value, option_parser, config_parser=None, config_section=None): + if value == '': + return None # allow overwriting a config file value try: codecs.lookup(value) except LookupError: diff --git a/docutils/test/test_io.py b/docutils/test/test_io.py index f545ab923..17b77eaa1 100755 --- a/docutils/test/test_io.py +++ b/docutils/test/test_io.py @@ -70,8 +70,9 @@ class HelperTests(unittest.TestCase): self.assertEqual(io.check_encoding(io.FileInput(), 'ascii'), None) # stream.encoding does not exist: self.assertEqual(io.check_encoding(BBuf, 'ascii'), None) - # encoding is None: + # encoding is None or empty string: self.assertEqual(io.check_encoding(mock_stdout, None), None) + self.assertEqual(io.check_encoding(mock_stdout, ''), None) # encoding is invalid self.assertEqual(io.check_encoding(mock_stdout, 'UTF-9'), None) @@ -142,6 +143,7 @@ print("hello world") 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': + # Provisional: the second fallback 'latin-1' will be dropped probed_encodings = (io._locale_encoding, 'latin-1') # noqa input = io.FileInput( source_path=os.path.join(DATA_ROOT, 'latin1.txt')) |