# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
import importlib.metadata
import itertools
import string
from typing import Dict, List, Tuple
def _tuple_from_text(version: str) -> Tuple:
text_parts = version.split(".")
int_parts = []
for text_part in text_parts:
digit_prefix = "".join(
itertools.takewhile(lambda x: x in string.digits, text_part)
)
try:
int_parts.append(int(digit_prefix))
except Exception:
break
return tuple(int_parts)
def _version_check(
requirement: str,
) -> bool:
"""Is the requirement fulfilled?
The requirement must be of the form
package>=version
"""
package, minimum = requirement.split(">=")
try:
version = importlib.metadata.version(package)
# This shouldn't happen, but it apparently can.
if version is None:
return False
except Exception:
return False
t_version = _tuple_from_text(version)
t_minimum = _tuple_from_text(minimum)
if t_version < t_minimum:
return False
return True
_cache: Dict[str, bool] = {}
def have(feature: str) -> bool:
"""Is *feature* available?
This tests if all optional packages needed for the
feature are available and recent enough.
Returns ``True`` if the feature is available,
and ``False`` if it is not or if metadata is
missing.
"""
value = _cache.get(feature)
if value is not None:
return value
requirements = _requirements.get(feature)
if requirements is None:
# we make a cache entry here for consistency not performance
_cache[feature] = False
return False
ok = True
for requirement in requirements:
if not _version_check(requirement):
ok = False
break
_cache[feature] = ok
return ok
def force(feature: str, enabled: bool) -> None:
"""Force the status of *feature* to be *enabled*.
This method is provided as a workaround for any cases
where importlib.metadata is ineffective, or for testing.
"""
_cache[feature] = enabled
_requirements: Dict[str, List[str]] = {
### BEGIN generated requirements
"dnssec": ["cryptography>=43"],
"doh": ["httpcore>=1.0.0", "httpx>=0.26.0", "h2>=4.1.0"],
"doq": ["aioquic>=1.0.0"],
"idna": ["idna>=3.7"],
"trio": ["trio>=0.23"],
"wmi": ["wmi>=1.5.1"],
### END generated requirements
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| dnssecalgs | Folder | 0755 |
|
|
| quic | Folder | 0755 |
|
|
| rdtypes | Folder | 0755 |
|
|
| __init__.py | File | 1.62 KB | 0644 |
|
| _asyncbackend.py | File | 2.34 KB | 0644 |
|
| _asyncio_backend.py | File | 8.84 KB | 0644 |
|
| _ddr.py | File | 5.12 KB | 0644 |
|
| _features.py | File | 2.43 KB | 0644 |
|
| _immutable_ctx.py | File | 2.4 KB | 0644 |
|
| _trio_backend.py | File | 8.27 KB | 0644 |
|
| asyncbackend.py | File | 2.73 KB | 0644 |
|
| asyncquery.py | File | 30.1 KB | 0644 |
|
| asyncresolver.py | File | 17.43 KB | 0644 |
|
| dnssec.py | File | 40.74 KB | 0644 |
|
| dnssectypes.py | File | 1.76 KB | 0644 |
|
| e164.py | File | 3.88 KB | 0644 |
|
| edns.py | File | 16.69 KB | 0644 |
|
| entropy.py | File | 4.14 KB | 0644 |
|
| enum.py | File | 3.6 KB | 0644 |
|
| exception.py | File | 5.81 KB | 0644 |
|
| flags.py | File | 2.69 KB | 0644 |
|
| grange.py | File | 2.09 KB | 0644 |
|
| immutable.py | File | 1.97 KB | 0644 |
|
| inet.py | File | 5.64 KB | 0644 |
|
| ipv4.py | File | 2.49 KB | 0644 |
|
| ipv6.py | File | 6.4 KB | 0644 |
|
| message.py | File | 66.59 KB | 0644 |
|
| name.py | File | 41.78 KB | 0644 |
|
| namedict.py | File | 3.91 KB | 0644 |
|
| nameserver.py | File | 9.88 KB | 0644 |
|
| node.py | File | 12.37 KB | 0644 |
|
| opcode.py | File | 2.67 KB | 0644 |
|
| py.typed | File | 0 B | 0644 |
|
| query.py | File | 54.98 KB | 0644 |
|
| rcode.py | File | 4.06 KB | 0644 |
|
| rdata.py | File | 30.29 KB | 0644 |
|
| rdataclass.py | File | 2.91 KB | 0644 |
|
| rdataset.py | File | 16.27 KB | 0644 |
|
| rdatatype.py | File | 7.27 KB | 0644 |
|
| renderer.py | File | 10.99 KB | 0644 |
|
| resolver.py | File | 72 KB | 0644 |
|
| reversename.py | File | 3.74 KB | 0644 |
|
| rrset.py | File | 8.96 KB | 0644 |
|
| serial.py | File | 3.52 KB | 0644 |
|
| set.py | File | 9 KB | 0644 |
|
| tokenizer.py | File | 23.03 KB | 0644 |
|
| transaction.py | File | 22.06 KB | 0644 |
|
| tsig.py | File | 11.15 KB | 0644 |
|
| tsigkeyring.py | File | 2.57 KB | 0644 |
|
| ttl.py | File | 2.91 KB | 0644 |
|
| update.py | File | 11.96 KB | 0644 |
|
| version.py | File | 1.88 KB | 0644 |
|
| versioned.py | File | 11.49 KB | 0644 |
|
| win32util.py | File | 8.67 KB | 0644 |
|
| wire.py | File | 2.76 KB | 0644 |
|
| xfr.py | File | 12.96 KB | 0644 |
|
| zone.py | File | 50.87 KB | 0644 |
|
| zonefile.py | File | 27.27 KB | 0644 |
|
| zonetypes.py | File | 690 B | 0644 |
|