From: Armin Ronacher Date: Sun, 14 Mar 2010 23:54:01 +0000 (+0100) Subject: Template to module compilation should work on 3.x now. X-Git-Tag: 2.4~15 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c57959d46b5847a170c23fef4000aa71d4af023f;p=jinja2.git Template to module compilation should work on 3.x now. --HG-- branch : trunk --- diff --git a/jinja2/environment.py b/jinja2/environment.py index b70f521..a250185 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -532,15 +532,16 @@ class Environment(object): if py_compile: import imp, struct, marshal - py_header = imp.get_magic() + '\xff\xff\xff\xff' + py_header = imp.get_magic() + \ + u'\xff\xff\xff\xff'.encode('iso-8859-15') - def write_file(filename, data): + def write_file(filename, data, mode): if zip: info = ZipInfo(filename) info.external_attr = 0755 << 16L zip_file.writestr(info, data) else: - f = open(os.path.join(target, filename), 'wb') + f = open(os.path.join(target, filename), mode) try: f.write(data) finally: @@ -571,11 +572,12 @@ class Environment(object): if py_compile: c = compile(code, _encode_filename(filename), 'exec') - write_file(filename + 'c', py_header + marshal.dumps(c)) + write_file(filename + 'c', py_header + + marshal.dumps(c), 'wb') log_function('Byte-compiled "%s" as %s' % (name, filename + 'c')) else: - write_file(filename, code) + write_file(filename, code, 'w') log_function('Compiled "%s" as %s' % (name, filename)) finally: if zip: