Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r59259:0e46137d618b
Date: 2012-12-02 14:55 +0100
http://bitbucket.org/pypy/pypy/changeset/0e46137d618b/

Log:    Only search encoding for Python source files. Binary files may not
        be opened with an "encoding" parameter...

diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -73,14 +73,15 @@
     stream = find_info.stream
 
     if stream is not None:
-        # try to find the declared encoding
         encoding = None
-        firstline = stream.readline()
-        stream.seek(0, 0) # reset position
-        if firstline.startswith('#'):
-            encoding = pytokenizer.match_encoding_declaration(firstline)
-        if encoding is None:
-            encoding = unicodetype.getdefaultencoding(space)
+        if find_info.modtype == importing.PY_SOURCE:
+            # try to find the declared encoding
+            firstline = stream.readline()
+            stream.seek(0, 0) # reset position
+            if firstline.startswith('#'):
+                encoding = pytokenizer.match_encoding_declaration(firstline)
+            if encoding is None:
+                encoding = unicodetype.getdefaultencoding(space)
         #
         # in python2, both CPython and PyPy pass the filename to
         # open(). However, CPython 3 just passes the fd, so the returned file
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to