Issue11862
Created on 2011-04-17 18:23 by liori, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg133934 - (view) | Author: Tomasz Melcer (liori) | Date: 2011-04-17 18:23 | |
I find it a minor annoyance that a result of `urlparse.urlparse` (an object of class urlparse.ParseResult) doesn't have a meaningful __str__/__unicode__ methods. `urlparse.ParseResult` is a subclass of `namedtuple` with __slots__, so I can't easily add it, too. I propose to make __str__/__unicode__ equivalent to geturl() call. |
|||
| msg133950 - (view) | Author: Senthil Kumaran (orsenthil) * ![]() |
Date: 2011-04-18 02:45 | |
What would be a 'meaning' __str__ or __unicode__ of urlparse.urlparse and how would it be useful to you? I would think that people would except a tuple, list or a ParsedResult for such a call. I cannot understand the rational behind the expectation that __str__ or __unicode__ of ParsedResult to be equivalent to the geturl call. If you can, please elaborate. |
|||
| msg133965 - (view) | Author: Tomasz Melcer (liori) | Date: 2011-04-18 12:55 | |
If __str__ is meant to be a user-understandable way of expressing an URL, the best way to do that is to show it the same way user sees it in usually. This is now done by .geturl() call.
This way I wouldn't have to remember to serialize it in cases where I want to display an URL to user:
url = urlparse.urlparse(sys.args[1])
...
print "Downloading {1}".format(url)
would mean: "show me that URL".
And if you would like to display its internal representation as a record of scheme/host/path/..., you always have __repr__. Currently both __str__ and __repr__ return `ParsedResult(scheme="http", netloc='example.com', ...)`
|
|||
| msg133966 - (view) | Author: Senthil Kumaran (orsenthil) * ![]() |
Date: 2011-04-18 13:16 | |
Tomasz, I think, you misunderstood the purpose of urlparse library. urlparse is for parsing the URL and into its components. The url could be a mailto:, svn+ssh or http,https. The requirement for parsing comes when you are designing systems which take up URL and you need to do parse it for certain purposes for your application and then do action based on the parsed result. That is why there are parse,unparse,split, unsplit functions provided. If you have to get the original url back it is reverse call, send the parsed result to urlunparse. The urllib, which provides facilties for doing http at higher level provides you geturl (which is getting the url from the header values). I don't see the use of __str__ or __unicode__ for parse library. I am closing this report as Invalid. Thank you. |
|||
| msg134270 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2011-04-22 16:49 | |
Why couldn’t ParseResult call urlunparse to implement a useful __str__? |
|||
| msg134669 - (view) | Author: Senthil Kumaran (orsenthil) * ![]() |
Date: 2011-04-28 11:50 | |
Éric, ParseResult is a class which provides tuple for urlparse/unparse. People should hardly (/never) use ParseResult directly. The original poster's concern was to get something like geturl() from this class which was not suitable and it should be obtained by other meaningful methods. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:16 | admin | set | github: 56071 |
| 2011-04-28 11:50:20 | orsenthil | set | messages: + msg134669 |
| 2011-04-22 16:49:46 | eric.araujo | set | versions:
+ Python 3.3 nosy: + eric.araujo messages: + msg134270 components: + Library (Lib), - Extension Modules |
| 2011-04-18 13:16:30 | orsenthil | set | status: open -> closed resolution: not a bug messages: + msg133966 stage: resolved |
| 2011-04-18 12:55:50 | liori | set | messages: + msg133965 |
| 2011-04-18 02:45:11 | orsenthil | set | assignee: orsenthil |
| 2011-04-17 18:23:11 | liori | create | |
