STINNER Victor <victor.stin...@haypocalc.com> added the comment:

Now I get an error in copy_scripts() function of 
Lib/distutils/command/build_scripts.py: this function adjusts Python shebang of 
installed Python scripts. The problem is that the shebang contains a non-ASCII 
character whereas the script is written into the locale encoding, which is 
ASCII in my test.

test_httpservers has a similar issue: CGIHTTPServerTestCase fails if the Python 
executable full path is not encodable to utf-8. I fixed simply this issue by 
skipping the test:

    try:
        # The python executable path is written as the first line of the
        # CGI Python script. The encoding cookie cannot be used, and so the
        # path should be encodable to the default script encoding (utf-8)
        self.pythonexe.encode('utf-8')
    except UnicodeEncodeError:
        self.tearDown()
        raise self.skipTest(
            "Python executable path is not encodable to utf-8")

--

Attached patch, copy_script.patch, fixes this issue by reading the Python 
script in binary mode. It ensures that the shebang is decodable from utf-8 and 
the script encoding.

It checks with utf-8 because the shebang is always written before the encoding 
cookie, and so the parser reads the shebang with the default parser encoding, 
which is utf-8. Eg. with a shebang not decodable from utf-8:
---
  File "./test.py", line 1
SyntaxError: Non-UTF-8 code starting with '\xff' in file ./blo.py on line 1, 
but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
---

It checks with the script encoding because when the parser hits the encoding 
cookie, it restarts to read the whole file with the encoding, and so the parser 
decodes the shebang from the script encoding.

----------
Added file: http://bugs.python.org/file19551/copy_script.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6011>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to