[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
 >>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
 >>> u.server
 >>> u.host
 >>> u.port
 >>> u.path
 >>> u.path_segments
[['foo', 'bar'], ['bar', 'foo'], ['baz']]
 >>> u.query
 >>> u.fragment
 >>> u.url
 >>> u.path = "/gurk/hurz/"
 >>> u.path_segments
[['gurk'], ['hurz'], ['']]
 >>> u.url
 >>> del u.query
 >>> del u.fragment
 >>> u.scheme = "ftp"
 >>> u.server = "user@ftp.foo.org:2121"
 >>> u.url
 >>> u.userinfo
 >>> u.host
 >>> u.port
 >>> u.userinfo = "user2"
 >>> u.server

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

    Walter Dörwald

Walter Dörwald · LivingLogic AG, Bayreuth/Germany · www.livinglogic.de