|
From: <mi...@us...> - 2022-06-15 11:31:11
|
Revision: 9072
http://sourceforge.net/p/docutils/code/9072
Author: milde
Date: 2022-06-15 11:31:09 +0000 (Wed, 15 Jun 2022)
Log Message:
-----------
Add encoding arguments when opening files.
Specify intended incoding, when possible.
Avoids `EncodingWarning` in PEP 597 and nasty surprises
if the default encoding is not what the user expects.
Keep encoding unspecified where this may be an API change.
Based on patch by Adam Turner.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/user/slide-shows.txt
trunk/docutils/docutils/statemachine.py
trunk/docutils/docutils/writers/odf_odt/__init__.py
trunk/docutils/docutils/writers/s5_html/__init__.py
trunk/docutils/test/alltests.py
trunk/docutils/test/functional/tests/footnotes_html5.py
trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py
trunk/docutils/test/functional/tests/standalone_rst_html4css1.py
trunk/docutils/test/functional/tests/standalone_rst_html5.py
trunk/docutils/test/functional/tests/standalone_rst_latex.py
trunk/docutils/test/functional/tests/standalone_rst_manpage.py
trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py
trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py
trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py
trunk/docutils/test/functional/tests/standalone_rst_xetex.py
trunk/docutils/test/test_CLI.py
trunk/docutils/test/test_functional.py
trunk/docutils/tools/dev/unicode2rstsubs.py
trunk/docutils/tools/test/test_buildhtml.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/HISTORY.txt 2022-06-15 11:31:09 UTC (rev 9072)
@@ -105,6 +105,10 @@
__ https://packaging.python.org/en/latest/specifications/entry-points/
+* test/alltests.py
+
+ - Always encode the log file "alltests.out" using 'utf-8'.
+
* test/DocutilsTestSupport.py
- `exception_data()` now returns None if no exception was raised.
Modified: trunk/docutils/docs/user/slide-shows.txt
===================================================================
--- trunk/docutils/docs/user/slide-shows.txt 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/docs/user/slide-shows.txt 2022-06-15 11:31:09 UTC (rev 9072)
@@ -474,11 +474,6 @@
.. container:: handout
- Themes from the `S5 tutorial`__ can be used. These themes are in
- the public domain and may be redistributed freely.
-
- __ http://meyerweb.com/eric/tools/s5/s5blank.zip
-
Sites with other S5 themes:
* http://meyerweb.com/eric/tools/s5/themes/
@@ -485,8 +480,8 @@
* http://mozilla.wikicities.com/wiki/Firefox_S5:Designs
* http://lachy.id.au/dev/mozilla/firefox/s5/
* http://www.openlight.com/Python-S5-Theme.tar.gz
-
- S5 is becoming more popular every day. Do a web search for "S5
+
+ Do a web search for "S5
theme" and you're bound to find plenty of choices.
* "``--theme``" option.
@@ -659,7 +654,7 @@
2. Copy ``ui/<base-theme>`` to ``ui/<new-theme>``.
-3. Edit the styles.
+3. Edit the styles (save in UTF-8 encoding).
.. class:: handout
Modified: trunk/docutils/docutils/statemachine.py
===================================================================
--- trunk/docutils/docutils/statemachine.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/docutils/statemachine.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -92,7 +92,8 @@
one-line strings. For example, to read text from a file called
'inputfile'::
- input_string = open('inputfile').read()
+ with open('inputfile', encoding='utf-8') as fp:
+ input_string = fp.read()
input_lines = statemachine.string2lines(input_string)
5. Run the state machine on the input text and collect the results, a list::
Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -936,7 +936,7 @@
stylespath = self.settings.stylesheet
ext = os.path.splitext(stylespath)[1]
if ext == '.xml':
- with open(stylespath, 'r') as stylesfile:
+ with open(stylespath, 'r', encoding='utf-8') as stylesfile:
s1 = stylesfile.read()
elif ext == extension:
zfile = zipfile.ZipFile(stylespath, 'r')
Modified: trunk/docutils/docutils/writers/s5_html/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/s5_html/__init__.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/docutils/writers/s5_html/__init__.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -216,7 +216,7 @@
base_theme_file = os.path.join(path, self.base_theme_file)
# If it exists, read it and record the theme path:
if os.path.isfile(base_theme_file):
- with open(base_theme_file) as f:
+ with open(base_theme_file, encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
line = line.strip()
Modified: trunk/docutils/test/alltests.py
===================================================================
--- trunk/docutils/test/alltests.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/alltests.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -30,7 +30,8 @@
"""Write to a file and a stream (default: stdout) simultaneously."""
def __init__(self, filename, stream=sys.__stdout__):
- self.file = open(filename, 'w', errors='backslashreplace')
+ self.file = open(filename, 'w', encoding='utf-8',
+ errors='backslashreplace')
atexit.register(self.close)
self.stream = stream
self.encoding = getattr(stream, 'encoding', None)
Modified: trunk/docutils/test/functional/tests/footnotes_html5.py
===================================================================
--- trunk/docutils/test/functional/tests/footnotes_html5.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/footnotes_html5.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_html4css1.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_html4css1.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_html5.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_html5.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_html5.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_latex.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_latex.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_latex.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_manpage.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_manpage.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_manpage.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,7 +1,8 @@
import filecmp as _filecmp
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names:
Modified: trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,5 +1,6 @@
# initialize with the settings & definitions from test 1:
-with open('functional/tests/standalone_rst_s5_html_1.py') as _f:
+with open('functional/tests/standalone_rst_s5_html_1.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# overrides specific to this test:
Modified: trunk/docutils/test/functional/tests/standalone_rst_xetex.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_xetex.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/functional/tests/standalone_rst_xetex.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -1,4 +1,5 @@
-with open('functional/tests/_standalone_rst_defaults.py') as _f:
+with open('functional/tests/_standalone_rst_defaults.py',
+ encoding='utf-8') as _f:
exec(_f.read())
# Source and destination file names.
Modified: trunk/docutils/test/test_CLI.py
===================================================================
--- trunk/docutils/test/test_CLI.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/test_CLI.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -67,7 +67,7 @@
f'{frontend.OptionParser.default_error_encoding}:backslashreplace',
'utf-8:backslashreplace')
# compare to stored version
- with open('data/help/docutils.txt') as samplefile:
+ with open('data/help/docutils.txt', encoding='utf-8') as samplefile:
expected = samplefile.read()
if expected != output:
print_mismatch(expected, output)
Modified: trunk/docutils/test/test_functional.py
===================================================================
--- trunk/docutils/test/test_functional.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/test/test_functional.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -117,10 +117,11 @@
namespace['settings_overrides'] = {'_disable_config': True}
# Read the variables set in the default config file and in
# the current config file into namespace:
- with open(join_path(datadir, 'tests', '_default.py')) as f:
+ with open(join_path(datadir, 'tests', '_default.py'),
+ encoding='utf-8') as f:
defaultpy = f.read()
exec(defaultpy, namespace)
- with open(self.configfile) as f:
+ with open(self.configfile, encoding='utf-8') as f:
exec(f.read(), namespace)
# Check for required settings:
assert 'test_source' in namespace,\
Modified: trunk/docutils/tools/dev/unicode2rstsubs.py
===================================================================
--- trunk/docutils/tools/dev/unicode2rstsubs.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/tools/dev/unicode2rstsubs.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -169,7 +169,7 @@
outname = set_name + '-wide.txt'
else:
outname = set_name + '.txt'
- outfile = open(outname, 'w')
+ outfile = open(outname, 'w', encoding='ascii')
print('writing file "%s"' % outname)
outfile.write(self.header + '\n')
set = self.sets[set_name]
Modified: trunk/docutils/tools/test/test_buildhtml.py
===================================================================
--- trunk/docutils/tools/test/test_buildhtml.py 2022-06-14 16:09:29 UTC (rev 9071)
+++ trunk/docutils/tools/test/test_buildhtml.py 2022-06-15 11:31:09 UTC (rev 9072)
@@ -81,7 +81,7 @@
if "." not in s:
os.mkdir(s)
else:
- fd_s = open(s, "w")
+ fd_s = open(s, "w", encoding='utf-8')
fd_s.write("dummy")
fd_s.close()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|