Skip to content

Commit edb85b6

Browse files
committed
Open profile scripts in binary mode
Pass the raw bytes to exec() so the compiler applies the source file's encoding declaration, instead of detecting it with tokenize.open().
1 parent 4c0bd4f commit edb85b6

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

Lib/tkinter/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,6 @@ def readprofile(self, baseName, className):
27392739
the Tcl Interpreter and calls exec on the contents of .BASENAME.py and
27402740
.CLASSNAME.py if such a file exists in the home directory."""
27412741
import os
2742-
import tokenize
27432742
if 'HOME' in os.environ: home = os.environ['HOME']
27442743
else: home = os.curdir
27452744
class_tcl = os.path.join(home, '.%s.tcl' % className)
@@ -2751,12 +2750,12 @@ def readprofile(self, baseName, className):
27512750
if os.path.isfile(class_tcl):
27522751
self.tk.call('source', class_tcl)
27532752
if os.path.isfile(class_py):
2754-
with tokenize.open(class_py) as f:
2753+
with open(class_py, 'rb') as f:
27552754
exec(f.read(), dir)
27562755
if os.path.isfile(base_tcl):
27572756
self.tk.call('source', base_tcl)
27582757
if os.path.isfile(base_py):
2759-
with tokenize.open(base_py) as f:
2758+
with open(base_py, 'rb') as f:
27602759
exec(f.read(), dir)
27612760

27622761
def report_callback_exception(self, exc, val, tb):
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
The ``readprofile`` method of :class:`tkinter.Tk` now reads the user's
2-
profile scripts using :func:`tokenize.open`.
2+
profile scripts using the encoding declared in the file, instead of the
3+
locale encoding.

0 commit comments

Comments
 (0)