Skip to content

remove reference to splitport() #229

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

Closed
wants to merge 2 commits into from
Closed

remove reference to splitport() #229

wants to merge 2 commits into from

Conversation

ccurvey
Copy link

@ccurvey ccurvey commented Apr 8, 2020

with python 3.8 I'm getting warnings that splitport() is deprecated. I rolled by own, rather than trying to use the official urlparse() method as the official version does not handle "host:port" style URLs.


This change is Reviewable

@andersk
Copy link
Contributor

andersk commented May 9, 2020

To use the official urlparse function, you just need to prepend a //:

>>> from urllib.parse import urlparse
>>> u = urlparse("//" + "localhost:1234")
>>> u.hostname
'localhost'
>>> u.port
1234

Additionally, urlparse supports IPv6 where this hand-rolled parser does not:

>>> u = urlparse("//" + "[::1]:1234")
>>> u.hostname
'::1'
>>> u.port
1234

Or you can use SplitResult to avoid string concatenation:

>>> from urllib.parse import SplitResult
u = SplitResult("", "[::1]:1234", "", "", "")
>>> u.hostname
'::1'
>>> u.port
1234

@jaysonsantos
Copy link
Owner

Hey there @ccurvey what do you think of trying @andersk 's approach?

@ccurvey ccurvey closed this Feb 3, 2022
@andersk
Copy link
Contributor

andersk commented Oct 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants