New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
urlparse.ParseResult to have meaningful __str__ #56071
Comments
I find it a minor annoyance that a result of I propose to make __str__/unicode equivalent to geturl() call. |
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. |
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 |
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. |
Why couldn’t ParseResult call urlunparse to implement a useful __str__? |
É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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: