DSM

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • page templates and "python:"

    13 answers - 569 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi,
    what does exactly happen when I use "python:" into a zpt?
    Is it a problem if I have many "python:" in my page templates?
    What are the differences in performances of these two definitions?
    <metal:block tal:define="my_value my_object/getValue"></metal:block>
    <metal:block tal:define="my_value
    python:my_object.getValue()"></metal:block>
    thank you very much
    claudio :-)
    Zope maillist - Zope (AT) zope (DOT) org
    ** No cross posts or HTML encoding! **
    (Related lists -
    )
  • No.1 | | 1038 bytes | |

    3. Juli 2006 15:05:36 +0200 Claudio Battaglino
    <c.battaglino (AT) metaware (DOT) itwrote:

    Hi,
    what does exactly happen when I use "python:" into a zpt?
    Is it a problem if I have many "python:" in my page templates?
    What are the differences in performances of these two definitions?

    Talking of performanceyou might write a benchmark to figure it out
    no idea

    <metal:block tal:define="my_value my_object/getValue"></metal:block>

    <metal:block tal:define="my_value
    python:my_object.getValue()"></metal:block>

    The main difference between both variants is that in path expressions
    getValue can be either an attribute or a methodso at least path
    expressions may have some overheadyou have to measure it.
    -aj

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )

    PGP SIGNATURE
    Version: GnuPG v1.4.3 (Darwin)

    9KIKxHW1YXkL6X28rg7CWY=
    =ngc7
    PGP SIGNATURE
  • No.2 | | 1109 bytes | |

    PGP SIGNED MESSAGE
    Hash: SHA1

    3 Jul 2006, at 15:09, Andreas Jung wrote:

    >>

    ><metal:block tal:define="my_value my_object/getValue"></
    >metal:block>
    >>

    ><metal:block tal:define="my_value
    >python:my_object.getValue()"></metal:block>
    >>

    >

    The main difference between both variants is that in path
    expressions getValue can be either an attribute or a methodso at
    least path expressions may have some overheadyou have to measure
    it.

    As far as I know path expressions have better performance. I don't
    have the in-depth expression engine knowledge to explain why, but
    that's been what everyone has said to me before.

    jens

    PGP SIGNATURE
    Version: GnuPG v1.4.1 (Darwin)

    b16sWokKTRVrWo4BtvRGVhg=
    =tt4I
    PGP SIGNATURE

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.3 | | 1200 bytes | |

    Jens Vagelpohl ha scritto:

    PGP SIGNED MESSAGE
    Hash: SHA1
    --
    3 Jul 2006, at 15:09, Andreas Jung wrote:

    <metal:block tal:define="my_value my_object/getValue"></
    metal:block>

    <metal:block tal:define="my_value
    python:my_object.getValue()"></metal:block>

    >>

    >The main difference between both variants is that in path expressions
    >getValue can be either an attribute or a methodso at least path
    >expressions may have some overheadyou have to measure it.
    >
    >

    As far as I know path expressions have better performance. I don't
    have the in-depth expression engine knowledge to explain why, but
    that's been what everyone has said to me before.

    jens
    --
    Could it be that, using a Python expression, I have an overhead because
    Zope loads a Python interpreter each time it finds a "python:"?
    If this is true then it is better to use path expression, if possible.

    claudio :-)

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.4 | | 931 bytes | |

    3. Juli 2006 15:38:58 +0200 Claudio Battaglino
    <c.battaglino (AT) metaware (DOT) itwrote:

    Jens Vagelpohl ha scritto:
    >>

    Could it be that, using a Python expression, I have an overhead because
    Zope loads a Python interpreter each time it finds a "python:"?
    If this is true then it is better to use path expression, if possible.

    nahPython expression are executed in a sandbox (RestrictedPython) which
    will introduce additional overheadbut let numbers speakwrite a loop in
    TAL and compare the performance of path expressions vs. python
    expressions don't guess, but measure
    -aj

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )

    PGP SIGNATURE
    Version: GnuPG v1.4.3 (Darwin)

    6rsyWGqvQXPAnXzdnxqt/k=
    =a7eK
    PGP SIGNATURE
  • No.5 | | 802 bytes | |

    Claudio Battaglino schrieb:
    Hi,
    what does exactly happen when I use "python:" into a zpt?
    Is it a problem if I have many "python:" in my page templates?

    Path expressions are by far better human readable IMH I try very hard
    to avoid Python expressions if possible.

    To give you an example:

    I prefer

    <option tal:attributes="selected item/selected"

    over

    <option tal:attributes="python: test(foo == bar, 'selected', None)"

    But also because in the first example the template doesn't need to
    know about implementation details and thus it is better reusable e.g. as
    macro.

    Tonico

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.6 | | 817 bytes | |

    3. Juli 2006 15:50:41 +0200 Tonico Strasser <contact_tonico (AT) yahoo (DOT) de
    wrote:

    Claudio Battaglino schrieb:
    >Hi,
    >what does exactly happen when I use "python:" into a zpt?
    >Is it a problem if I have many "python:" in my page templates?
    >

    Path expressions are by far better human readable IMH I try very hard
    to avoid Python expressions if possible.

    (Un)fortunately we live a in world where methods may have parameters. Path
    expressions work only for parameter-less methods.
    -aj

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )

    PGP SIGNATURE
    Version: GnuPG v1.4.3 (Darwin)

    VlRMTElo4LFFHa8RKvE6g4w=
    =2CAQ
    PGP SIGNATURE
  • No.7 | | 357 bytes | |

    Small correction

    <option tal:attributes="python: test(foo == bar, 'selected', None)"

    Should be:

    <option tal:attributes="selected python: test(foo == bar, 'selected',
    None)"

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.8 | | 1263 bytes | |

    Andreas Jung schrieb:

    3. Juli 2006 15:50:41 +0200 Tonico Strasser
    <contact_tonico (AT) yahoo (DOT) dewrote:

    >Claudio Battaglino schrieb:

    Hi,
    what does exactly happen when I use "python:" into a zpt?
    Is it a problem if I have many "python:" in my page templates?
    >>

    >Path expressions are by far better human readable IMH I try very hard
    >to avoid Python expressions if possible.


    (Un)fortunately we live a in world where methods may have parameters.
    Path expressions work only for parameter-less methods.

    This can be avoided if you "prepare" a namespace and pass it to the
    template, this way the template doesn't need to call methods.

    I've written a simple page class for doing this, but it's also possible
    TTW from a Python script:

    names = {'foo': 'bar'}
    template = context.a_page_template
    return template.pt_render(extra_context=names)

    course you can still use Python expressions if needed.

    Tonico

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.9 | | 1555 bytes | |

    Actually, I think python: expressions perform slightly better than
    their path: counterparts because their evaluation step needs to do
    less work (no guessing about getitem vs. getattr). Geoff Davis
    taught me that. But in the end it's all dwarfed by the penalty
    imposed by security, so it really doesn't much matter.

    Jul 3, 2006, at 9:20 AM, Jens Vagelpohl wrote:

    PGP SIGNED MESSAGE
    Hash: SHA1
    --
    3 Jul 2006, at 15:09, Andreas Jung wrote:

    <metal:block tal:define="my_value my_object/getValue"></
    metal:block>

    <metal:block tal:define="my_value
    python:my_object.getValue()"></metal:block>

    >>

    >The main difference between both variants is that in path
    >expressions getValue can be either an attribute or a methodso
    >at least path expressions may have some overheadyou have to
    >measure it.
    >

    As far as I know path expressions have better performance. I don't
    have the in-depth expression engine knowledge to explain why, but
    that's been what everyone has said to me before.

    jens
    --
    PGP SIGNATURE
    Version: GnuPG v1.4.1 (Darwin)

    b16sWokKTRVrWo4BtvRGVhg=
    =tt4I
    PGP SIGNATURE

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists
    )

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.10 | | 782 bytes | |

    7/3/06, Chris McDonough <chrism (AT) plope (DOT) comwrote:
    Actually, I think python: expressions perform slightly better than
    their path: counterparts because their evaluation step needs to do
    less work (no guessing about getitem vs. getattr). Geoff Davis
    taught me that. But in the end it's all dwarfed by the penalty
    imposed by security, so it really doesn't much matter.

    Right. So the best and quickest is to prepare all the data in pure
    disk-based python.
    It's easy to do if you use the view methodology you get with Five, but
    there are other ways to do it if you don't want to use views.

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.11 | | 2184 bytes | |

    Andreas Jung ha scritto:

    --
    3. Juli 2006 15:38:58 +0200 Claudio Battaglino
    <c.battaglino (AT) metaware (DOT) itwrote:
    >
    >Jens Vagelpohl ha scritto:
    >>


    >Could it be that, using a Python expression, I have an overhead because
    >Zope loads a Python interpreter each time it finds a "python:"?
    >If this is true then it is better to use path expression, if possible.
    >>

    >

    nahPython expression are executed in a sandbox (RestrictedPython)
    which will introduce additional overheadbut let numbers
    speakwrite a loop in TAL and compare the performance of path
    expressions vs. python expressions don't guess, but measure

    -aj

    It seems that the Python Expression works a bit better:

    To the test this, I used these two Page Templates and PTProfiler:

    PATH EXPRESSIN
    <div tal:define="test_user " tal:repeat="counter python:range(5000)">
    <span tal:content="test_user/getId" />
    </div>

    PYTHN EXPRESSIN
    <div tal:define="test_user " tal:repeat="counter python:range(5000)">
    <span tal:content="python: test_user.getId()" />
    </div>

    PATH EXPRESSIN
    Expression - Total time - Number of calls - Time per call
    path: test_user/getId 0.72 5000 0.00014
    path: test_user/getId 0.63 5000 0.00013
    path: test_user/getId 0.72 5000 0.00014

    path: test_user/getId 4.0 50000 8e-05
    path: test_user/getId4.09500008e-05
    path: test_user/getId 4.12 50000 8e-05

    PYTHN EXPRESSIN
    Expression - Total time - Number of calls - Time per call
    python: test_user.getId() 0.6 5000 0.00012
    python: test_user.getId() 0.51 5000 0.0001
    python: test_user.getId() 0.48 5000 0.0001
    python: test_user.getId() 3.19 50000 6e-05
    python: test_user.getId() 3.42 50000 7e-05
    python: test_user.getId() 2.96 50000 6e-05

    Is it a significant test?

    claudio :-)

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.12 | | 2258 bytes | |

    PGP SIGNED MESSAGE
    Hash: SHA1

    Lennart Regebro wrote:
    7/3/06, Chris McDonough
    <chrism (AT) plope (DOT) comwrote:
    >Actually, I think python: expressions perform slightly better than
    >their path: counterparts because their evaluation step needs to do
    >less work (no guessing about getitem vs. getattr). Geoff Davis
    >taught me that. But in the end it's all dwarfed by the penalty
    >imposed by security, so it really doesn't much matter.


    Right. So the best and quickest is to prepare all the data in pure
    disk-based python.
    It's easy to do if you use the view methodology you get with Five, but
    there are other ways to do it if you don't want to use views.

    My 'pushpage' package is an attempt to make this the "standard" pattern
    (pushpage templates don't have *any* top-level names available to them
    (i.e., 'context', 'container', 'request', etc.) except those passed to
    their '__call__' as keyword arguments (which traditional ZPT exposes
    under 'options'):

    The templates can be used from within methods of view classes, and can
    also be published as "pages" via ZCML with the help of a user-defined
    callable which computes the keyword arguments. E.g.:

    <pushpage:view
    for=""
    name="somepage.html"
    permission="zope.Public"
    template="templates/sometemplate.pt"
    mapping=".somemodule,somefunction"
    layer="mylayer"
    />

    In this example, 'somemodule.somefunction' returns the mapping which
    'sometemplate' will use as its top-level namespace. The callable is
    passed 'context' and 'request' as arguments.

    Tres.
    - --
    Tres Seaver +1 202-558-7113 tseaver (AT) palladion (DOT) com
    Palladion Software "Excellence by Design" http://palladion.com
    PGP SIGNATURE
    Version: GnuPG v1.4.2.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    gN4Q7fIm63hA4HUoViIwdBk=
    =2aTX
    PGP SIGNATURE

    Zope maillist - Zope (AT) zope (DOT) org

    ** No cross posts or HTML encoding! **
    (Related lists -

    )
  • No.13 | | 248 bytes | |

    7/3/06, Claudio Battaglino <c.battaglino (AT) metaware (DOT) itwrote:
    Is it a significant test?
    Yes, for the use case of in-memory objects and methods.
    You might want to do the same with a traversal path
    , or something, and then

Re: page templates and "python:"


max 4000 letters.
Your nickname that display:
In order to stop the spam: 9 + 8 =
QUESTION ON "DSM"

EMSDN.COM