I am looking for something like java.net.URL in python-modules, Django, Zope or wherever in Python. I want it preferably from the semantics reason, because the result of analysis of concerned program implies that the URL plays an essential role in it. The consequence is that such URL class also will have great practical usage in that program.
Of course I could write such class on my own, but I'd like to look around before I start to reinvent the wheel.
I did look at urllib2 and urlparse. The urlparse
basically has the functionality I need, but it doesn't encapsulate it into a class like java.net.URL
. Regarding my analysis of my program it works upside-down.
I looked also into the source code of urlparse
at the classes SplitResult
and ParseResult
. They have some basic functionality and they can be used for subclassing. But I'll have to rewrite rest of the urlparse functions as the subclass methods.
I found also mxURL - Flexible URL Datatype for Python. It is very close to what I really want. Only it seems to be quite an overkill for my purpose.
Can anyone suggest another option? Should I proceed with reinventing the wheel?
My solution:
To get my URL class I did basically two things:
urlparse.ResultMixin
. urlparse.urlparse()
and transforms results to
parameters of URL instance.You might want consider having a look at furl because it might be an answer to your needs.