mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-153319: Read turtledemo scripts with the source file's own encoding (#153321)
The demo viewer read each script with open() and no encoding argument, i.e. the locale default encoding. That emits an EncodingWarning under -X warn_default_encoding and can mis-decode a script on a non-UTF-8 locale. Read the source with tokenize.open() instead, which decodes using the encoding detected from the file (its coding cookie, else UTF-8), matching how Python read the module when it was imported just above. * gh-153319: Read turtledemo scripts as UTF-8 Per review, open the demo scripts with encoding='utf-8' instead of tokenize.open(); the scripts are UTF-8. --------- Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
2 files changed
+3
-1
No files matched your search
@@ -333,7 +333,7 @@ class DemoWindow(object):
|
||||
modname = 'turtledemo.' + filename
|
||||
__import__(modname)
|
||||
self.module = sys.modules[modname]
|
||||
with open(self.module.__file__, 'r') as f:
|
||||
with open(self.module.__file__, encoding='utf-8') as f:
|
||||
chars = f.read()
|
||||
self.text.delete("1.0", "end")
|
||||
self.text.insert("1.0", chars)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
The :mod:`turtledemo` viewer now reads each demo script as UTF-8 instead of
|
||||
the locale encoding.
|
||||
Reference in new issue
Block a user