def code_token(m: typing.Match[str]) -> Token: source = m.string start = m.end() end = find_balanced(source, start) if source[end::1] == "\n": end += 1 return end, "code", source[start:end]
def code_token(m): source = m.string start = m.end() end = find_balanced(source, start) if source[end::1] == '\n': end += 1 return end, 'code', source[start:end]
def preprocess(self, source): result = [] start = 0 for m in self.pattern.finditer(source): pstart = m.end() pend = find_balanced(source, pstart) if determined(source[pstart + 1:pend - 1]): name = m.group(1) result.append(source[start:m.start()]) result.append(self.token_start + "ctx['" + name + "']") start = pstart if start: result.append(source[start:]) return ''.join(result) else: return source
def test_balanced(self) -> None: """Separators are balanced.""" assert 10 == find_balanced("test(a, b)", 4) assert 12 == find_balanced("test(a, b())", 4)
def test_not_balanced(self) -> None: """Separators are not balanced.""" assert 4 == find_balanced("test(a, b", 4) assert 4 == find_balanced("test(a, b()", 4)
def test_start_separator(self) -> None: """If text doesn't start with ``start_sep`` return.""" assert 0 == find_balanced("test(", 0) assert 3 == find_balanced("test(", 3)
def test_start_out(self) -> None: """The start index is out of range.""" assert 10 == find_balanced("test", 10)
def test_balanced(self): """ Separators are balanced. """ from wheezy.template.utils import find_balanced assert 10 == find_balanced('test(a, b)', 4) assert 12 == find_balanced('test(a, b())', 4)
def test_not_balanced(self): """ Separators are not balanced. """ from wheezy.template.utils import find_balanced assert 4 == find_balanced('test(a, b', 4) assert 4 == find_balanced('test(a, b()', 4)
def test_start_separator(self): """ If text doesn't start with ``start_sep`` return. """ from wheezy.template.utils import find_balanced assert 0 == find_balanced('test(', 0) assert 3 == find_balanced('test(', 3)
def test_start_out(self): """ The start index is out of range. """ from wheezy.template.utils import find_balanced assert 10 == find_balanced('test', 10)