Update Mako-1.1.5

This commit is contained in:
JonnyWong16 2021-10-14 21:46:34 -07:00
parent 4eb0fea423
commit 668f6bfbb8
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 28 additions and 12 deletions

View file

@ -5,4 +5,4 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
__version__ = '1.1.2'
__version__ = "1.1.5"

View file

@ -99,11 +99,20 @@ else:
if py3k:
from importlib import machinery
def load_module(module_id, path):
return machinery.SourceFileLoader(module_id, path).load_module()
from importlib import machinery, util
if hasattr(util, 'module_from_spec'):
# Python 3.5+
def load_module(module_id, path):
spec = util.spec_from_file_location(module_id, path)
module = util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
else:
def load_module(module_id, path):
module = machinery.SourceFileLoader(module_id, path).load_module()
del sys.modules[module_id]
return module
else:
import imp
@ -111,7 +120,9 @@ else:
def load_module(module_id, path):
fp = open(path, "rb")
try:
return imp.load_source(module_id, path, fp)
module = imp.load_source(module_id, path, fp)
del sys.modules[module_id]
return module
finally:
fp.close()

View file

@ -27,7 +27,15 @@ class LinguaMakoExtractor(Extractor, MessageExtractor):
self.python_extractor = get_extractor("x.py")
if fileobj is None:
fileobj = open(filename, "rb")
return self.process_file(fileobj)
must_close = True
else:
must_close = False
try:
for message in self.process_file(fileobj):
yield message
finally:
if must_close:
fileobj.close()
def process_python(self, code, code_lineno, translator_strings):
source = code.getvalue().strip()

View file

@ -201,7 +201,7 @@ class Lexer(object):
"""
if isinstance(text, compat.text_type):
m = self._coding_re.match(text)
encoding = m and m.group(1) or known_encoding or "ascii"
encoding = m and m.group(1) or known_encoding or "utf-8"
return encoding, text
if text.startswith(codecs.BOM_UTF8):
@ -222,7 +222,7 @@ class Lexer(object):
if m:
parsed_encoding = m.group(1)
else:
parsed_encoding = known_encoding or "ascii"
parsed_encoding = known_encoding or "utf-8"
if decode_raw:
try:

View file

@ -12,7 +12,6 @@ import os
import re
import shutil
import stat
import sys
import tempfile
import types
import weakref
@ -414,14 +413,12 @@ class Template(object):
self, data, filename, path, self.module_writer
)
module = compat.load_module(self.module_id, path)
del sys.modules[self.module_id]
if module._magic_number != codegen.MAGIC_NUMBER:
data = util.read_file(filename)
_compile_module_file(
self, data, filename, path, self.module_writer
)
module = compat.load_module(self.module_id, path)
del sys.modules[self.module_id]
ModuleInfo(module, path, self, filename, None, None, None)
else:
# template filename and no module directory, compile code