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
2feef0d3
Commit
2feef0d3
authored
Jun 12, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
38793800
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
lib/python/TAL/DummyEngine.py
lib/python/TAL/DummyEngine.py
+15
-12
No files found.
lib/python/TAL/DummyEngine.py
View file @
2feef0d3
...
@@ -88,12 +88,16 @@ Dummy TALES engine so that I can test out the TAL implementation.
...
@@ -88,12 +88,16 @@ Dummy TALES engine so that I can test out the TAL implementation.
import
re
import
re
import
sys
import
sys
import
string
from
string
import
rfind
,
strip
import
driver
from
TALDefs
import
NAME_RE
,
TALError
,
TALESError
from
TALDefs
import
NAME_RE
,
TALError
,
TALESError
Default
=
[]
Default
=
[]
name_match
=
re
.
compile
(
r"(?s)(%s):(.*)\
Z
" % NAME_RE).match
class DummyEngine:
class DummyEngine:
def __init__(self, macros=None):
def __init__(self, macros=None):
...
@@ -128,8 +132,9 @@ class DummyEngine:
...
@@ -128,8 +132,9 @@ class DummyEngine:
self.globals[name] = value
self.globals[name] = value
def evaluate(self, expression):
def evaluate(self, expression):
expression
=
self
.
uncompile
(
expression
)
assert expression[:1] == "
$
" == expression[-1:], expression
m
=
re
.
match
(
r"(?s)(%s):(.*)\
Z
" % NAME_RE, expression)
expression = expression[1:-1]
m = name_match(expression)
if m:
if m:
type, expr = m.group(1, 2)
type, expr = m.group(1, 2)
else:
else:
...
@@ -138,7 +143,7 @@ class DummyEngine:
...
@@ -138,7 +143,7 @@ class DummyEngine:
if type in ("
string
", "
str
"):
if type in ("
string
", "
str
"):
return expr
return expr
if type in ("
path
", "
var
", "
global
", "
local
"):
if type in ("
path
", "
var
", "
global
", "
local
"):
expr = stri
ng.stri
p(expr)
expr = strip(expr)
if self.locals.has_key(expr):
if self.locals.has_key(expr):
return self.locals[expr]
return self.locals[expr]
elif self.globals.has_key(expr):
elif self.globals.has_key(expr):
...
@@ -146,8 +151,7 @@ class DummyEngine:
...
@@ -146,8 +151,7 @@ class DummyEngine:
else:
else:
raise TALESError("
unknown
variable
:
%
s
" % `expr`)
raise TALESError("
unknown
variable
:
%
s
" % `expr`)
if type == "
not
":
if type == "
not
":
v = self.evaluate(expr)
return not self.evaluate(expr)
return not v
if type == "
exists
":
if type == "
exists
":
return self.locals.has_key(expr) or self.globals.has_key(expr)
return self.locals.has_key(expr) or self.globals.has_key(expr)
if type == "
python
":
if type == "
python
":
...
@@ -180,15 +184,15 @@ class DummyEngine:
...
@@ -180,15 +184,15 @@ class DummyEngine:
return self.evaluate(expr)
return self.evaluate(expr)
def evaluateMacro(self, macroName):
def evaluateMacro(self, macroName):
macroName = self.uncompile(macroName)
assert macroName[:1] == "
$
" == macroName[-1:], macroName
macroName = macroName[1:-1]
file, localName = self.findMacroFile(macroName)
file, localName = self.findMacroFile(macroName)
if not file:
if not file:
# Local macro
# Local macro
macro = self.macros[localName]
macro = self.macros[localName]
else:
else:
# External macro
# External macro
from driver import compilefile
program, macros = driver.compilefile(file)
program, macros = compilefile(file)
macro = macros.get(localName)
macro = macros.get(localName)
if not macro:
if not macro:
raise TALESError("
macro
%
s
not
found
in
file
%
s
" %
raise TALESError("
macro
%
s
not
found
in
file
%
s
" %
...
@@ -199,14 +203,13 @@ class DummyEngine:
...
@@ -199,14 +203,13 @@ class DummyEngine:
file, localName = self.findMacroFile(macroName)
file, localName = self.findMacroFile(macroName)
if not file:
if not file:
return file, localName
return file, localName
from driver import parsefile
doc = driver.parsefile(file)
doc = parsefile(file)
return doc, localName
return doc, localName
def findMacroFile(self, macroName):
def findMacroFile(self, macroName):
if not macroName:
if not macroName:
raise TALESError("
empty
macro
name
")
raise TALESError("
empty
macro
name
")
i =
string.
rfind(macroName, '/')
i = rfind(macroName, '/')
if i < 0:
if i < 0:
# No slash -- must be a locally defined macro
# No slash -- must be a locally defined macro
return None, macroName
return None, macroName
...
...
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