Terse Syntax through External Methods

Discussion in 'Python' started by Jens, Jan 25, 2008.

  1. Jens

    Jens Guest

    Hello Everyone

    I'm newbie to Zope and i have a few questions regarding external
    methods. What i wan't to do
    is provide a terse syntax for converting urls to special tracking
    urls:

    <dtml-var "track('http://myurl/')">

    turns the provided url into something like

    http://host/tracking?url=http://myurl/

    in the output.

    i've been trying to use a external procedure like this.

    ## Script (Python) "track_link"
    ##bind container=container
    ##bind context=context
    ##bind namespace=_
    ##bind script=script
    ##bind subpath=traverse_subpath
    ##parameters=self,url
    ##title=track link
    ##
    return "%s%s" % (self.tracking_prefix, url_quote(url))

    This doesn't work because because the method doesn't have access to
    the environment. Obviously I don't wan't to pass everything explicitly
    into the function as this would defeat the purpose of the exercise,
    namely to provide a terse syntax.

    I have a background in other languages so I might be missing something
    conceptually with regard Zope and DTML.. Is there a better was of
    doing this, perhaps without using external methods? Currently im doing
    the following which isn't very elegant:

    in content document
    <a href="<dtml-let exturl="'http://www.mylink.com/"><dtml-var
    tracking></dtml-let>">link</a>
    ....
    tracking:
    <dtml-var tracking_prefix><dtml-var name="exturl" url_quote_plus>

    Appreciate any input you might have on this-
    Jens, Jan 25, 2008
    #1
    1. Advertising

  2. Jens schrieb:
    > Hello Everyone
    >
    > I'm newbie to Zope and i have a few questions regarding external
    > methods. What i wan't to do
    > is provide a terse syntax for converting urls to special tracking
    > urls:
    >
    > <dtml-var "track('http://myurl/')">
    >
    > turns the provided url into something like
    >
    > http://host/tracking?url=http://myurl/
    >
    > in the output.
    >
    > i've been trying to use a external procedure like this.
    >
    > ## Script (Python) "track_link"
    > ##bind container=container
    > ##bind context=context
    > ##bind namespace=_
    > ##bind script=script
    > ##bind subpath=traverse_subpath
    > ##parameters=self,url
    > ##title=track link
    > ##
    > return "%s%s" % (self.tracking_prefix, url_quote(url))
    >
    > This doesn't work because because the method doesn't have access to
    > the environment. Obviously I don't wan't to pass everything explicitly
    > into the function as this would defeat the purpose of the exercise,
    > namely to provide a terse syntax.
    >
    > I have a background in other languages so I might be missing something
    > conceptually with regard Zope and DTML.. Is there a better was of
    > doing this, perhaps without using external methods? Currently im doing
    > the following which isn't very elegant:
    >
    > in content document
    > <a href="<dtml-let exturl="'http://www.mylink.com/"><dtml-var
    > tracking></dtml-let>">link</a>
    > ...
    > tracking:
    > <dtml-var tracking_prefix><dtml-var name="exturl" url_quote_plus>
    >
    > Appreciate any input you might have on this-


    Is it really needed to use an external method for this, or isn't a
    "normal" python script enough already?

    If it has to be an External method, you can't access such a context
    AFAIK. But then you can create a python script that _has_ this context,
    and passese it to the external method. Not the nicest solution, but
    should work.

    Diez
    Diez B. Roggisch, Jan 25, 2008
    #2
    1. Advertising

  3. Jens

    Jens Guest

    On Jan 25, 3:19 pm, "Diez B. Roggisch" <> wrote:
    > Jens schrieb:
    >
    >
    >
    > > Hello Everyone

    >
    > > I'm newbie to Zope and i have a few questions regarding external
    > > methods. What i wan't to do
    > > is provide a terse syntax for converting urls to special tracking
    > > urls:

    >
    > > <dtml-var "track('http://myurl/')">

    >
    > > turns the provided url into something like

    >
    > >http://host/tracking?url=http://myurl/

    >
    > > in the output.

    >
    > > i've been trying to use a external procedure like this.

    >
    > > ## Script (Python) "track_link"
    > > ##bind container=container
    > > ##bind context=context
    > > ##bind namespace=_
    > > ##bind script=script
    > > ##bind subpath=traverse_subpath
    > > ##parameters=self,url
    > > ##title=track link
    > > ##
    > > return "%s%s" % (self.tracking_prefix, url_quote(url))

    >
    > > This doesn't work because because the method doesn't have access to
    > > the environment. Obviously I don't wan't to pass everything explicitly
    > > into the function as this would defeat the purpose of the exercise,
    > > namely to provide a terse syntax.

    >
    > > I have a background in other languages so I might be missing something
    > > conceptually with regard Zope and DTML.. Is there a better was of
    > > doing this, perhaps without using external methods? Currently im doing
    > > the following which isn't very elegant:

    >
    > > in content document
    > > <a href="<dtml-let exturl="'http://www.mylink.com/"><dtml-var
    > > tracking></dtml-let>">link</a>
    > > ...
    > > tracking:
    > > <dtml-var tracking_prefix><dtml-var name="exturl" url_quote_plus>

    >
    > > Appreciate any input you might have on this-

    >
    > Is it really needed to use an external method for this, or isn't a
    > "normal" python script enough already?
    >
    > If it has to be an External method, you can't access such a context
    > AFAIK. But then you can create a python script that _has_ this context,
    > and passese it to the external method. Not the nicest solution, but
    > should work.
    >
    > Diez


    Like I said i'm a newbie. I though the deal with Zope was that i
    couldn't really do inline scripting (for security reasons)
    like in php but had to use these external methods. how does one go
    about creating a "normal" python script exactly and
    how do I invoke it's functionality?
    Jens, Jan 29, 2008
    #3
  4. Jens a écrit :
    > On Jan 25, 3:19 pm, "Diez B. Roggisch" <> wrote:
    >> Jens schrieb:
    >>
    >>
    >>
    >>> Hello Everyone
    >>> I'm newbie to Zope and i have a few questions regarding external
    >>> methods.

    (snip)
    >>> This doesn't work because because the method doesn't have access to
    >>> the environment.


    >> If it has to be an External method, you can't access such a context
    >> AFAIK.


    IIRC, that's what the 'self' argument is for. Now I don't know if it
    will solve the OP's problem with dtml (which I avoid like pest).

    >> But then you can create a python script that _has_ this context,
    >> and passese it to the external method. Not the nicest solution, but
    >> should work.
    >>

    >
    > Like I said i'm a newbie. I though the deal with Zope was that i
    > couldn't really do inline scripting (for security reasons)
    > like in php but had to use these external methods. how does one go
    > about creating a "normal" python script exactly and
    > how do I invoke it's functionality?


    Zope (well... Zope2.x) has an object type named "Script (Python)". What
    you can do with them is restricted (for security reasons) but is
    obviously enough for what you want here. And really, you should *not*
    use dtml unless you have no other choice at all.

    Anyway: Zope is a world in itself, and most pythoneers don't use it. The
    Zope experts are mostly on the Zope's mailing list, so that's where you
    should post such questions.

    HTH
    Bruno Desthuilliers, Jan 29, 2008
    #4
  5. Jens schrieb:
    > On Jan 25, 3:19 pm, "Diez B. Roggisch" <> wrote:
    >> Jens schrieb:
    >>
    >>
    >>
    >>> Hello Everyone
    >>> I'm newbie to Zope and i have a few questions regarding external
    >>> methods. What i wan't to do
    >>> is provide a terse syntax for converting urls to special tracking
    >>> urls:
    >>> <dtml-var "track('http://myurl/')">
    >>> turns the provided url into something like
    >>> http://host/tracking?url=http://myurl/
    >>> in the output.
    >>> i've been trying to use a external procedure like this.
    >>> ## Script (Python) "track_link"
    >>> ##bind container=container
    >>> ##bind context=context
    >>> ##bind namespace=_
    >>> ##bind script=script
    >>> ##bind subpath=traverse_subpath
    >>> ##parameters=self,url
    >>> ##title=track link
    >>> ##
    >>> return "%s%s" % (self.tracking_prefix, url_quote(url))
    >>> This doesn't work because because the method doesn't have access to
    >>> the environment. Obviously I don't wan't to pass everything explicitly
    >>> into the function as this would defeat the purpose of the exercise,
    >>> namely to provide a terse syntax.
    >>> I have a background in other languages so I might be missing something
    >>> conceptually with regard Zope and DTML.. Is there a better was of
    >>> doing this, perhaps without using external methods? Currently im doing
    >>> the following which isn't very elegant:
    >>> in content document
    >>> <a href="<dtml-let exturl="'http://www.mylink.com/"><dtml-var
    >>> tracking></dtml-let>">link</a>
    >>> ...
    >>> tracking:
    >>> <dtml-var tracking_prefix><dtml-var name="exturl" url_quote_plus>
    >>> Appreciate any input you might have on this-

    >> Is it really needed to use an external method for this, or isn't a
    >> "normal" python script enough already?
    >>
    >> If it has to be an External method, you can't access such a context
    >> AFAIK. But then you can create a python script that _has_ this context,
    >> and passese it to the external method. Not the nicest solution, but
    >> should work.
    >>
    >> Diez

    >
    > Like I said i'm a newbie. I though the deal with Zope was that i
    > couldn't really do inline scripting (for security reasons)
    > like in php but had to use these external methods. how does one go
    > about creating a "normal" python script exactly and
    > how do I invoke it's functionality?


    Read the docs:

    http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx

    There's everything in there you need.

    Diez
    Diez B. Roggisch, Jan 29, 2008
    #5
  6. Jens

    Guest

    On Jan 29, 11:50 pm, "Diez B. Roggisch" <> wrote:
    > Jens schrieb:
    >
    >
    >
    > > On Jan 25, 3:19 pm, "Diez B. Roggisch" <> wrote:
    > >> Jens schrieb:

    >
    > >>> Hello Everyone
    > >>> I'm newbie toZopeand i have a few questions regarding external
    > >>> methods. What i wan't to do
    > >>> is provide a terse syntax for converting urls to special tracking
    > >>> urls:
    > >>> <dtml-var "track('http://myurl/')">
    > >>> turns the provided url into something like
    > >>>http://host/tracking?url=http://myurl/
    > >>> in the output.
    > >>> i've been trying to use a external procedure like this.
    > >>> ## Script (Python) "track_link"
    > >>> ##bind container=container
    > >>> ##bind context=context
    > >>> ##bind namespace=_
    > >>> ##bind script=script
    > >>> ##bind subpath=traverse_subpath
    > >>> ##parameters=self,url
    > >>> ##title=track link
    > >>> ##
    > >>> return "%s%s" % (self.tracking_prefix, url_quote(url))
    > >>> This doesn't work because because the method doesn't have access to
    > >>> the environment. Obviously I don't wan't to pass everything explicitly
    > >>> into the function as this would defeat the purpose of the exercise,
    > >>> namely to provide a terse syntax.
    > >>> I have a background in other languages so I might be missing something
    > >>> conceptually with regardZopeand DTML.. Is there a better was of
    > >>> doing this, perhaps without using external methods? Currently im doing
    > >>> the following which isn't very elegant:
    > >>> in content document
    > >>> <a href="<dtml-let exturl="'http://www.mylink.com/"><dtml-var
    > >>> tracking></dtml-let>">link</a>
    > >>> ...
    > >>> tracking:
    > >>> <dtml-var tracking_prefix><dtml-var name="exturl" url_quote_plus>
    > >>> Appreciate any input you might have on this-
    > >> Is it really needed to use an external method for this, or isn't a
    > >> "normal" python script enough already?

    >
    > >> If it has to be an External method, you can't access such a context
    > >> AFAIK. But then you can create a python script that _has_ this context,
    > >> and passese it to the external method. Not the nicest solution, but
    > >> should work.

    >
    > >> Diez

    >
    > > Like I said i'm a newbie. I though the deal withZopewas that i
    > > couldn't really do inline scripting (for security reasons)
    > > like in php but had to use these external methods. how does one go
    > > about creating a "normal" python script exactly and
    > > how do I invoke it's functionality?

    >
    > Read the docs:
    >
    > http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/Scripting...
    >
    > There's everything in there you need.
    >
    > Diez


    Thanks, this is exactly what i needed. And Btw. the answer is to use
    the 'context' keyword.

    - Jens

    P.S. And thanks to everyone else for their feedback :)
    , Feb 4, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Allen
    Replies:
    8
    Views:
    10,929
    Scott Allen
    May 2, 2004
  2. Denise Vela

    Enzte is a ripoff terse chief

    Denise Vela, Jun 3, 2004, in forum: Python
    Replies:
    0
    Views:
    1,209
    Denise Vela
    Jun 3, 2004
  3. Roy Smith

    Getting terse tracebacks?

    Roy Smith, Jan 1, 2006, in forum: Python
    Replies:
    1
    Views:
    257
  4. Kenneth McDonald
    Replies:
    5
    Views:
    312
    Kenneth McDonald
    Sep 26, 2008
  5. luser droog
    Replies:
    0
    Views:
    86
    luser droog
    May 4, 2014
Loading...

Share This Page