mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
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.
This commit is contained in:
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
import sys
|
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):
|
def main(infile):
|
||||||
conv = ['\\' + ("%03o" % c) for c in range(256)]
|
conv = ['\\' + ("%03o" % c) for c in range(256)]
|
||||||
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
|
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
|
||||||
@@ -16,7 +20,7 @@ def main(infile):
|
|||||||
for c, esc in ("\nn", "\tt", r"\\", '""'):
|
for c, esc in ("\nn", "\tt", r"\\", '""'):
|
||||||
conv[ord(c)] = '\\' + esc
|
conv[ord(c)] = '\\' + esc
|
||||||
for line in infile:
|
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:
|
with open(sys.argv[1], 'rb') as infile:
|
||||||
sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])
|
sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ Can also be used to directly parse Matroska files and display their contents.
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# for compatibility with Python 2.x
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
elements_ebml = (
|
elements_ebml = (
|
||||||
'EBML, 1a45dfa3, sub', (
|
'EBML, 1a45dfa3, sub', (
|
||||||
|
|||||||
Reference in New Issue
Block a user