[Zope3-dev] Re: Make AbsoluteURL produce quoted urls
Stuart Bishop
stuart at stuartbishop.net
Tue Jun 1 09:47:45 EDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 01/06/2004, at 1:39 PM, Philipp von Weitershausen wrote:
> Bjorn Tillenius wrote:
>> > No, I think there's a quite easy solution. AbsoluteURL.__call__
>> should > return unicode so that one has all the options when using it
>> from > Python. AbsoluteURL.__str__ should return whatever __call__
>> would > return, but encoded in UTF8. If I remember correctly, TALES
>> first > evaluates __str__ before __call__, so the path expressions
>> would still > be fine.
>> I'm almost fine with this, __str__ should still return ascii, it
>> should
>> quote the url instead (but maybe that's what you meant).
>
> Indeed the spec (http://www.ietf.org/rfc/rfc2718.txt, section 2.2.5)
> suggests::
>
> Unless there is some compelling reason for a
> particular scheme to do otherwise, translating character
> sequences
> into UTF-8 (RFC 2279) [3] and then subsequently using the %HH
> encoding for unsafe octets is recommended.
>
> So, __str__ could indeed first encode to UTF-8 and then urlquote so we
> end up with%HH. I can't come up with a good use case for wanting a
> string but not quoted, so having either unicode or a quoted string
> would be enough and easily implemented.
It is impossible to convert a Unicode URL to an ASCII string and
*not* have it quoted.
I would prefer the AbsoluteURL to be a subclass of unicode, so:
>>> url = URL(u'http://www.ol\xe9.de/\xc7/page_\u2160.html')
>>> unicode(url)
u'http://www.ol\xe9.de/\xc7/page_\u2160.html'
>>> str(url)
'http://www.xn--ol-cja.de/rene%C3%A9.html'
>>> url.urlencode()
'http://www.xn--ol-cja.de/rene%C3%A9.html'
This is almost identical to the EmailAddress class available
at http://www.stuartbishop.net/Software/EmailAddress (should
I check this into Z3? If so, where?)
The last syntax was to make TALES nicer:
<a tal:attributes="href someurl/urlencode" tal:content="someurl" />
I prefer that to the proposed use of __call__, which would mean I
would have to write the above as:
<a tal:attributes="href someurl" tal:content="python: someurl()" />
- --
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQFAvIkBAfqZj7rGN0oRAkj+AJ0etcnMZaBVrvQuNBPlZPCqbT8ymwCeIw8u
mScjQvQUuKAA00D8denpvaQ=
=ID5J
-----END PGP SIGNATURE-----
More information about the Zope3-dev
mailing list