Skip to content

Commit 58e1498

Browse files
author
Christopher Doris
committed
code is now escaped instead of base64 [skip ci]
1 parent adc3a2d commit 58e1498

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pysrc/juliacall/importer.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,24 @@ def uninstall(finder):
3636
sys.meta_path.remove(finder)
3737

3838
def gen_code(jl):
39-
jlb = base64.b64encode(jl.encode('utf8')).decode('ascii')
4039
buf = io.StringIO()
4140
pr = lambda x: print(x, file=buf)
41+
jl2 = jl.replace('\\', '\\\\').replace("'", "\\'")
4242
pr('# This file was automatically generated by juliacall.importer')
4343
pr('import juliacall.importer')
44-
pr('juliacall.importer.exec_module(__name__, """')
45-
for i in range(0, len(jlb), 80):
46-
pr(jlb[i:i+80])
47-
pr('""")')
44+
pr('juliacall.importer.exec_module(__name__,')
45+
pr("'''"+jl2+"''')")
4846
return buf.getvalue()
4947

5048
def gen_file(jl, py):
51-
with open(jl) as fp:
49+
with open(jl, encoding='utf-8') as fp:
5250
jlcode = fp.read()
5351
pycode = gen_code(jlcode)
54-
with open(py, 'w') as fp:
52+
with open(py, 'w', encoding='utf-8') as fp:
5553
fp.write(pycode)
5654

5755
def exec_module(name, code):
5856
pymod = sys.modules[name]
59-
code = base64.b64decode(code.encode('ascii')).decode('utf8')
6057
jlmod = newmodule(name)
6158
jlmod.seval('begin\n' + code + '\nend')
6259
delattr(pymod, 'juliacall')

0 commit comments

Comments
 (0)