[XML-SIG] Re: Ideas for web/ package
Walter Dörwald
walter@livinglogic.de
Thu, 21 Feb 2002 14:15:13 +0100
M.-A. Lemburg wrote:
> Alan Kennedy wrote:
>
>>>You may be interested in the mxURL package for dealing
>>>with URL, URIs or whatever you call them ;-):
>>>
>>> http://www.egenix.com/files/python/mxURL.html
>>>
>>Marc-André,
>>
>>Just a quick question: Is the "normalize" that is mentioned
>>in the mxURL documentation the same "normalization" as
>>mentioned in section 6: "URI Normalization and Equivalence"
>>of rfc2396?
>>
>
> I guess so, but keep in mind that mxURL was crafted after
> urlparse() and common sense :-)
>
> Seriously, mxURL will slowly move towards RFC 2396 and
> so the answer is "yes, but...".
What I'd like to have is an RFC2396 compliant URL class,
that has all the url components as assignable properties,
i.e. something that can be used like:
>>> u = URL("http://www.foo.com:81/foo;bar/bar;foo/baz?what#frag")
>>> u.scheme
'http'
>>> u.server
'www.foo.com:81'
>>> u.host
'www.foo.com'
>>> u.port
81
>>> u.path
'/foo;bar/bar;foo/baz'
>>> u.path_segments
[['foo', 'bar'], ['bar', 'foo'], ['baz']]
>>> u.query
'what'
>>> u.fragment
'frag'
>>> u.url
'http://www.foo.com:81/foo;bar/bar;foo/baz?what#frag'
>>> u.path = "/gurk/hurz/"
>>> u.path_segments
[['gurk'], ['hurz'], ['']]
>>> u.url
'http://www.foo.com:81/gurk/hurz/?what#frag'
>>> del u.query
>>> del u.fragment
>>> u.scheme = "ftp"
>>> u.server = "user@ftp.foo.org:2121"
>>> u.url
'ftp://user@ftp.foo.org:2121/gurk/hurz/'
>>> u.userinfo
'user'
>>> u.host
'ftp.foo.org'
>>> u.port
2121
>>> u.userinfo = "user2"
>>> u.server
'user2@ftp.foo.org:2121'
i.e. whenever a property for a non-terminal symbol from
the RFC2396 BNF is set it will be split into its
components and whenever one is accessed it will be
reassembled from the components.
This means that to get the functionality of urlparse.urlsplit()
you simple set the property "url" and access the parts you need:
"scheme", "userinfo", "host", "port", "path" etc. For the
functionality of urlparse.urlunsplit() you set the simple
properties and then use the value of the property "url".
A quick hack that implements something like this can be found
at ftp://ftp.livinglogic.de/pub/url.py
Bye,
Walter Dörwald
--
Walter Dörwald · LivingLogic AG, Bayreuth/Germany · www.livinglogic.de