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
44f1fd05
Commit
44f1fd05
authored
Mar 01, 2006
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- refactored Engine and moved it out from Five
- translation service needs to be rehooked
parent
0fc2910b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
0 deletions
+106
-0
lib/python/Products/PageTemplates/Engine.py
lib/python/Products/PageTemplates/Engine.py
+95
-0
lib/python/Products/PageTemplates/PageTemplateFile.py
lib/python/Products/PageTemplates/PageTemplateFile.py
+5
-0
lib/python/Products/PageTemplates/ZopePageTemplate.py
lib/python/Products/PageTemplates/ZopePageTemplate.py
+6
-0
No files found.
lib/python/Products/PageTemplates/Engine.py
0 → 100644
View file @
44f1fd05
# Common Engine for Zope3-ZPT-in-Zope-2
from
zope.tales.tales
import
ExpressionEngine
from
zope.tales.expressions
import
PathExpr
,
StringExpr
,
NotExpr
,
DeferExpr
,
SubPathExpr
from
zope.tales.expressions
import
SimpleModuleImporter
,
_marker
from
zope.tales.pythonexpr
import
PythonExpr
from
zope.tales.tales
import
_valid_name
,
_parse_expr
,
NAME_RE
,
Undefined
def
BoboTraverseAwareSimpleTraverse
(
object
,
path_items
,
econtext
):
""" a slightly modified version of zope.tales.expressions.simpleTraverse()
that interacts correctly with objects implementing bobo_traverse().
"""
for
name
in
path_items
:
next
=
getattr
(
object
,
name
,
_marker
)
if
next
is
not
_marker
:
object
=
next
else
:
try
:
object
=
object
.
restrictedTraverse
(
name
)
except
(
KeyError
,
AttributeError
):
try
:
object
=
object
[
name
]
except
:
object
=
getattr
(
object
,
name
)
return
object
class
PathExpr
(
PathExpr
):
"""We need to subclass PathExpr at this point since there is no other
away to pass our own traverser because we do not instantiate
PathExpr on our own...this sucks!
"""
def
__init__
(
self
,
name
,
expr
,
engine
,
traverser
=
BoboTraverseAwareSimpleTraverse
):
self
.
_s
=
expr
self
.
_name
=
name
paths
=
expr
.
split
(
'|'
)
self
.
_subexprs
=
[]
add
=
self
.
_subexprs
.
append
for
i
in
range
(
len
(
paths
)):
path
=
paths
[
i
].
lstrip
()
if
_parse_expr
(
path
):
# This part is the start of another expression type,
# so glue it back together and compile it.
add
(
engine
.
compile
(
'|'
.
join
(
paths
[
i
:]).
lstrip
()))
break
add
(
SubPathExpr
(
path
,
traverser
,
engine
).
_eval
)
from
zope.tales.tales
import
Context
from
zope.i18n
import
translate
class
Context
(
Context
):
def
translate
(
self
,
msgid
,
domain
=
None
,
mapping
=
None
,
default
=
None
):
# fix that
return
msgid
# return translate(msgid, domain, mapping,
# context=context, default=default)
class
ExpressionEngine
(
ExpressionEngine
):
def
getContext
(
self
,
contexts
=
None
,
**
kwcontexts
):
if
contexts
is
not
None
:
if
kwcontexts
:
kwcontexts
.
update
(
contexts
)
else
:
kwcontexts
=
contexts
return
Context
(
self
,
kwcontexts
)
def
Engine
():
e
=
ExpressionEngine
()
reg
=
e
.
registerType
for
pt
in
PathExpr
.
_default_type_names
:
reg
(
pt
,
PathExpr
)
reg
(
'string'
,
StringExpr
)
reg
(
'python'
,
PythonExpr
)
reg
(
'not'
,
NotExpr
)
reg
(
'defer'
,
DeferExpr
)
e
.
registerBaseName
(
'modules'
,
SimpleModuleImporter
())
return
e
Engine
=
Engine
()
lib/python/Products/PageTemplates/PageTemplateFile.py
View file @
44f1fd05
...
...
@@ -32,6 +32,8 @@ from Shared.DC.Scripts.Script import Script
from
OFS.SimpleItem
import
Item_w__name__
from
Shared.DC.Scripts.Signature
import
FuncCode
from
Engine
import
Engine
class
PageTemplateFile
(
SimpleItem
,
Script
,
PT
,
Traversable
):
""" A Zope 2-aware wrapper class around the Zope 3 ZPT
...
...
@@ -86,6 +88,9 @@ class PageTemplateFile(SimpleItem, Script, PT, Traversable):
self
.
pt_edit
(
content
,
guess_type
(
filename
,
content
))
def
pt_getEngine
(
self
):
return
Engine
def
pt_getContext
(
self
):
root
=
self
.
getPhysicalRoot
()
context
=
self
.
_getContext
()
...
...
lib/python/Products/PageTemplates/ZopePageTemplate.py
View file @
44f1fd05
...
...
@@ -38,6 +38,8 @@ from webdav.WriteLockInterface import WriteLockInterface
from
zope.pagetemplate.pagetemplate
import
PageTemplate
from
zope.pagetemplate.pagetemplatefile
import
sniff_type
from
Engine
import
Engine
# regular expression to extract the encoding from the XML preamble
encoding_reg
=
re
.
compile
(
'<
\
?xml.*?e
n
coding="(.*?)".*?
\
?>
'
, re.M)
...
...
@@ -175,6 +177,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
self.ZCacheable_invalidate()
def pt_getEngine(self):
return Engine
security.declareProtected(change_page_templates, '
pt_upload
')
def pt_upload(self, REQUEST, file='', encoding='
utf
-
8
'):
"""Replace the document with the text in file."""
...
...
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