Author vstinner
Recipients eric.araujo, nils, tarek, vstinner, zegreek
Date 2010-11-09.00:59:19
SpamBayes Score 4.38538e-15
Marked as misclassified No
Message-id <1289264366.83.0.851365085265.issue6011@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-11-09 00:59:27vstinnersetrecipients: + vstinner, tarek, eric.araujo, zegreek, nils
2010-11-09 00:59:26vstinnersetmessageid: <1289264366.83.0.851365085265.issue6011@psf.upfronthosting.co.za>
2010-11-09 00:59:23vstinnerlinkissue6011 messages
2010-11-09 00:59:22vstinnercreate