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
Show 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 @@
...
@@ -86,10 +86,6 @@
Common definitions used by TAL and METAL compilation an transformation.
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
XMLNS_NS
=
"http://www.w3.org/2000/xmlns/"
# URI for XML NS declarations
ZOPE_TAL_NS
=
"http://xml.zope.org/namespaces/tal"
ZOPE_TAL_NS
=
"http://xml.zope.org/namespaces/tal"
...
@@ -97,10 +93,15 @@ ZOPE_METAL_NS = "http://xml.zope.org/namespaces/metal"
...
@@ -97,10 +93,15 @@ ZOPE_METAL_NS = "http://xml.zope.org/namespaces/metal"
NAME_RE
=
"[a-zA-Z_][a-zA-Z0-9_]*"
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):
def parseAttributeReplacements(arg):
dict = {}
dict = {}
for part in splitParts(arg):
for part in splitParts(arg):
m
=
re
.
match
(
r"\
s*([^
\s]+)\
s*(.*)
",
part)
m =
_attr_re.match(
part)
if not m:
if not m:
print "
Bad
syntax
in
z
:
attributes
:
", `part`
print "
Bad
syntax
in
z
:
attributes
:
", `part`
continue
continue
...
@@ -112,7 +113,7 @@ def parseAttributeReplacements(arg):
...
@@ -112,7 +113,7 @@ def parseAttributeReplacements(arg):
return dict
return dict
def parseSubstitution(arg):
def parseSubstitution(arg):
m =
re.match(r"
\
s
*
(
?
:(
text
|
structure
)
\
s
+
)
?
(.
*
)
",
arg)
m =
_subst_re.match(
arg)
if not m:
if not m:
print "
Bad
syntax
in
z
:
insert
/
replace
:
", `arg`
print "
Bad
syntax
in
z
:
insert
/
replace
:
", `arg`
return None, None
return None, None
...
@@ -124,9 +125,10 @@ def parseSubstitution(arg):
...
@@ -124,9 +125,10 @@ def parseSubstitution(arg):
def splitParts(arg):
def splitParts(arg):
# Break in pieces at undoubled semicolons and
# Break in pieces at undoubled semicolons and
# change double semicolons to singles:
# change double semicolons to singles:
import string
arg = string.replace(arg, "
;;
", "
\
0
")
arg = string.replace(arg, "
;;
", "
\
0
")
parts = string.split(arg, ';')
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
return parts
...
@@ -140,6 +142,8 @@ def macroIndexer(document):
...
@@ -140,6 +142,8 @@ def macroIndexer(document):
_macroVisitor(document.documentElement, macroIndex)
_macroVisitor(document.documentElement, macroIndex)
return macroIndex
return macroIndex
from xml.dom import Node
def _macroVisitor(node, macroIndex, __elementNodeType=Node.ELEMENT_NODE):
def _macroVisitor(node, macroIndex, __elementNodeType=Node.ELEMENT_NODE):
# Internal routine to efficiently recurse down the tree of elements
# Internal routine to efficiently recurse down the tree of elements
macroName = node.getAttributeNS(ZOPE_METAL_NS, "
define
-
macro
")
macroName = node.getAttributeNS(ZOPE_METAL_NS, "
define
-
macro
")
...
@@ -176,3 +180,5 @@ def _slotVisitor(node, slotIndex, __elementNodeType=Node.ELEMENT_NODE):
...
@@ -176,3 +180,5 @@ def _slotVisitor(node, slotIndex, __elementNodeType=Node.ELEMENT_NODE):
for child in node.childNodes:
for child in node.childNodes:
if child.nodeType == __elementNodeType:
if child.nodeType == __elementNodeType:
_slotVisitor(child, slotIndex)
_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