Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
da6b94fd
Commit
da6b94fd
authored
Apr 27, 2001
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add action cancellation.
parent
06018f21
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
14 deletions
+43
-14
lib/python/TAL/DummyEngine.py
lib/python/TAL/DummyEngine.py
+9
-2
lib/python/TAL/TALGenerator.py
lib/python/TAL/TALGenerator.py
+1
-1
lib/python/TAL/TALInterpreter.py
lib/python/TAL/TALInterpreter.py
+32
-10
lib/python/TAL/tests/test_htmltalparser.py
lib/python/TAL/tests/test_htmltalparser.py
+1
-1
No files found.
lib/python/TAL/DummyEngine.py
View file @
da6b94fd
...
...
@@ -92,6 +92,8 @@ import string
from
TALDefs
import
NAME_RE
,
TALError
,
TALESError
CancelAction
=
[]
class
DummyEngine
:
def
__init__
(
self
,
macros
=
None
):
...
...
@@ -120,10 +122,12 @@ class DummyEngine:
if
self
.
locals
is
self
.
stack
[
-
1
]:
# Unmerge this scope's locals from previous scope of first set
self
.
locals
=
self
.
locals
.
copy
()
self
.
locals
[
name
]
=
value
if
value
is
not
CancelAction
:
self
.
locals
[
name
]
=
value
def
setGlobal
(
self
,
name
,
value
):
self
.
globals
[
name
]
=
value
if
value
is
not
CancelAction
:
self
.
globals
[
name
]
=
value
def
evaluate
(
self
,
expression
):
expression
=
self
.
uncompile
(
expression
)
...
...
@@ -221,6 +225,9 @@ class DummyEngine:
def getTALESError(self):
return TALESError
def getCancelAction(self):
return CancelAction
class Iterator:
def __init__(self, name, seq, engine):
...
...
lib/python/TAL/TALGenerator.py
View file @
da6b94fd
...
...
@@ -347,7 +347,7 @@ class TALGenerator:
del repldict[key]
newlist.append(item)
for key, value in repldict.items(): # Add dynamic-only attributes
item = (key,
"", "
replace
", value)
item = (key,
None, "
insert
", value)
newlist.append(item)
return newlist
...
...
lib/python/TAL/TALInterpreter.py
View file @
da6b94fd
...
...
@@ -96,7 +96,7 @@ try:
except
ImportError
:
from
StringIO
import
StringIO
from
TALDefs
import
quote
,
TAL_VERSION
,
METALError
from
TALDefs
import
quote
,
TAL_VERSION
,
TALError
,
METALError
from
TALDefs
import
isCurrentVersion
,
getProgramVersion
,
getProgramMode
from
TALGenerator
import
TALGenerator
...
...
@@ -157,6 +157,7 @@ class TALInterpreter:
self
.
macros
=
macros
self
.
engine
=
engine
self
.
TALESError
=
engine
.
getTALESError
()
self
.
CancelAction
=
engine
.
getCancelAction
()
self
.
stream
=
stream
or
sys
.
stdout
self
.
debug
=
debug
self
.
wrap
=
wrap
...
...
@@ -245,6 +246,7 @@ class TALInterpreter:
def
do_startTag
(
self
,
name
,
attrList
):
self
.
startTagCommon
(
name
,
attrList
,
">"
)
actionIndex
=
[
"replace"
,
"insert"
,
"metal"
,
"tal"
,
"xmlns"
].
index
def
startTagCommon
(
self
,
name
,
attrList
,
end
):
if
not
attrList
:
self
.
stream_write
(
"<%s%s"
%
(
name
,
end
))
...
...
@@ -254,21 +256,32 @@ class TALInterpreter:
for
item
in
attrList
:
name
,
value
=
item
[:
2
]
if
len
(
item
)
>
2
:
action
=
item
[
2
]
if
not
self
.
showtal
and
action
in
(
"tal"
,
"metal"
,
"xmlns"
):
try
:
action
=
self
.
actionIndex
(
item
[
2
])
except
ValueError
:
raise
TALError
,
(
'Error in TAL program'
,
self
.
position
)
if
not
self
.
showtal
and
action
>
1
:
continue
if
action
==
"replace"
and
len
(
item
)
>
3
and
self
.
tal
:
if
action
<=
1
and
self
.
tal
:
if
self
.
html
and
string
.
lower
(
name
)
in
BOOLEAN_HTML_ATTRS
:
ok
=
self
.
engine
.
evaluateBoolean
(
item
[
3
])
if
not
ok
:
evalue
=
self
.
engine
.
evaluateBoolean
(
item
[
3
])
if
evalue
is
self
.
CancelAction
:
if
action
==
1
:
# Cancelled insert
continue
elif
not
evalue
:
continue
else
:
value
=
None
else
:
value
=
self
.
engine
.
evaluateText
(
item
[
3
])
if
value
is
None
:
continue
elif
(
action
==
"metal"
and
self
.
currentMacro
and
evalue
=
self
.
engine
.
evaluateText
(
item
[
3
])
if
evalue
is
self
.
CancelAction
:
if
action
==
1
:
# Cancelled insert
continue
else
:
value
=
item
[
1
]
if
value
is
None
:
continue
elif
(
action
==
2
and
self
.
currentMacro
and
name
[
-
13
:]
==
":define-macro"
and
self
.
metal
):
name
=
name
[:
-
13
]
+
":use-macro"
value
=
self
.
currentMacro
...
...
@@ -314,6 +327,9 @@ class TALInterpreter:
text
=
self
.
engine
.
evaluateText
(
expr
)
if
text
is
None
:
return
if
text
is
self
.
CancelAction
:
self
.
interpret
(
block
)
return
text
=
cgi
.
escape
(
text
)
self
.
stream_write
(
text
)
...
...
@@ -324,6 +340,9 @@ class TALInterpreter:
structure
=
self
.
engine
.
evaluateStructure
(
expr
)
if
structure
is
None
:
return
if
structure
is
self
.
CancelAction
:
self
.
interpret
(
block
)
return
text
=
str
(
structure
)
if
not
repldict
and
not
self
.
strictinsert
:
# Take a shortcut, no error checking
...
...
@@ -378,6 +397,9 @@ class TALInterpreter:
self
.
interpret
(
block
)
return
macro
=
self
.
engine
.
evaluateMacro
(
macroExpr
)
if
macro
is
self
.
CancelAction
:
self
.
interpret
(
block
)
return
if
not
isCurrentVersion
(
macro
):
raise
METALError
(
"macro %s has incompatible version %s"
%
(
`macroName`
,
`getProgramVersion(macro)`
),
...
...
lib/python/TAL/tests/test_htmltalparser.py
View file @
da6b94fd
...
...
@@ -332,7 +332,7 @@ class TALGeneratorTestCases(TestCaseBase):
(
'name'
,
'bar'
),
(
'tal:attributes'
,
'href string:http://www.zope.org; x string:y'
,
'tal'
),
(
'x'
,
''
,
'replace
'
,
'$string:y$'
)]),
(
'x'
,
None
,
'insert
'
,
'$string:y$'
)]),
(
'rawtext'
,
'link</a>'
),
])
self
.
_run_check
(
"<p tal:replace='structure string:<img>' "
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment