summaryrefslogtreecommitdiffstats
path: root/TOOLS/file2string.py
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-29 15:53:54 +0200
committerwm4 <wm4@nowhere>2012-09-29 15:53:54 +0200
commit0ee09dcdbecc115531ee4fbfa534bcb654b5cbf6 (patch)
tree7f2d310394b056b3c9bc8974e4308e8b8a7b607e /TOOLS/file2string.py
parent327a5d0ecf33dd44e5542f9128a26d7659864a79 (diff)
downloadmpv-0ee09dcdbecc115531ee4fbfa534bcb654b5cbf6.tar.bz2
mpv-0ee09dcdbecc115531ee4fbfa534bcb654b5cbf6.tar.xz
build: make Python scripts compatible with Python 2.x
They were originally written for Python 3.x. Changing them to work on Python 2.x as well is trivial. Tested with Python 2.7.3 and 3.2.3.
Diffstat (limited to 'TOOLS/file2string.py')
-rwxr-xr-xTOOLS/file2string.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py
index cb121e4884..35c89cb731 100755
--- a/TOOLS/file2string.py
+++ b/TOOLS/file2string.py
@@ -7,6 +7,10 @@
import sys
+# Indexing a byte string yields int on Python 3.x, and a str on Python 2.x
+def pord(c):
+ return ord(c) if type(c) == str else c
+
def main(infile):
conv = ['\\' + ("%03o" % c) for c in range(256)]
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
@@ -16,7 +20,7 @@ def main(infile):
for c, esc in ("\nn", "\tt", r"\\", '""'):
conv[ord(c)] = '\\' + esc
for line in infile:
- sys.stdout.write('"' + ''.join(conv[c] for c in line) + '"\n')
+ sys.stdout.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n')
with open(sys.argv[1], 'rb') as infile:
sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])