-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
86 lines (78 loc) · 1.45 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from lexer import Lexer
from parser import Parser
from compiler import generate
from environment import Template
class E:
autoescape = True
def tokenize(self, source):
l = Lexer(None)
return l.tokenize(source)
template = '''
{{hello}}
{% if 1 < 2 %}
{{hello2}}
{{func()}}
heya
{% endif %}
{% with x, y = (1, 'test') %}
{{x}}
{% endwith %}
{% block test %}
{% for i in func() %}
{{i}}
{% endfor %}
{% endblock %}'''
template = '''
{{hello}}
{% block content %}
{% for i in items %}
{{i}}
{% else %}
heya
{% endfor %}
{% endblock %}
'''
template = '''
{{hello}}
{% block content %}
{{test()}}
{{d['t']}}
{{obj.x}}
{{hello}}
{% with x = 100 %}
{{func(x)}}
{% endwith %}
{% block test %}
{{hello, func(2)}}
{{func(1)}}
{% if hello %}
{{hello_}}
hey there!
{% endif %}
{% block test2 %}
{{func(hello)}}
{% with x = 2 %}
{{func(x)}}
{% endwith %}
{% endblock %}
{% for i in items %}{{i}}{% endfor %}
{% if 1 == 0 %}yes{% endif %}
{% endblock %}
{% endblock %}
'''
e = E()
l = Lexer(None)
p = Parser(e, template)
t = Template(template)
# print(p.parse())
def t_():
return 'this is test'
class A:
x = 1
source = t.render(
items=[1,2,3,4],
test=t_,
obj=A(),
func=lambda x: x,
d=(1,23,4))
print(source)