diff options
| author | Benjamin Peterson <benjamin@python.org> | 2012-04-24 11:09:20 -0400 |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2012-04-24 11:09:20 -0400 |
| commit | 53d09b53993c6fd90307bbe842bccb40dcb03e43 (patch) | |
| tree | eab386f41260d464b00eadb79181216fa6261faa /Python/freeze_importlib.py | |
| parent | f73861a9f1b07296436badc29cb67c38f5e9c462 (diff) | |
| parent | 4fd25873791e766eb60314d42bd6b292b4a6d221 (diff) | |
| download | cpython-53d09b53993c6fd90307bbe842bccb40dcb03e43.tar.gz | |
merge 3.2 (#14658)
Diffstat (limited to 'Python/freeze_importlib.py')
| -rw-r--r-- | Python/freeze_importlib.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Python/freeze_importlib.py b/Python/freeze_importlib.py new file mode 100644 index 0000000000..c012722a42 --- /dev/null +++ b/Python/freeze_importlib.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python +"""Freeze importlib for use as the implementation of import.""" +import marshal + + +header = """/* Auto-generated by Python/freeze_importlib.py */""" + + +def main(input_path, output_path): + with open(input_path, 'r', encoding='utf-8') as input_file: + source = input_file.read() + + code = compile(source, '<frozen importlib._bootstrap>', 'exec') + + lines = [header] + lines.append('unsigned char _Py_M__importlib[] = {') + data = marshal.dumps(code) + # Code from Tools/freeze/makefreeze.py:writecode() + for i in range(0, len(data), 16): + line = [' '] + for c in data[i:i+16]: + line.append('%d,' % c) + lines.append(''.join(line)) + lines.append('};\n') + with open(output_path, 'w', encoding='utf-8') as output_file: + output_file.write('\n'.join(lines)) + output_file.write('/* Mercurial binary marker: \x00 */') + + +if __name__ == '__main__': + import sys + + args = sys.argv[1:] + if len(args) != 2: + print('Need to specify input and output file paths', file=sys.stderr) + sys.exit(1) + + main(*args) |
