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
8456e516
Commit
8456e516
authored
Sep 02, 1997
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various fixes to parsing code.
parent
2abb619c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
19 deletions
+44
-19
lib/python/DocumentTemplate/DT_String.py
lib/python/DocumentTemplate/DT_String.py
+34
-15
lib/python/DocumentTemplate/DT_Util.py
lib/python/DocumentTemplate/DT_Util.py
+10
-4
No files found.
lib/python/DocumentTemplate/DT_String.py
View file @
8456e516
...
...
@@ -25,13 +25,15 @@ class String:
def
tagre
(
self
):
return
regex
.
symcomp
(
'%('
# beginning
'
\
(<
n
ame>[a-z]+
\
)
'
# tag name
'
[
\
0
-
]
*
' # space after tag name
'
\
(<
n
ame>[a-zA-Z0-9_/.-]+
\
)
'
# tag name
'
\
(
'
'
[
\
0
-
]
+
' # space after tag name
'
\
(
<
args
>
\
([
^
)
"]+
\
(
"
[^"
]
*
"
\
)?
\
)*
\
)
'
# arguments
'
\
)?
'
')
\
(<
f
mt>[0-9]*[.]?[0-9]*[a-z]
\
|[]![]
\
)' # end
, regex.casefold)
def parseTag(self, tagre, command=None):
def parseTag(self, tagre, command=None
, sargs=''
):
"""Parse a tag using an already matched re
Return: tag, args, command, coname
...
...
@@ -44,13 +46,23 @@ class String:
or None otherwise
"""
tag, name, args, fmt =tagre.group(0, 'name', 'args', 'fmt')
args=args and strip(args) or ''
if fmt==']':
if not command or name != command.name:
raise ParseError,
'unexpected end tag'
raise ParseError,
('unexpected end tag', tag)
return tag, args, None, None
elif fmt=='[' or fmt=='!':
if command and name in command.blockContinuations:
if name=='else' and args:
# Waaaaaah! Have to special case else because of
# old else start tag usage. Waaaaaaah!
l=len(args)
if not (args==sargs or
args==sargs[:l] and sargs[l:l+1] in '
\
t
\
n
'):
return tag, args, self.commands[name], None
return tag, args, None, name
try: return tag, args, self.commands[name], None
...
...
@@ -58,7 +70,7 @@ class String:
raise ParseError, ('Unexpected tag', tag)
else:
# Var command
args=
"
%
s
%
s
" % (name, args)
args=
args and ("
%
s
%
s
" % (name, args)) or name
return tag, args, Var, None
def varExtra(self,tagre): return tagre.group('fmt')
...
...
@@ -80,10 +92,12 @@ class String:
start=self.parse_block(text, start, result, tagre,
tag, l, args, command)
else:
if command is Var:
result.append(command(args, self.varExtra(tagre)))
else:
result.append(command(args))
try:
if command is Var:
result.append(command(args, self.varExtra(tagre)))
else:
result.append(command(args))
except ParseError, m: self.parse_error(m,tag,text,l)
l=tagre.search(text,start)
...
...
@@ -106,19 +120,21 @@ class String:
tname=scommand.name
sname=stag
sstart=start
sa=sargs
while 1:
l=tagre.search(text,start)
if l < 0: self.parse_error('No closing tag', stag, text, sloc)
try: tag, args, command, coname= self.parseTag(tagre,scommand)
try: tag, args, command, coname= self.parseTag(tagre,scommand
,sa
)
except ParseError, m: self.parse_error(m[0],m[1], text, l)
if command:
start=l+len(tag)
if hasattr(command, 'blockContinuations'):
# New open tag. Need to find closing tag.
start=self.parse_close(text, start, tagre, tag, l, command)
start=self.parse_close(text, start, tagre, tag, l,
command, args)
else:
# Either a continuation tag or an end tag
section=self.SubTemplate(sname)
...
...
@@ -134,22 +150,25 @@ class String:
sargs=args
sstart=start
else:
result.append(scommand(blocks))
try: result.append(scommand(blocks))
except ParseError, m: self.parse_error(m,stag,text,l)
return start
def parse_close(self, text, start, tagre, stag, sloc, scommand):
def parse_close(self, text, start, tagre, stag, sloc, scommand
, sa
):
while 1:
l=tagre.search(text,start)
if l < 0: self.parse_error('No closing tag', stag, text, sloc)
try: tag, args, command, coname= self.parseTag(tagre,scommand)
try: tag, args, command, coname= self.parseTag(tagre,scommand
,sa
)
except ParseError, m: self.parse_error(m[0],m[1], text, l)
start=l+len(tag)
if command:
if hasattr(command, 'blockContinuations'):
# New open tag. Need to find closing tag.
start=self.parse_close(text, start, tagre, tag, l, command)
start=self.parse_close(text, start, tagre, tag, l,
command,args)
elif not coname: return start
shared_globals={}
...
...
lib/python/DocumentTemplate/DT_Util.py
View file @
8456e516
'''$Id: DT_Util.py,v 1.
1 1997/08/27 18:55:43
jim Exp $'''
'''$Id: DT_Util.py,v 1.
2 1997/09/02 20:35:09
jim Exp $'''
############################################################################
# Copyright
...
...
@@ -52,7 +52,7 @@
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
import
sys
,
regex
,
string
,
types
,
math
,
os
from
string
import
rfind
,
strip
,
joinfields
,
atoi
,
lower
,
upper
,
capitalize
...
...
@@ -133,7 +133,9 @@ def parse_params(text,
l=len(unparmre.group(1))
if result.has_key(''):
if parms.has_key(name): result[name]=parms[name]
else: raise InvalidParameter, name
else: raise ParseError, (
'
Invalid
parameter
name
,
%
s
<
!
--%
s
-->
<
!
--
u
-->
'
% (name, text))
else:
result['']=name
return apply(parse_params,(text[l:],result),parms)
...
...
@@ -141,7 +143,8 @@ def parse_params(text,
if not text or not strip(text): return result
raise InvalidParameter, text
if not parms.has_key(name): raise ParseError, name
if not parms.has_key(name):
raise ParseError, '
Invalid
parameter
name
,
%
s
<
!
--%
s
-->
' % (name, text)
result[name]=value
...
...
@@ -154,6 +157,9 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
############################################################################
# $Log: DT_Util.py,v $
# Revision 1.2 1997/09/02 20:35:09 jim
# Various fixes to parsing code.
#
# Revision 1.1 1997/08/27 18:55:43 jim
# initial
#
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