]> granicus.if.org Git - python/commitdiff
Issue #4282: Fix the main function of the profile module for a non-ASCII
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 22 Mar 2010 01:58:35 +0000 (01:58 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 22 Mar 2010 01:58:35 +0000 (01:58 +0000)
script, open the file in binary mode and not in text mode with the default
(utf8) encoding.

Lib/profile.py
Misc/NEWS

index a09fffea430c5a04935b58086beb58e5fcdc5ad7..8d68d17cbe65b6e6d2ffbcd24e7e74ef3e74219b 100755 (executable)
@@ -602,11 +602,8 @@ def main():
     if (len(args) > 0):
         sys.argv[:] = args
         sys.path.insert(0, os.path.dirname(sys.argv[0]))
-        fp = open(sys.argv[0])
-        try:
+        with open(sys.argv[0], 'rb') as fp:
             script = fp.read()
-        finally:
-            fp.close()
         run('exec(%r)' % script, options.outfile, options.sort)
     else:
         parser.print_usage()
index c287e0c2916e249366932ab193755cd44a914c39..cfe45fb666190f77c5a2e79d152a8ca188e3238d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -285,6 +285,10 @@ C-API
 Library
 -------
 
+- Issue #4282: Fix the main function of the profile module for a non-ASCII
+  script, open the file in binary mode and not in text mode with the default
+  (utf8) encoding.
+
 - Issue #8179: Fix macpath.realpath() on a non-existing path.
 
 - Issue #8024: Update the Unicode database to 5.2.