torsava / rpms / python3

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