class url_hostname.host.Host(val: str = '', *, second_level_domain: str = '', top_level_domain: str = '', subdomains: Union[Iterable[str], str] = ())
Immutable representation of a host in URL Modifying the host will return new instance of the class, thus allowing chaining
>>> leaf 🍃 domain name
>>> _|_ __|__
>>> ⸍ ⸌ ⸍ ⸌
>>> www.prixroberval.utc.fr
>>> ⸌________________⸍⸌__⸍⸌__⸍
>>> | | |
>>> subdomains second top
>>> domain domain
>>> level level
Creates and returns a new Host:
-
Parameters
-
second_level_domain (str) -- single part
-
top_level_domain (str) -- level in the hierarchical DNS after the root domain
-
subdomains (Iterable*[str]**, *optional) -- parts on the left of the domain name
-
-
Returns
new Host instance
-
Return type
Host
>>> Host.build("utc", "fr")
Host('utc.fr')
Get the minimal part of the domain space that corresponds to an IP address as a string
-
Returns
second and top level domains
-
Return type
Host
>>> host = Host.build("utc", "fr", subdomains=("www", "prixroberval"))
>>> host.domain_name
Host('utc.fr')
Whether or not this Host is relative to other
-
Returns
whether this Host is relative to other
-
Return type
bool
>>> docs = Host.build('amazon', 'com', ("docs",'aws'))
>>> macie = docs.with_subdomains(("us-west-2", "redirection", "macie", "aws"))
>>> macie.is_relative_to(docs)
True
Left most part of the domain
-
Returns
host domain's leaf
-
Return type
str
>>> host = Host.build("utc", "fr", subdomains=("www", "prixroberval"))
>>> host.leaf
'www'
Compute new a version of this Host relative to the path represented by other
-
Returns
new with common domain names
-
Return type
Host
-
Raises
ValueError -- when no relative host exists
>>> docs = Host.build('amazon', 'com', ("docs",'aws'))
>>> macie = docs.with_subdomains(("us-west-2", "redirection", "macie", "aws"))
>>> macie.relative_to(docs)
Host('aws.amazon.com')
New Host with the left most part of the domain replaced
-
Returns
new with leaf replaced
-
Return type
Host
>>> host = Host.build("wikipedia", "org", subdomains="en")
>>> host.with_leaf('fr')
Host('fr.wikipedia.org')
New Host with subdomains replaced
-
Parameters
subdomains (Union*[Iterable[str]**, str]*) -- subdomains with leaf at left
-
Returns
new with subdomains replaced
-
Return type
Host
>>> host = Host.build("utc", "fr", subdomains=("www", "prixroberval"))
>>> host.with_leaf('prixroberval')
Host('prixroberval.utc.fr')
-
Index
-
Module Index
-
Search Page