Skip to content
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

Closed
liori mannequin opened this issue Apr 17, 2011 · 6 comments
Closed

urlparse.ParseResult to have meaningful __str__ #56071

liori mannequin opened this issue Apr 17, 2011 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@liori
Copy link
Mannequin

liori mannequin commented Apr 17, 2011

BPO 11862
Nosy @orsenthil, @merwok

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:

assignee = 'https://github.com/orsenthil'
closed_at = <Date 2011-04-18.13:16:30.410>
created_at = <Date 2011-04-17.18:23:11.287>
labels = ['invalid', 'type-feature', 'library']
title = 'urlparse.ParseResult to have meaningful __str__'
updated_at = <Date 2011-04-28.11:50:20.106>
user = 'https://bugs.python.org/liori'

bugs.python.org fields:

activity = <Date 2011-04-28.11:50:20.106>
actor = 'orsenthil'
assignee = 'orsenthil'
closed = True
closed_date = <Date 2011-04-18.13:16:30.410>
closer = 'orsenthil'
components = ['Library (Lib)']
creation = <Date 2011-04-17.18:23:11.287>
creator = 'liori'
dependencies = []
files = []
hgrepos = []
issue_num = 11862
keywords = []
message_count = 6.0
messages = ['133934', '133950', '133965', '133966', '134270', '134669']
nosy_count = 3.0
nosy_names = ['orsenthil', 'eric.araujo', 'liori']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue11862'
versions = ['Python 3.3']

@liori
Copy link
Mannequin Author

liori mannequin commented Apr 17, 2011

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.

@liori liori mannequin added extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Apr 17, 2011
@orsenthil
Copy link
Member

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.

@orsenthil orsenthil self-assigned this Apr 18, 2011
@liori
Copy link
Mannequin Author

liori mannequin commented Apr 18, 2011

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', ...)

@orsenthil
Copy link
Member

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.

@merwok
Copy link
Member

merwok commented Apr 22, 2011

Why couldn’t ParseResult call urlunparse to implement a useful __str__?

@merwok merwok added stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Apr 22, 2011
@orsenthil
Copy link
Member

É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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants