Skip to content

Commit

Permalink
Fixed behavior of pipe character in Python expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed May 11, 2011
1 parent bcbae1b commit 38fb86a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
=========

In next release...

- Python-expressions are no longer TALES-expressions; previously, the
pipe operator would split Python expression clauses, allowing
fallbacks even for Python expressions, but this is not the standard
behavior of ZPT.

- Fixed an issue where an error which occurred inside a dynamic
``path`` or ``exists`` evaluation would fail to propagate due to a
missing remote context.

- Set variables ``here`` and ``context`` to the bound instance value
on ``PageTemplate`` instances.

2.0-rc2 (2011-03-24)
~~~~~~~~~~~~~~~~~~~~

Expand Down
11 changes: 10 additions & 1 deletion src/z3c/pt/expressions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ast
import re
import ast
import namespaces
import zope.event

Expand All @@ -17,6 +17,7 @@

from chameleon.tales import PathExpr as BasePathExpr
from chameleon.tales import ExistsExpr as BaseExistsExpr
from chameleon.tales import PythonExpr as BasePythonExpr
from chameleon.codegen import template
from chameleon.astutil import load
from chameleon.astutil import Symbol
Expand Down Expand Up @@ -212,3 +213,11 @@ def __call__(self, target, engine):
traverse=self.traverser,
name=ast.Str(string),
)


class PythonExpr(BasePythonExpr):
def __init__(self, expression):
self.expression = expression

def __call__(self, target, engine):
return self.translate(self.expression, target)
3 changes: 1 addition & 2 deletions src/z3c/pt/pagetemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from chameleon.i18n import fast_translate
from chameleon.zpt import template
from chameleon.tales import PythonExpr
from chameleon.tales import StringExpr
from chameleon.tales import NotExpr
from chameleon.nodes import Assignment
Expand Down Expand Up @@ -59,7 +58,7 @@ class BaseTemplate(template.PageTemplate):
registry = DummyRegistry()

expression_types = {
'python': PythonExpr,
'python': expressions.PythonExpr,
'string': StringExpr,
'not': NotExpr,
'exists': expressions.ExistsExpr,
Expand Down
4 changes: 4 additions & 0 deletions src/z3c/pt/tests/path.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div tal:define="editor options/editor"
tal:condition="python: path('nocall:here/%s_wysiwyg_support|here/%s/wysiwyg_support|here/portal_skins/plone_wysiwyg/wysiwyg_support' % (editor, editor))">
WYSWIWYG supported.
</div>
13 changes: 13 additions & 0 deletions src/z3c/pt/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ def dont_call():
result = template(callable=dont_call)
self.failUnless('ok' in result)

def test_path(self):
from z3c.pt.pagetemplate import PageTemplateFile
template = PageTemplateFile("path.pt")

class Context(object):
dummy_wysiwyg_support = True

context = Context()
template = template.__get__(context, Context)

result = template(editor="dummy")
self.failUnless("supported" in result)


def test_suite():
import sys
Expand Down

0 comments on commit 38fb86a

Please sign in to comment.