python3.12/python-3.1.1-pathfix.patch
2010-01-13 21:25:18 +00:00

62 lines
1.9 KiB
Diff

--- Python-3.1.1.orig/Tools/scripts/pathfix.py 2009-09-24 15:27:04.000000000 -0600
+++ Python-3.1.1/Tools/scripts/pathfix.py 2009-09-25 14:05:04.000000000 -0600
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#!/usr/bin/env python3.1
# Change the #! line occurring in Python scripts. The new interpreter
# pathname must be given with a -i option.
@@ -43,8 +43,8 @@
sys.exit(2)
for o, a in opts:
if o == '-i':
- new_interpreter = a
- if not new_interpreter or new_interpreter[0] != '/' or not args:
+ new_interpreter = a.encode()
+ if not new_interpreter or new_interpreter[0] != b'/'[0] or not args:
err('-i option or file-or-directory missing\n')
err(usage)
sys.exit(2)
@@ -61,7 +61,7 @@
ispythonprog = re.compile('^[a-zA-Z0-9_]+\.py$')
def ispython(name):
- return ispythonprog.match(name) >= 0
+ return bool(ispythonprog.match(name))
def recursedown(dirname):
dbg('recursedown(%r)\n' % (dirname,))
@@ -88,7 +88,7 @@
def fix(filename):
## dbg('fix(%r)\n' % (filename,))
try:
- f = open(filename, 'r')
+ f = open(filename, 'rb')
except IOError as msg:
err('%s: cannot open: %r\n' % (filename, msg))
return 1
@@ -101,7 +101,7 @@
head, tail = os.path.split(filename)
tempname = os.path.join(head, '@' + tail)
try:
- g = open(tempname, 'w')
+ g = open(tempname, 'wb')
except IOError as msg:
f.close()
err('%s: cannot create: %r\n' % (tempname, msg))
@@ -139,11 +139,11 @@
return 0
def fixline(line):
- if not line.startswith('#!'):
+ if not line.startswith(b'#!'):
return line
- if "python" not in line:
+ if b"python" not in line:
return line
- return '#! %s\n' % new_interpreter
+ return b'#!' + new_interpreter + b'\n'
if __name__ == '__main__':
main()