I often create an external method for this... em: def url_quote(s): import urllib return urllib.quote_plus(s, safe='') Silly, but it works. I think the alternative is to hack the DT_Util.py module in the DocumentTemplate directory to expose urllib or a derived function.
-----Original Message----- From: Kapil Thangavelu [mailto:kvthan@wm.edu] Sent: Wednesday, July 19, 2000 11:46 PM To: zope@zope.org Subject: [Zope] URL quoting in python
is there a way to get a url-encoded/quoted variable in pythonish dtml ?
what i am trying to do <dtml-call "RESPONSE.redirect(URL1+'?foo_bar='+foobar)">
Kapil
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
How about doing the equivalent on html_quote in python? Chris Chris McDonough wrote:
I often create an external method for this...
em:
def url_quote(s): import urllib return urllib.quote_plus(s, safe='')
Silly, but it works.
I think the alternative is to hack the DT_Util.py module in the DocumentTemplate directory to expose urllib or a derived function.
-----Original Message----- From: Kapil Thangavelu [mailto:kvthan@wm.edu] Sent: Wednesday, July 19, 2000 11:46 PM To: zope@zope.org Subject: [Zope] URL quoting in python
is there a way to get a url-encoded/quoted variable in pythonish dtml ?
what i am trying to do <dtml-call "RESPONSE.redirect(URL1+'?foo_bar='+foobar)">
Kapil
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
I often create an external method for this...
em:
def url_quote(s): import urllib return urllib.quote_plus(s, safe='')
Silly, but it works.
I think the alternative is to hack the DT_Util.py module in the DocumentTemplate directory to expose urllib or a derived function.
Isn't an external method a bit overkill? It is possible to just create a DTML Method called url_quote where the body is: <dtml-var s url_quote> (making sure there is no whitespace before this line, and no newline after it.) Then from any other DTML method you just call it remembering to pass in the parameter by name. e.g. <dtml-call "RESPONSE.redirect(URL1+'?foo_bar='+url_quote(s=ufoobar))"> -- Duncan Booth duncan@dales.rmplc.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? http://dales.rmplc.co.uk/Duncan
Thanks for the tip Duncan, I find it strange that this utility function is not in the _ namepace... time to make a trip to the Tracker. It seems like a url-encoding function should be directly accessible from zope. Thanks Kapil Duncan Booth wrote:
I often create an external method for this...
em:
def url_quote(s): import urllib return urllib.quote_plus(s, safe='')
Silly, but it works.
I think the alternative is to hack the DT_Util.py module in the DocumentTemplate directory to expose urllib or a derived function.
Isn't an external method a bit overkill? It is possible to just create a DTML Method called url_quote where the body is: <dtml-var s url_quote>
(making sure there is no whitespace before this line, and no newline after it.)
Then from any other DTML method you just call it remembering to pass in the parameter by name.
e.g. <dtml-call "RESPONSE.redirect(URL1+'?foo_bar='+url_quote(s=ufoobar))">
-- Duncan Booth duncan@dales.rmplc.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? http://dales.rmplc.co.uk/Duncan
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Chris McDonough -
Chris Withers -
Duncan Booth -
Kapil Thangavelu