summaryrefslogtreecommitdiff
path: root/tools/js2c.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/js2c.py')
-rwxr-xr-xtools/js2c.py15
1 files changed, 4 insertions, 11 deletions
diff --git a/tools/js2c.py b/tools/js2c.py
index d7d0c710b1..86648f785c 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -34,17 +34,10 @@
import os
import re
import sys
-import string
-import hashlib
-
-try:
- xrange # Python 2
-except NameError:
- xrange = range # Python 3
def ToCArray(elements, step=10):
- slices = (elements[i:i+step] for i in xrange(0, len(elements), step))
+ slices = (elements[i:i+step] for i in range(0, len(elements), step))
slices = map(lambda s: ','.join(str(x) for x in s), slices)
return ',\n'.join(slices)
@@ -160,14 +153,14 @@ def ReadMacros(lines):
macro_match = MACRO_PATTERN.match(line)
if macro_match:
name = macro_match.group(1)
- args = map(string.strip, macro_match.group(2).split(','))
+ args = [s.strip() for s in macro_match.group(2).split(',')]
body = macro_match.group(3).strip()
macros[name] = TextMacro(args, body)
else:
python_match = PYTHON_MACRO_PATTERN.match(line)
if python_match:
name = python_match.group(1)
- args = map(string.strip, python_match.group(2).split(','))
+ args = [s.strip() for s in python_match.group(2).split(',')]
body = python_match.group(3).strip()
fun = eval("lambda " + ",".join(args) + ': ' + body)
macros[name] = PythonMacro(args, fun)
@@ -238,7 +231,7 @@ def JS2C(source, target):
# Treat non-ASCII as UTF-8 and convert it to UTF-16.
if any(ord(c) > 127 for c in source):
source = map(ord, source.decode('utf-8').encode('utf-16be'))
- source = [source[i] * 256 + source[i+1] for i in xrange(0, len(source), 2)]
+ source = [source[i] * 256 + source[i+1] for i in range(0, len(source), 2)]
source = ToCArray(source)
return TWO_BYTE_STRING.format(var=var, data=source)
else: