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
b5b04b77
Commit
b5b04b77
authored
Feb 11, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it safe to write "from TALDefs import *".
parent
47f89f61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
lib/python/TAL/TALDefs.py
lib/python/TAL/TALDefs.py
+13
-7
No files found.
lib/python/TAL/TALDefs.py
View file @
b5b04b77
...
...
@@ -86,10 +86,6 @@
Common definitions used by TAL and METAL compilation an transformation.
"""
import
string
import
re
from
xml.dom
import
Node
XMLNS_NS
=
"http://www.w3.org/2000/xmlns/"
# URI for XML NS declarations
ZOPE_TAL_NS
=
"http://xml.zope.org/namespaces/tal"
...
...
@@ -97,10 +93,15 @@ ZOPE_METAL_NS = "http://xml.zope.org/namespaces/metal"
NAME_RE
=
"[a-zA-Z_][a-zA-Z0-9_]*"
import
re
_attr_re
=
re
.
compile
(
r"\
s*([^
\s]+)\
s*(.*)
")
_subst_re = re.compile(r"
\
s
*
(
?
:(
text
|
structure
)
\
s
+
)
?
(.
*
)
")
del re
def parseAttributeReplacements(arg):
dict = {}
for part in splitParts(arg):
m
=
re
.
match
(
r"\
s*([^
\s]+)\
s*(.*)
",
part)
m =
_attr_re.match(
part)
if not m:
print "
Bad
syntax
in
z
:
attributes
:
", `part`
continue
...
...
@@ -112,7 +113,7 @@ def parseAttributeReplacements(arg):
return dict
def parseSubstitution(arg):
m =
re.match(r"
\
s
*
(
?
:(
text
|
structure
)
\
s
+
)
?
(.
*
)
",
arg)
m =
_subst_re.match(
arg)
if not m:
print "
Bad
syntax
in
z
:
insert
/
replace
:
", `arg`
return None, None
...
...
@@ -124,9 +125,10 @@ def parseSubstitution(arg):
def splitParts(arg):
# Break in pieces at undoubled semicolons and
# change double semicolons to singles:
import string
arg = string.replace(arg, "
;;
", "
\
0
")
parts = string.split(arg, ';')
parts = map(lambda s
: string.replace
(s, "
\
0
", "
;;
"), parts)
parts = map(lambda s
, repl=string.replace: repl
(s, "
\
0
", "
;;
"), parts)
return parts
...
...
@@ -140,6 +142,8 @@ def macroIndexer(document):
_macroVisitor(document.documentElement, macroIndex)
return macroIndex
from xml.dom import Node
def _macroVisitor(node, macroIndex, __elementNodeType=Node.ELEMENT_NODE):
# Internal routine to efficiently recurse down the tree of elements
macroName = node.getAttributeNS(ZOPE_METAL_NS, "
define
-
macro
")
...
...
@@ -176,3 +180,5 @@ def _slotVisitor(node, slotIndex, __elementNodeType=Node.ELEMENT_NODE):
for child in node.childNodes:
if child.nodeType == __elementNodeType:
_slotVisitor(child, slotIndex)
del Node
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