Skip to content

Commit 781e5e9

Browse files
zzzeekGerrit Code Review
authored andcommitted
Merge "more code updates" into main
2 parents 4371b7e + 3fae86f commit 781e5e9

27 files changed

Lines changed: 114 additions & 269 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. change::
2+
:tags: py3k
3+
4+
The ``bytestring_passthrough`` template argument is removed, as this
5+
flag only applied to Python 2.

mako/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/__init__.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php

mako/_ast_util.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/_ast_util.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -47,7 +47,6 @@
4747
from _ast import UAdd
4848
from _ast import USub
4949

50-
from mako.compat import arg_stringname
5150

5251
BOOLOP_SYMBOLS = {And: "and", Or: "or"}
5352

@@ -94,9 +93,7 @@ def parse(expr, filename="<unknown>", mode="exec"):
9493

9594
def iter_fields(node):
9695
"""Iterate over all fields of a node, only yielding existing fields."""
97-
# CPython 2.5 compat
98-
if not hasattr(node, "_fields") or not node._fields:
99-
return
96+
10097
for field in node._fields:
10198
try:
10299
yield field, getattr(node, field)
@@ -266,10 +263,10 @@ def write_comma():
266263
self.visit(default)
267264
if node.vararg is not None:
268265
write_comma()
269-
self.write("*" + arg_stringname(node.vararg))
266+
self.write("*" + node.vararg.arg)
270267
if node.kwarg is not None:
271268
write_comma()
272-
self.write("**" + arg_stringname(node.kwarg))
269+
self.write("**" + node.kwarg.arg)
273270

274271
def decorators(self, node):
275272
for decorator in node.decorator_list:

mako/ast.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/ast.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -87,7 +87,7 @@ def __init__(self, code, **exception_kwargs):
8787
if not m:
8888
raise exceptions.CompileException(
8989
"Fragment '%s' is not a partial control statement" % code,
90-
**exception_kwargs
90+
**exception_kwargs,
9191
)
9292
if m.group(3):
9393
code = code[: m.start(3)]
@@ -105,7 +105,7 @@ def __init__(self, code, **exception_kwargs):
105105
else:
106106
raise exceptions.CompileException(
107107
"Unsupported control keyword: '%s'" % keyword,
108-
**exception_kwargs
108+
**exception_kwargs,
109109
)
110110
super(PythonFragment, self).__init__(code, **exception_kwargs)
111111

@@ -123,13 +123,13 @@ def __init__(self, code, allow_kwargs=True, **exception_kwargs):
123123
if not hasattr(self, "funcname"):
124124
raise exceptions.CompileException(
125125
"Code '%s' is not a function declaration" % code,
126-
**exception_kwargs
126+
**exception_kwargs,
127127
)
128128
if not allow_kwargs and self.kwargs:
129129
raise exceptions.CompileException(
130130
"'**%s' keyword argument not allowed here"
131131
% self.kwargnames[-1],
132-
**exception_kwargs
132+
**exception_kwargs,
133133
)
134134

135135
def get_argument_expressions(self, as_call=False):

mako/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/cache.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php

mako/cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/cmd.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -85,7 +85,7 @@ def cmdline(argv=None):
8585
except:
8686
_exit()
8787

88-
kw = dict([varsplit(var) for var in options.var])
88+
kw = dict(varsplit(var) for var in options.var)
8989
try:
9090
rendered = template.render(**kw)
9191
except:

mako/codegen.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/codegen.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -12,7 +12,6 @@
1212
import time
1313

1414
from mako import ast
15-
from mako import compat
1615
from mako import exceptions
1716
from mako import filters
1817
from mako import parsetree
@@ -25,8 +24,8 @@
2524
# names which are hardwired into the
2625
# template and are not accessed via the
2726
# context itself
28-
TOPLEVEL_DECLARED = set(["UNDEFINED", "STOP_RENDERING"])
29-
RESERVED_NAMES = set(["context", "loop"]).union(TOPLEVEL_DECLARED)
27+
TOPLEVEL_DECLARED = {"UNDEFINED", "STOP_RENDERING"}
28+
RESERVED_NAMES = {"context", "loop"}.union(TOPLEVEL_DECLARED)
3029

3130

