mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Update mako to 1.1.0
This commit is contained in:
parent
84ce4758d1
commit
f2d7beec90
27 changed files with 2424 additions and 1890 deletions
|
@ -1,5 +1,5 @@
|
|||
# mako/pygen.py
|
||||
# Copyright (C) 2006-2015 the Mako authors and contributors <see AUTHORS file>
|
||||
# Copyright 2006-2019 the Mako authors and contributors <see AUTHORS file>
|
||||
#
|
||||
# This module is part of Mako and is released under
|
||||
# the MIT License: http://www.opensource.org/licenses/mit-license.php
|
||||
|
@ -7,8 +7,10 @@
|
|||
"""utilities for generating and formatting literal Python code."""
|
||||
|
||||
import re
|
||||
|
||||
from mako import exceptions
|
||||
|
||||
|
||||
class PythonPrinter(object):
|
||||
def __init__(self, stream):
|
||||
# indentation counter
|
||||
|
@ -52,14 +54,16 @@ class PythonPrinter(object):
|
|||
self.stream.write("\n" * num)
|
||||
self._update_lineno(num)
|
||||
|
||||
def write_indented_block(self, block):
|
||||
def write_indented_block(self, block, starting_lineno=None):
|
||||
"""print a line or lines of python which already contain indentation.
|
||||
|
||||
The indentation of the total block of lines will be adjusted to that of
|
||||
the current indent level."""
|
||||
self.in_indent_lines = False
|
||||
for l in re.split(r'\r?\n', block):
|
||||
for i, l in enumerate(re.split(r"\r?\n", block)):
|
||||
self.line_buffer.append(l)
|
||||
if starting_lineno is not None:
|
||||
self.start_source(starting_lineno + i)
|
||||
self._update_lineno(1)
|
||||
|
||||
def writelines(self, *lines):
|
||||
|
@ -80,20 +84,19 @@ class PythonPrinter(object):
|
|||
self._flush_adjusted_lines()
|
||||
self.in_indent_lines = True
|
||||
|
||||
if (line is None or
|
||||
re.match(r"^\s*#",line) or
|
||||
re.match(r"^\s*$", line)
|
||||
):
|
||||
if (
|
||||
line is None
|
||||
or re.match(r"^\s*#", line)
|
||||
or re.match(r"^\s*$", line)
|
||||
):
|
||||
hastext = False
|
||||
else:
|
||||
hastext = True
|
||||
|
||||
is_comment = line and len(line) and line[0] == '#'
|
||||
is_comment = line and len(line) and line[0] == "#"
|
||||
|
||||
# see if this line should decrease the indentation level
|
||||
if (not is_comment and
|
||||
(not hastext or self._is_unindentor(line))
|
||||
):
|
||||
if not is_comment and (not hastext or self._is_unindentor(line)):
|
||||
|
||||
if self.indent > 0:
|
||||
self.indent -= 1
|
||||
|
@ -102,7 +105,8 @@ class PythonPrinter(object):
|
|||
# module wont compile.
|
||||
if len(self.indent_detail) == 0:
|
||||
raise exceptions.SyntaxException(
|
||||
"Too many whitespace closures")
|
||||
"Too many whitespace closures"
|
||||
)
|
||||
self.indent_detail.pop()
|
||||
|
||||
if line is None:
|
||||
|
@ -132,8 +136,9 @@ class PythonPrinter(object):
|
|||
# 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 = re.match(
|
||||
r"^\s*(def|class|else|elif|except|finally)", line
|
||||
)
|
||||
if m2:
|
||||
self.indent += 1
|
||||
self.indent_detail.append(indentor)
|
||||
|
@ -172,27 +177,28 @@ class PythonPrinter(object):
|
|||
|
||||
# should we decide that its not good enough, heres
|
||||
# more stuff to check.
|
||||
#keyword = match.group(1)
|
||||
# keyword = match.group(1)
|
||||
|
||||
# match the original indent keyword
|
||||
#for crit in [
|
||||
# for crit in [
|
||||
# (r'if|elif', r'else|elif'),
|
||||
# (r'try', r'except|finally|else'),
|
||||
# (r'while|for', r'else'),
|
||||
#]:
|
||||
# ]:
|
||||
# if re.match(crit[0], indentor) and re.match(crit[1], keyword):
|
||||
# return True
|
||||
|
||||
#return False
|
||||
# return False
|
||||
|
||||
def _indent_line(self, line, stripspace=''):
|
||||
def _indent_line(self, line, stripspace=""):
|
||||
"""indent the given line according to the current indent level.
|
||||
|
||||
stripspace is a string of space that will be truncated from the
|
||||
start of the line before indenting."""
|
||||
|
||||
return re.sub(r"^%s" % stripspace, self.indentstring
|
||||
* self.indent, line)
|
||||
return re.sub(
|
||||
r"^%s" % stripspace, self.indentstring * self.indent, line
|
||||
)
|
||||
|
||||
def _reset_multi_line_flags(self):
|
||||
"""reset the flags which would indicate we are in a backslashed
|
||||
|
@ -210,7 +216,7 @@ class PythonPrinter(object):
|
|||
# a literal multiline string with unfortunately placed
|
||||
# whitespace
|
||||
|
||||
current_state = (self.backslashed or self.triplequoted)
|
||||
current_state = self.backslashed or self.triplequoted
|
||||
|
||||
if re.search(r"\\$", line):
|
||||
self.backslashed = True
|
||||
|
@ -247,7 +253,7 @@ def adjust_whitespace(text):
|
|||
(backslashed, triplequoted) = (0, 1)
|
||||
|
||||
def in_multi_line(line):
|
||||
start_state = (state[backslashed] or state[triplequoted])
|
||||
start_state = state[backslashed] or state[triplequoted]
|
||||
|
||||
if re.search(r"\\$", line):
|
||||
state[backslashed] = True
|
||||
|
@ -257,7 +263,7 @@ def adjust_whitespace(text):
|
|||
def match(reg, t):
|
||||
m = re.match(reg, t)
|
||||
if m:
|
||||
return m, t[len(m.group(0)):]
|
||||
return m, t[len(m.group(0)) :]
|
||||
else:
|
||||
return None, t
|
||||
|
||||
|
@ -269,7 +275,7 @@ def adjust_whitespace(text):
|
|||
else:
|
||||
m, line = match(r".*?(?=%s|$)" % state[triplequoted], line)
|
||||
else:
|
||||
m, line = match(r'#', line)
|
||||
m, line = match(r"#", line)
|
||||
if m:
|
||||
return start_state
|
||||
|
||||
|
@ -282,13 +288,13 @@ def adjust_whitespace(text):
|
|||
|
||||
return start_state
|
||||
|
||||
def _indent_line(line, stripspace=''):
|
||||
return re.sub(r"^%s" % stripspace, '', line)
|
||||
def _indent_line(line, stripspace=""):
|
||||
return re.sub(r"^%s" % stripspace, "", line)
|
||||
|
||||
lines = []
|
||||
stripspace = None
|
||||
|
||||
for line in re.split(r'\r?\n', text):
|
||||
for line in re.split(r"\r?\n", text):
|
||||
if in_multi_line(line):
|
||||
lines.append(line)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue