On Thursday, January 12, 2012 10:59:09 AM UTC-5, Jonathan Lundell wrote:
>
> It's an interesting idea, but URL just returns a string, and aside from
> being a fairly big rewrite, it's likely that it would break existing code
> that relies on it being a string.
>
> You could create your own object that takes the same arguments as URL and
> stores them as attributes, and whose __str__ and __repr__ functions are the
> actual call to URL().
>
Perhaps this isn't advisable or worthwhile, but maybe we could subclass str
so URL still returns a string but can also have attributes to store the
controller, function, etc.
class URL(str):
def __new__(cls, a, c, f, etc.):
[build url string as usual]
url = str.__new__(cls, url_string)
url.controller = controller
url.function = function
etc.
return url
Anthony