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
616dbe2c
Commit
616dbe2c
authored
Sep 25, 2001
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced string module function calls by string method calls.
DTML stuff is now roughly 8-10% faster.
parent
8423054e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
46 deletions
+38
-46
lib/python/DocumentTemplate/DT_HTML.py
lib/python/DocumentTemplate/DT_HTML.py
+20
-24
lib/python/DocumentTemplate/DT_Return.py
lib/python/DocumentTemplate/DT_Return.py
+1
-2
lib/python/DocumentTemplate/DT_String.py
lib/python/DocumentTemplate/DT_String.py
+3
-4
lib/python/DocumentTemplate/DT_Try.py
lib/python/DocumentTemplate/DT_Try.py
+2
-2
lib/python/DocumentTemplate/DT_Var.py
lib/python/DocumentTemplate/DT_Var.py
+9
-10
lib/python/DocumentTemplate/pDocumentTemplate.py
lib/python/DocumentTemplate/pDocumentTemplate.py
+3
-4
No files found.
lib/python/DocumentTemplate/DT_HTML.py
View file @
616dbe2c
...
...
@@ -84,12 +84,11 @@
##############################################################################
"""HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.
29 2001/05/25 11:34:56 andreas
Exp $"""
$Id: DT_HTML.py,v 1.
30 2001/09/25 13:37:02 andreasjung
Exp $"""
from
DT_String
import
String
,
FileMixin
import
DT_String
,
re
from
DT_Util
import
ParseError
,
str
from
string
import
strip
,
find
,
split
,
join
,
rfind
,
replace
class
dtml_re_class
:
""" This needs to be replaced before 2.4. It's a hackaround. """
...
...
@@ -98,9 +97,6 @@ class dtml_re_class:
end_match
=
re
.
compile
(
'[
\
000
- ]*(/|end)'
,
re
.
I
).
match
,
start_search
=
re
.
compile
(
'[<&]'
).
search
,
ent_name
=
re
.
compile
(
'[-a-zA-Z0-9_.]+'
).
match
,
find
=
find
,
strip
=
strip
,
replace
=
replace
,
):
while
1
:
...
...
@@ -109,23 +105,23 @@ class dtml_re_class:
s
=
mo
.
start
(
0
)
if
text
[
s
:
s
+
5
]
==
'<!--#'
:
n
=
s
+
5
e
=
find
(
text
,
'-->'
,
n
)
e
=
text
.
find
(
'-->'
,
n
)
if
e
<
0
:
return
None
en
=
3
mo
=
end_match
(
text
,
n
)
if
mo
is
not
None
:
l
=
mo
.
end
(
0
)
-
mo
.
start
(
0
)
end
=
strip
(
text
[
n
:
n
+
l
]
)
end
=
text
[
n
:
n
+
l
].
strip
(
)
n
=
n
+
l
else
:
end
=
''
elif
text
[
s
:
s
+
6
]
==
'<dtml-'
:
e
=
n
=
s
+
6
while
1
:
e
=
find
(
text
,
'>'
,
e
+
1
)
e
=
text
.
find
(
'>'
,
e
+
1
)
if
e
<
0
:
return
None
if
len
(
split
(
text
[
n
:
e
],
'"'
))
%
2
:
if
len
(
text
[
n
:
e
].
split
(
'"'
))
%
2
:
# check for even number of "s inside
break
...
...
@@ -135,9 +131,9 @@ class dtml_re_class:
elif
text
[
s
:
s
+
7
]
==
'</dtml-'
:
e
=
n
=
s
+
7
while
1
:
e
=
find
(
text
,
'>'
,
e
+
1
)
e
=
text
.
find
(
'>'
,
e
+
1
)
if
e
<
0
:
return
None
if
len
(
split
(
text
[
n
:
e
],
'"'
))
%
2
:
if
len
(
text
[
n
:
e
].
split
(
'"'
))
%
2
:
# check for even number of "s inside
break
...
...
@@ -147,7 +143,7 @@ class dtml_re_class:
else
:
if
text
[
s
:
s
+
5
]
==
'&dtml'
and
text
[
s
+
5
]
in
'.-'
:
n
=
s
+
6
e
=
find
(
text
,
';'
,
n
)
e
=
text
.
find
(
';'
,
n
)
if
e
>=
0
:
args
=
text
[
n
:
e
]
l
=
len
(
args
)
...
...
@@ -163,13 +159,13 @@ class dtml_re_class:
self
.
_start
=
s
return
self
else
:
nn
=
find
(
args
,
'-'
)
nn
=
args
.
find
(
'-'
)
if
nn
>=
0
and
nn
<
l
-
1
:
d
[
1
]
=
d
[
'end'
]
=
''
d
[
2
]
=
d
[
'name'
]
=
'var'
d
[
0
]
=
text
[
s
:
e
+
1
]
args
=
(
args
[
nn
+
1
:]
+
' '
+
replace
(
args
[:
nn
],
'.'
,
' '
)
)
args
=
args
[
nn
+
1
:]
+
' '
+
\
args
[:
nn
].
replace
(
'.'
,
' '
)
d
[
3
]
=
d
[
'args'
]
=
args
self
.
_start
=
s
return
self
...
...
@@ -184,9 +180,9 @@ class dtml_re_class:
l
=
mo
.
end
(
0
)
-
mo
.
start
(
0
)
a
=
n
+
l
name
=
strip
(
text
[
n
:
a
]
)
name
=
text
[
n
:
a
].
strip
(
)
args
=
strip
(
text
[
a
:
e
]
)
args
=
text
[
a
:
e
].
strip
(
)
d
=
self
.
__dict__
d
[
0
]
=
text
[
s
:
e
+
en
]
...
...
@@ -238,7 +234,7 @@ class HTML(DT_String.String):
or None otherwise
"""
tag
,
end
,
name
,
args
=
match_ob
.
group
(
0
,
'end'
,
'name'
,
'args'
)
args
=
strip
(
args
)
args
=
args
.
strip
(
)
if
end
:
if
not
command
or
name
!=
command
.
name
:
raise
ParseError
,
(
'unexpected end tag'
,
tag
)
...
...
@@ -282,7 +278,7 @@ class HTML(DT_String.String):
((
'"'
),
'"'
))):
#"
if
text
is
None
:
text
=
self
.
read_raw
()
for
re
,
name
in
character_entities
:
if
find
(
text
,
re
)
>=
0
:
text
=
join
(
split
(
text
,
re
),
name
)
if
text
.
find
(
re
)
>=
0
:
text
=
name
.
join
(
text
.
split
(
re
)
)
return
text
errQuote__roles__
=
()
...
...
@@ -327,7 +323,7 @@ class HTMLDefault(HTML):
def
manage_edit
(
self
,
data
,
PARENTS
,
URL1
,
REQUEST
):
'edit a template'
newHTML
=
self
.
copy_class
(
data
,
self
.
globals
,
self
.
__name__
)
setattr
(
PARENTS
[
1
],
URL1
[
rfind
(
URL1
,
'/'
)
+
1
:],
newHTML
)
setattr
(
PARENTS
[
1
],
URL1
[
URL1
.
rfind
(
'/'
)
+
1
:],
newHTML
)
return
self
.
editConfirmation
(
self
,
REQUEST
)
...
...
@@ -375,9 +371,9 @@ class HTMLFile(FileMixin, HTML):
PARENTS
=
[],
URL1
=
''
,
URL2
=
''
,
REQUEST
=
''
,
SUBMIT
=
''
):
'edit a template'
if
SUBMIT
==
FactoryDefaultString
:
return
self
.
manage_default
(
REQUEST
)
if
find
(
data
,
'
\
r
'
):
data
=
join
(
split
(
data
,
'
\
r
\
n
'
),
'
\
n
\
r
'
)
data
=
join
(
split
(
data
,
'
\
n
\
r
'
),
'
\
n
'
)
if
data
.
find
(
'
\
r
'
):
data
=
'
\
n
\
r
'
.
join
(
data
.
split
(
'
\
r
\
n
'
)
)
data
=
'
\
n
'
.
join
(
data
.
split
(
'
\
n
\
r
'
)
)
if
self
.
edited_source
:
self
.
edited_source
=
data
...
...
@@ -387,5 +383,5 @@ class HTMLFile(FileMixin, HTML):
newHTML
=
self
.
__class__
()
newHTML
.
__setstate__
(
self
.
__getstate__
())
newHTML
.
edited_source
=
data
setattr
(
PARENTS
[
1
],
URL1
[
rfind
(
URL1
,
'/'
)
+
1
:],
newHTML
)
setattr
(
PARENTS
[
1
],
URL1
[
URL1
.
rfind
(
'/'
)
+
1
:],
newHTML
)
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
lib/python/DocumentTemplate/DT_Return.py
View file @
616dbe2c
...
...
@@ -82,11 +82,10 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
4
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
str
import
string
,
sys
from
string
import
find
,
split
,
join
,
atoi
,
rfind
class
ReturnTag
:
name
=
'return'
...
...
lib/python/DocumentTemplate/DT_String.py
View file @
616dbe2c
...
...
@@ -82,9 +82,8 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
"$Id: DT_String.py,v 1.4
7 2001/09/04 13:46:43 evan
Exp $"
"$Id: DT_String.py,v 1.4
8 2001/09/25 13:37:02 andreasjung
Exp $"
from
string
import
split
,
strip
import
thread
,
re
,
exceptions
,
os
from
DT_Util
import
ParseError
,
InstanceDict
,
TemplateDict
,
render_blocks
,
str
...
...
@@ -129,7 +128,7 @@ class String:
parse_error__roles__
=
()
def
parse_error
(
self
,
mess
,
tag
,
text
,
start
):
raise
ParseError
,
"%s, for tag %s, on line %s of %s<p>"
%
(
mess
,
self
.
errQuote
(
tag
),
len
(
split
(
text
[:
start
],
'
\
n
'
)),
mess
,
self
.
errQuote
(
tag
),
len
(
text
[:
start
].
split
(
'
\
n
'
)),
self
.
errQuote
(
self
.
__name__
))
commands__roles__
=
()
...
...
@@ -192,7 +191,7 @@ class String:
or None otherwise
"""
tag
,
name
,
args
,
fmt
=
match_ob
.
group
(
0
,
'name'
,
'args'
,
'fmt'
)
args
=
args
and
strip
(
args
)
or
''
args
=
args
and
args
.
strip
(
)
or
''
if
fmt
==
']'
:
if
not
command
or
name
!=
command
.
name
:
...
...
lib/python/DocumentTemplate/DT_Try.py
View file @
616dbe2c
...
...
@@ -196,9 +196,9 @@ class Try:
'The else block should be the last block '
'in a try tag'
,
self
.
name
)
for
errname
in
string
.
split
(
nargs
):
for
errname
in
nargs
.
split
(
):
self
.
handlers
.
append
((
errname
,
nsection
.
blocks
))
if
string
.
strip
(
nargs
)
==
''
:
if
nargs
.
split
(
)
==
''
:
if
defaultHandlerFound
:
raise
ParseError
,
(
'Only one default exception handler '
...
...
lib/python/DocumentTemplate/DT_Var.py
View file @
616dbe2c
...
...
@@ -217,12 +217,11 @@ Evaluating expressions without rendering results
'''
# '
__rcs_id__
=
'$Id: DT_Var.py,v 1.4
2 2001/07/12 20:04:01 andreas
Exp $'
__version__
=
'$Revision: 1.4
2
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_Var.py,v 1.4
3 2001/09/25 13:37:02 andreasjung
Exp $'
__version__
=
'$Revision: 1.4
3
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
str
import
re
,
string
,
sys
from
string
import
find
,
split
,
join
,
atoi
,
rfind
from
urllib
import
quote
,
quote_plus
from
cgi
import
escape
from
html_quote
import
html_quote
# for import by other modules, dont remove!
...
...
@@ -330,7 +329,7 @@ class Var:
tag with a non-integer value.'''
)
if
len
(
val
)
>
size
:
val
=
val
[:
size
]
l
=
rfind
(
val
,
' '
)
l
=
val
.
rfind
(
' '
)
if
l
>
size
/
2
:
val
=
val
[:
l
+
1
]
if
have_arg
(
'etc'
):
l
=
args
[
'etc'
]
...
...
@@ -362,8 +361,8 @@ def url_quote_plus(v, name='(Unknown name)', md={}):
def
newline_to_br
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
v
=
str
(
v
)
if
find
(
v
,
'
\
r
'
)
>=
0
:
v
=
join
(
split
(
v
,
'
\
r
'
),
''
)
if
find
(
v
,
'
\
n
'
)
>=
0
:
v
=
join
(
split
(
v
,
'
\
n
'
),
'<br>
\
n
'
)
if
v
.
find
(
'
\
r
'
)
>=
0
:
v
=
''
.
join
(
v
.
split
(
'
\
r
'
)
)
if
v
.
find
(
'
\
n
'
)
>=
0
:
v
=
'<br>
\
n
'
.
join
(
v
.
split
(
'
\
n
'
)
)
return
v
def
whole_dollars
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
...
...
@@ -378,11 +377,11 @@ def thousands_commas(v, name='(Unknown name)', md={},
thou
=
re
.
compile
(
r"([0-9])([0-9][0-9][0-9]([,.]|$))"
).
search
):
v
=
str
(
v
)
vl
=
split
(
v
,
'.'
)
vl
=
v
.
split
(
'.'
)
if
not
vl
:
return
v
v
=
vl
[
0
]
del
vl
[
0
]
if
vl
:
s
=
'.'
+
join
(
vl
,
'.'
)
if
vl
:
s
=
'.'
+
'.'
.
join
(
vl
)
else
:
s
=
''
mo
=
thou
(
v
)
while
mo
is
not
None
:
...
...
@@ -419,7 +418,7 @@ def sql_quote(v, name='(Unknown name)', md={}):
This is needed to securely insert values into sql
string literals in templates that generate sql.
"""
if
find
(
v
,
"'"
)
>=
0
:
return
join
(
split
(
v
,
"'"
),
"''"
)
if
v
.
find
(
"'"
)
>=
0
:
return
"''"
.
join
(
v
.
split
(
"'"
)
)
return
v
special_formats
=
{
...
...
@@ -440,7 +439,7 @@ special_formats={
}
def
spacify
(
val
):
if
find
(
val
,
'_'
)
>=
0
:
val
=
join
(
split
(
val
,
'_'
))
if
val
.
find
(
'_'
)
>=
0
:
val
=
" "
.
join
(
val
.
split
(
'_'
))
return
val
modifiers
=
(
html_quote
,
url_quote
,
url_quote_plus
,
newline_to_br
,
...
...
lib/python/DocumentTemplate/pDocumentTemplate.py
View file @
616dbe2c
...
...
@@ -85,11 +85,10 @@
__doc__
=
'''Python implementations of document template some features
$Id: pDocumentTemplate.py,v 1.3
1 2001/06/21 19:43:44 shane
Exp $'''
__version__
=
'$Revision: 1.3
1
$'
[
11
:
-
2
]
$Id: pDocumentTemplate.py,v 1.3
2 2001/09/25 13:37:02 andreasjung
Exp $'''
__version__
=
'$Revision: 1.3
2
$'
[
11
:
-
2
]
import
string
,
sys
,
types
from
string
import
join
ClassTypes
=
[
types
.
ClassType
]
...
...
@@ -301,5 +300,5 @@ def render_blocks(blocks, md):
l
=
len
(
rendered
)
if
l
==
0
:
return
''
elif
l
==
1
:
return
rendered
[
0
]
return
join
(
rendered
,
''
)
return
''
.
join
(
rendered
)
return
rendered
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