furl icon indicating copy to clipboard operation
furl copied to clipboard

Feature: Addition of `is_domain` flag

Open znd4 opened this issue 3 years ago • 0 comments

This idea has been floated in a couple of comments (thanks @pramttl and @fearless0307 !). I just thought it'd be worth creating a standalone issue for this idea and maybe fleshing it out a bit.

I'm currently thinking of behavior like:

f_bare = furl("github.com", is_domain=True, scheme="https")
f_http = furl("http://github.com", is_domain=True, scheme="https")
f_https = furl("https://github.com", is_domain=True, scheme="https")

{f_bare.url, f_http.url, f_https.url} = {"https://github.com"}  # True

The motivation that I see for this is I'd like to be able to cleanly implement a function to coerce a domain to include the https schema. I can currently do that like this, but it's a bit hacky:

def coerce_to_https(url: str) -> str:
    url = url.removeprefix("http://").removeprefix("https://")
    return furl(host=url, scheme="https").url

assert {
    coerce_to_https("github.com"),
    coerce_to_https("http://github.com"),
    coerce_to_https("https://github.com"),
} == {"https://github.com"}

Thanks, I love this library btw <3

znd4 avatar Dec 03 '21 20:12 znd4