3231
def compile( # noqa
@@ -393,7 +392,7 @@ def visitDefOrBase(s, node):
393392
raise exceptions.CompileException(
394393
"Can't put anonymous blocks inside "
395394
"<%namespace>",
396-
**node.exception_kwargs
395+
**node.exception_kwargs,
397396
)
398397
self.write_inline_def(node, identifiers, nested=False)
399398
export.append(node.funcname)
@@ -470,7 +469,7 @@ def write_variable_declares(self, identifiers, toplevel=False, limit=None):
470469
"""
471470

472471
# collection of all defs available to us in this scope
473-
comp_idents = dict([(c.funcname, c) for c in identifiers.defs])
472+
comp_idents = {c.funcname: c for c in identifiers.defs}
474473
to_write = set()
475474

476475
# write "context.get()" for all variables we are going to
@@ -846,11 +845,11 @@ def visitControlLine(self, node):
846845
# and end control lines, and
847846
# 3) any control line with no content other than comments
848847
if not children or (
849-
compat.all(
848+
all(
850849
isinstance(c, (parsetree.Comment, parsetree.ControlLine))
851850
for c in children
852851
)
853-
and compat.all(
852+
and all(
854853
(node.is_ternary(c.keyword) or c.isend)
855854
for c in children
856855
if isinstance(c, parsetree.ControlLine)
@@ -1157,7 +1156,7 @@ def _check_name_exists(self, collection, node):
11571156
raise exceptions.CompileException(
11581157
"%%def or %%block named '%s' already "
11591158
"exists in this template." % node.funcname,
1160-
**node.exception_kwargs
1159+
**node.exception_kwargs,
11611160
)
11621161

11631162
def visitDefTag(self, node):
@@ -1187,15 +1186,15 @@ def visitBlockTag(self, node):
11871186
raise exceptions.CompileException(
11881187
"Named block '%s' not allowed inside of def '%s'"
11891188
% (node.name, self.node.name),
1190-
**node.exception_kwargs
1189+
**node.exception_kwargs,
11911190
)
11921191
elif isinstance(
11931192
self.node, (parsetree.CallTag, parsetree.CallNamespaceTag)
11941193
):
11951194
raise exceptions.CompileException(
11961195
"Named block '%s' not allowed inside of <%%call> tag"
11971196
% (node.name,),
1198-
**node.exception_kwargs
1197+
**node.exception_kwargs,
11991198
)
12001199

12011200
for ident in node.undeclared_identifiers():

mako/compat.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/compat.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -46,53 +46,16 @@ def inspect_getargspec(func):
4646
return ArgSpec(args, varargs, varkw, func.__defaults__)
4747

4848

49-
def octal(lit):
50-
return eval("0o" + lit)
51-
52-
5349
def load_module(module_id, path):
5450
spec = util.spec_from_file_location(module_id, path)
5551
module = util.module_from_spec(spec)
5652
spec.loader.exec_module(module)
5753
return module
5854

5955

60-
def reraise(tp, value, tb=None, cause=None):
61-
if cause is not None:
62-
value.__cause__ = cause
63-
if value.__traceback__ is not tb:
64-
raise value.with_traceback(tb)
65-
raise value
66-
67-
6856
def exception_as():
6957
return sys.exc_info()[1]
7058

7159

72-
all = all # noqa
73-
74-
7560
def exception_name(exc):
7661
return exc.__class__.__name__
77-
78-
79-
################################################
80-
# cross-compatible metaclass implementation
81-
# Copyright (c) 2010-2012 Benjamin Peterson
82-
def with_metaclass(meta, base=object):
83-
"""Create a base class with a metaclass."""
84-
return meta("%sBase" % meta.__name__, (base,), {})
85-
86-
87-
################################################
88-
89-
90-
def arg_stringname(func_arg):
91-
"""Gets the string name of a kwarg or vararg
92-
In Python3.4 a function's args are
93-
of _ast.arg type not _ast.name
94-
"""
95-
if hasattr(func_arg, "arg"):
96-
return func_arg.arg
97-
else:
98-
return str(func_arg)

mako/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mako/exceptions.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php

mako/ext/autohandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ext/autohandler.py
2-
# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file>
2+
# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file>
33
#
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php

0 commit comments

Comments
 (0)