[Zope] html_quote in Python script

Tino Wildenhain tino@wildenhain.de
Thu, 12 Jun 2003 14:22:11 +0200


Hi,

Petter Enhom wrote:
> It's all written in the source :-)
> 
> This is the html_quote method used by dtml
> (lib/python/DocumenTemplate/html_quote.py)
> 
> # split off into its own module for aliasing without circrefs
> 
> from cgi import escape
> from ustr import ustr
> 
> def html_quote(v, name='(Unknown name)', md={}):
>     return escape(ustr(v), 1)

Its all written in front of you when you start writing a new
python script in Zope:

# Example code:
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
                                             ^ ^ ^ ^ ^ ^



> I think also urllib can help you:
> 
> import urllib
> print urllib.quote('this is a string')

erm. but this is a different thing.
html_quoting means put & into -> &,
put < into &lt; and so on.

url_quote means put " " into %20, ...

BTW (hint! hint!) for alle the URL constructors
out there:

from ZTUtils import make_query

query=make_query(foo='bar',blah=[1,2,3])

will build a nice query string to be appendet to URLs.

Regards
Tino