diff --git a/lib/mako/__init__.py b/lib/mako/__init__.py index 5ae55011..3d7dcb6d 100644 --- a/lib/mako/__init__.py +++ b/lib/mako/__init__.py @@ -1,8 +1,8 @@ # mako/__init__.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -__version__ = "1.2.0" +__version__ = "1.2.3" diff --git a/lib/mako/_ast_util.py b/lib/mako/_ast_util.py index b8615335..95742835 100644 --- a/lib/mako/_ast_util.py +++ b/lib/mako/_ast_util.py @@ -1,5 +1,5 @@ # mako/_ast_util.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ast.py b/lib/mako/ast.py index f879e8b4..a3f3ee3e 100644 --- a/lib/mako/ast.py +++ b/lib/mako/ast.py @@ -1,5 +1,5 @@ # mako/ast.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/cache.py b/lib/mako/cache.py index d77be271..db21bb3e 100644 --- a/lib/mako/cache.py +++ b/lib/mako/cache.py @@ -1,5 +1,5 @@ # mako/cache.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/cmd.py b/lib/mako/cmd.py index 7592fb27..93a6733f 100755 --- a/lib/mako/cmd.py +++ b/lib/mako/cmd.py @@ -1,5 +1,5 @@ # mako/cmd.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py index c897f0ff..a9dbcb67 100644 --- a/lib/mako/codegen.py +++ b/lib/mako/codegen.py @@ -1,5 +1,5 @@ # mako/codegen.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/compat.py b/lib/mako/compat.py index 68bc03b1..48df30d6 100644 --- a/lib/mako/compat.py +++ b/lib/mako/compat.py @@ -1,5 +1,5 @@ # mako/compat.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/exceptions.py b/lib/mako/exceptions.py index a0a5feca..31c695fd 100644 --- a/lib/mako/exceptions.py +++ b/lib/mako/exceptions.py @@ -1,5 +1,5 @@ # mako/exceptions.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/autohandler.py b/lib/mako/ext/autohandler.py index e8fdac89..5bcfc285 100644 --- a/lib/mako/ext/autohandler.py +++ b/lib/mako/ext/autohandler.py @@ -1,5 +1,5 @@ # ext/autohandler.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/babelplugin.py b/lib/mako/ext/babelplugin.py index f015ec25..907d0b80 100644 --- a/lib/mako/ext/babelplugin.py +++ b/lib/mako/ext/babelplugin.py @@ -1,5 +1,5 @@ # ext/babelplugin.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/beaker_cache.py b/lib/mako/ext/beaker_cache.py index a40b09cf..9aa35b06 100644 --- a/lib/mako/ext/beaker_cache.py +++ b/lib/mako/ext/beaker_cache.py @@ -1,5 +1,5 @@ # ext/beaker_cache.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/extract.py b/lib/mako/ext/extract.py index 74d067d8..9d33ee18 100644 --- a/lib/mako/ext/extract.py +++ b/lib/mako/ext/extract.py @@ -1,5 +1,5 @@ # ext/extract.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/linguaplugin.py b/lib/mako/ext/linguaplugin.py index 4cce6262..efb04c70 100644 --- a/lib/mako/ext/linguaplugin.py +++ b/lib/mako/ext/linguaplugin.py @@ -1,5 +1,5 @@ # ext/linguaplugin.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/preprocessors.py b/lib/mako/ext/preprocessors.py index 6855eeb4..80403ecd 100644 --- a/lib/mako/ext/preprocessors.py +++ b/lib/mako/ext/preprocessors.py @@ -1,5 +1,5 @@ # ext/preprocessors.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/pygmentplugin.py b/lib/mako/ext/pygmentplugin.py index 38d6a71b..9acbf4cd 100644 --- a/lib/mako/ext/pygmentplugin.py +++ b/lib/mako/ext/pygmentplugin.py @@ -1,5 +1,5 @@ # ext/pygmentplugin.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/ext/turbogears.py b/lib/mako/ext/turbogears.py index 413d9f74..2ebf0746 100644 --- a/lib/mako/ext/turbogears.py +++ b/lib/mako/ext/turbogears.py @@ -1,5 +1,5 @@ # ext/turbogears.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/filters.py b/lib/mako/filters.py index 26edd8ee..af202f3f 100644 --- a/lib/mako/filters.py +++ b/lib/mako/filters.py @@ -1,5 +1,5 @@ # mako/filters.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/lexer.py b/lib/mako/lexer.py index 527c4b51..75182f85 100644 --- a/lib/mako/lexer.py +++ b/lib/mako/lexer.py @@ -1,5 +1,5 @@ # mako/lexer.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php @@ -74,12 +74,11 @@ class Lexer: (start, end) = match.span() self.match_position = end + 1 if end == start else end self.matched_lineno = self.lineno - lines = re.findall(r"\n", self.text[mp : self.match_position]) cp = mp - 1 - while cp >= 0 and cp < self.textlength and self.text[cp] != "\n": - cp -= 1 + if cp >= 0 and cp < self.textlength: + cp = self.text[: cp + 1].rfind("\n") self.matched_charpos = mp - cp - self.lineno += len(lines) + self.lineno += self.text[mp : self.match_position].count("\n") return match def parse_until_text(self, watch_nesting, *text): @@ -273,20 +272,24 @@ class Lexer: return self.template def match_tag_start(self): - match = self.match( - r""" + reg = r""" \<% # opening tag ([\w\.\:]+) # keyword - ((?:\s+\w+|\s*=\s*|".*?"|'.*?')*) # attrname, = \ + ((?:\s+\w+|\s*=\s*|"[^"]*?"|'[^']*?'|\s*,\s*)*) # attrname, = \ # sign, string expression + # comma is for backwards compat + # identified in #366 \s* # more whitespace (/)?> # closing - """, + """ + + match = self.match( + reg, re.I | re.S | re.X, ) @@ -319,7 +322,7 @@ class Lexer: return True def match_tag_end(self): - match = self.match(r"\") + match = self.match(r"\") if match: if not len(self.tag): raise exceptions.SyntaxException( diff --git a/lib/mako/lookup.py b/lib/mako/lookup.py index 7afe242b..f7410ce3 100644 --- a/lib/mako/lookup.py +++ b/lib/mako/lookup.py @@ -1,5 +1,5 @@ # mako/lookup.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/parsetree.py b/lib/mako/parsetree.py index 2135769f..c5a12d1d 100644 --- a/lib/mako/parsetree.py +++ b/lib/mako/parsetree.py @@ -1,5 +1,5 @@ # mako/parsetree.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/pygen.py b/lib/mako/pygen.py index 46b0b52f..57c69793 100644 --- a/lib/mako/pygen.py +++ b/lib/mako/pygen.py @@ -1,5 +1,5 @@ # mako/pygen.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php @@ -43,6 +43,15 @@ class PythonPrinter: # source lines self.source_map = {} + self._re_space_comment = re.compile(r"^\s*#") + self._re_space = re.compile(r"^\s*$") + self._re_indent = re.compile(r":[ \t]*(?:#.*)?$") + self._re_compound = re.compile(r"^\s*(if|try|elif|while|for|with)") + self._re_indent_keyword = re.compile( + r"^\s*(def|class|else|elif|except|finally)" + ) + self._re_unindentor = re.compile(r"^\s*(else|elif|except|finally).*\:") + def _update_lineno(self, num): self.lineno += num @@ -86,8 +95,8 @@ class PythonPrinter: if ( line is None - or re.match(r"^\s*#", line) - or re.match(r"^\s*$", line) + or self._re_space_comment.match(line) + or self._re_space.match(line) ): hastext = False else: @@ -121,12 +130,12 @@ class PythonPrinter: # note that a line can both decrase (before printing) and # then increase (after printing) the indentation level. - if re.search(r":[ \t]*(?:#.*)?$", line): + if self._re_indent.search(line): # increment indentation count, and also # keep track of what the keyword was that indented us, # if it is a python compound statement keyword # where we might have to look for an "unindent" keyword - match = re.match(r"^\s*(if|try|elif|while|for|with)", line) + match = self._re_compound.match(line) if match: # its a "compound" keyword, so we will check for "unindentors" indentor = match.group(1) @@ -137,9 +146,7 @@ class PythonPrinter: # its not a "compound" keyword. but lets also # test for valid Python keywords that might be indenting us, # else assume its a non-indenting line - m2 = re.match( - r"^\s*(def|class|else|elif|except|finally)", line - ) + m2 = self._re_indent_keyword.match(line) if m2: self.indent += 1 self.indent_detail.append(indentor) @@ -167,7 +174,7 @@ class PythonPrinter: # if the current line doesnt have one of the "unindentor" keywords, # return False - match = re.match(r"^\s*(else|elif|except|finally).*\:", line) + match = self._re_unindentor.match(line) # if True, whitespace matches up, we have a compound indentor, # and this line has an unindentor, this # is probably good enough @@ -193,6 +200,9 @@ class PythonPrinter: stripspace is a string of space that will be truncated from the start of the line before indenting.""" + if stripspace == "": + # Fast path optimization. + return self.indentstring * self.indent + line return re.sub( r"^%s" % stripspace, self.indentstring * self.indent, line diff --git a/lib/mako/pyparser.py b/lib/mako/pyparser.py index 5c55505b..d9b090c6 100644 --- a/lib/mako/pyparser.py +++ b/lib/mako/pyparser.py @@ -1,5 +1,5 @@ # mako/pyparser.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/template.py b/lib/mako/template.py index bbbe73cb..8c70731d 100644 --- a/lib/mako/template.py +++ b/lib/mako/template.py @@ -1,5 +1,5 @@ # mako/template.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/lib/mako/testing/fixtures.py b/lib/mako/testing/fixtures.py index c9379c0c..01e99617 100644 --- a/lib/mako/testing/fixtures.py +++ b/lib/mako/testing/fixtures.py @@ -80,6 +80,16 @@ class TemplateTest: output = filters(output) eq_(output, expected) + def indicates_unbound_local_error(self, rendered_output, unbound_var): + var = f"'{unbound_var}'" + error_msgs = ( + # < 3.11 + f"local variable {var} referenced before assignment", + # >= 3.11 + f"cannot access local variable {var} where it is not associated", + ) + return any((msg in rendered_output) for msg in error_msgs) + class PlainCacheImpl(CacheImpl): """Simple memory cache impl so that tests which diff --git a/lib/mako/util.py b/lib/mako/util.py index 74c8b9eb..5fb683b4 100644 --- a/lib/mako/util.py +++ b/lib/mako/util.py @@ -1,5 +1,5 @@ # mako/util.py -# Copyright 2006-2021 the Mako authors and contributors +# Copyright 2006-2022 the Mako authors and contributors # # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php diff --git a/requirements.txt b/requirements.txt index fd8a848c..2f22fe04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ importlib-metadata==5.0.0 importlib-resources==5.10.0 git+https://github.com/Tautulli/ipwhois.git@master#egg=ipwhois IPy==1.01 -Mako==1.2.0 +Mako==1.2.3 MarkupSafe==2.1.1 musicbrainzngs==0.7.1 packaging==21.3