summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-09-25 21:13:17 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-09-25 21:13:17 (GMT)
commit0e33da095f39ad18791cb4457dca868a74d84e72 (patch)
tree3329921cb0b7bb8912ed8b73cd3fbb88c8898b36 /Tools/scripts
parentae1b4d2d1aaedfab8c2121a2652b5fb89b634443 (diff)
downloadcpython-0e33da095f39ad18791cb4457dca868a74d84e72.zip
cpython-0e33da095f39ad18791cb4457dca868a74d84e72.tar.gz
cpython-0e33da095f39ad18791cb4457dca868a74d84e72.tar.bz2
Merged revisions 75061-75062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r75061 | benjamin.peterson | 2009-09-25 15:34:04 -0500 (Fri, 25 Sep 2009) | 1 line fix print statement ........ r75062 | benjamin.peterson | 2009-09-25 15:56:52 -0500 (Fri, 25 Sep 2009) | 2 lines correct the fixpath.py script to work in Python 3 #6999 ........
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-xTools/scripts/pathfix.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py
index 601a172..6cbac10 100755
--- a/Tools/scripts/pathfix.py
+++ b/Tools/scripts/pathfix.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#!/usr/bin/env python3
# Change the #! line occurring in Python scripts. The new interpreter
# pathname must be given with a -i option.
@@ -43,8 +43,9 @@ def main():
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 not new_interpreter.startswith(b'/') or \
+ not args:
err('-i option or file-or-directory missing\n')
err(usage)
sys.exit(2)
@@ -61,7 +62,7 @@ def main():
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 +89,7 @@ def recursedown(dirname):
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 +102,7 @@ def fix(filename):
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 +140,11 @@ def fix(filename):
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()