Address: allow checking for multiple types
This commit is contained in:
parent
7d54de09a2
commit
a15e89854c
|
@ -151,15 +151,19 @@ class Address(str):
|
|||
return self._hostname
|
||||
|
||||
|
||||
def is_type(self, iptype):
|
||||
if not isinstance(iptype, IpAddressType):
|
||||
try:
|
||||
iptype = IpAddressType[iptype.upper()]
|
||||
def is_type(self, *iptypes):
|
||||
for iptype in iptypes:
|
||||
if not isinstance(iptype, IpAddressType):
|
||||
try:
|
||||
iptype = IpAddressType[iptype.upper()]
|
||||
|
||||
except KeyError:
|
||||
raise KeyError(f'Invalid address type: {iptype}')
|
||||
except KeyError:
|
||||
raise KeyError(f'Invalid address type: {iptype}')
|
||||
|
||||
return self.type == iptype
|
||||
if self.type == iptype:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class Url(str):
|
||||
|
@ -354,7 +358,7 @@ class Url(str):
|
|||
domain = self.domain or self.path
|
||||
|
||||
if not self._tldcache:
|
||||
if not self._tldcache_path.exists() or self._tldcache_path.mtime + timedelta(days=7) < datetime.now():
|
||||
if not self._tldcache_path.exists() or self._tldcache_path.modified() + timedelta(days=7) < datetime.now():
|
||||
resp = urlopen('https://publicsuffix.org/list/public_suffix_list.dat')
|
||||
|
||||
with self._tldcache_path.open('w') as fd:
|
||||
|
|
Loading…
Reference in a new issue