durusmail: quixote-users: quoting
quoting
2002-06-20
2002-06-21
quoting
Quinn Dunkan
2002-06-20
I know how close HTML quoting is to some people's hearts around here :) so I
thought I'd try to clear up a few questions I have about the issue...

First, am I correct that value_quote(s) is redundant since
'"' + html_quote(s) + '"' is just as good?  Secondly, is
link_url = html_quote(url_quote(url)) correct usage (assuming 'url' doesn't
include a query string)?  Actually, I use a url_args() that takes a url
(*without* schema and hostname, so path_args() might be a better name) and
kw args, quotes the url, and tacks on the appropriate query string, so I
don't think I should have to worry about manually url_quote()ing everywhere...

Anyway, speaking of the manual quoting, it sort of bothers me.

I'm sure this is something many other people have thought about, so it's
likely that someone has a better solution than I do.

Currently, I have a lot of html_quote()s and url_quote()s sprinkled throughout
my template code, which is sort of repetetive and error-prone (too much
quoting, not enough quoting, quoting the wrong part (e.g. http%3A//...
syndrome)).  Making a Tag class that automatically quotes the right stuff
is an obvious solution, but then that turns

v1, v2, v3 = map(html_quote, (v1, v2, v3))
'''
           
''' % locals()

into

        Tag(Tag( ... crazy nest of tags ))))))).render()

My next consideration was:

'''
         %(
''' % ht(locals())

... where 'ht' is a class with an appropriate __getitem__.  '?v1'
html_quote()s locals()['v1'] and plain 'v1' would pass through literally.
This substitutes some tricky weird looking hackery for manual-but-explicit
quoting, so I'm not really sure if it's worth the tradeoff.  Besides, you
still have to quote the tag contents.

I see no easy way to use plain flat strings (instead of nested objects)
and get quoted contents, aside from coming up with a whole language just
like HTML only with automatic interpolation and quoting of values (the
%(<...)s notation is a sort of mini-language).

So my current resolution is "quote manually and just be careful".  Maybe
a short set of guidelines of what to quote would be a good thing.




reply