[Zope3-dev] Re: Make AbsoluteURL produce quoted urls

Stuart Bishop stuart at stuartbishop.net
Tue Jun 1 16:40:54 EDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 01/06/2004, at 5:33 PM, Bjorn Tillenius wrote:

>> 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'
>
> I don't like the urlencode method. I think an AbsoluteURL should be a
> valid URL, if you want to do something special, like converting it to
> unicode, you should have to do something extra. Not the other way 
> around.
>
> So, I want to do the following changes::
>
>   * Add __unicode__, which will of course return a unicode string.
>
>   * Change __str__ so that it takes the unicode url, encodes it to
>     utf-8, and urlquotes it before it gets returned.

I think that is pretty much what I had. I don't know if that will
work the way you want, in that I *think* that adding the __unicode__
method means you will need to do the following:
	<a tal:attributes="href python:str(url)" tal:content="url" />
(ie. TALES will prefer the Unicode representation over the plain text).

I prefer it though, so I'm not worried if this actually is the case :-)

The __str__ method *will* need to convert the domain portion of the
URL using the IDNA encoding though (domain.encode('idna')). Not doing
this will generate invalid URL's. I've updated the examples
at http://images.stuartbishop.net/idna.html if people want a
demonstration they can click on. It is the responsibility of
AbsoluteURL because nothing else requires the domain portion
to be ASCII (Not that I have tested how Z3 copes when it is running
with a Unicode domain name... but I believe all of the Python
stuff now correctly handles Unicode strings as domain names).

  --
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFAvOneAfqZj7rGN0oRAjaDAJ9VJtOhiwozRIOvYzEM+zoUTAwSDwCfb2dj
07N+9M2hr+UOMsfy9hSzw1I=
=+2G/
-----END PGP SIGNATURE-----




More information about the Zope3-dev mailing list