/opt/imh-python/lib/python3.9/site-packages/dns
NameSizeModeActions
dnssecalgs/-0755rm
quic/-0755rm
rdtypes/-0755rm
__pycache__/-0755rm
asyncbackend.py27960644editdlrm
asyncquery.py308210644editdlrm
asyncresolver.py178520644editdlrm
dnssec.py417170644editdlrm
dnssectypes.py17990644editdlrm
e164.py39780644editdlrm
edns.py170890644editdlrm
entropy.py42420644editdlrm
enum.py36910644editdlrm
exception.py59530644editdlrm
flags.py27500644editdlrm
grange.py21440644editdlrm
immutable.py20170644editdlrm
inet.py57720644editdlrm
ipv4.py25520644editdlrm
ipv6.py65540644editdlrm
message.py681850644editdlrm
name.py427780644editdlrm
namedict.py40000644editdlrm
nameserver.py101150644editdlrm
node.py126630644editdlrm
opcode.py27300644editdlrm
py.typed00644editdlrm
query.py562980644editdlrm
rcode.py41560644editdlrm
rdata.py310220644editdlrm
rdataclass.py29840644editdlrm
rdataset.py166640644editdlrm
rdatatype.py74480644editdlrm
renderer.py112540644editdlrm
resolver.py737300644editdlrm
reversename.py38280644editdlrm
rrset.py91700644editdlrm
serial.py36060644editdlrm
set.py92130644editdlrm
tokenizer.py235830644editdlrm
transaction.py225890644editdlrm
tsig.py114130644editdlrm
tsigkeyring.py26330644editdlrm
ttl.py29770644editdlrm
update.py122430644editdlrm
version.py19260644editdlrm
versioned.py117650644editdlrm
win32util.py88740644editdlrm
wire.py28300644editdlrm
xfr.py132710644editdlrm
zone.py520860644editdlrm
zonefile.py279260644editdlrm
zonetypes.py6900644editdlrm
_asyncbackend.py23960644editdlrm
_asyncio_backend.py90510644editdlrm
_ddr.py52470644editdlrm
_features.py24920644editdlrm
_immutable_ctx.py24590644editdlrm
_trio_backend.py84730644editdlrm
__init__.py16630644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/dns/e164.py (3978B)
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license # Copyright (C) 2006-2017 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, # provided that the above copyright notice and this permission notice # appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """DNS E.164 helpers.""" from typing import Iterable, Optional, Union import dns.exception import dns.name import dns.resolver #: The public E.164 domain. public_enum_domain = dns.name.from_text("e164.arpa.") def from_e164( text: str, origin: Optional[dns.name.Name] = public_enum_domain ) -> dns.name.Name: """Convert an E.164 number in textual form into a Name object whose value is the ENUM domain name for that number. Non-digits in the text are ignored, i.e. "16505551212", "+1.650.555.1212" and "1 (650) 555-1212" are all the same. *text*, a ``str``, is an E.164 number in textual form. *origin*, a ``dns.name.Name``, the domain in which the number should be constructed. The default is ``e164.arpa.``. Returns a ``dns.name.Name``. """ parts = [d for d in text if d.isdigit()] parts.reverse() return dns.name.from_text(".".join(parts), origin=origin) def to_e164( name: dns.name.Name, origin: Optional[dns.name.Name] = public_enum_domain, want_plus_prefix: bool = True, ) -> str: """Convert an ENUM domain name into an E.164 number. Note that dnspython does not have any information about preferred number formats within national numbering plans, so all numbers are emitted as a simple string of digits, prefixed by a '+' (unless *want_plus_prefix* is ``False``). *name* is a ``dns.name.Name``, the ENUM domain name. *origin* is a ``dns.name.Name``, a domain containing the ENUM domain name. The name is relativized to this domain before being converted to text. If ``None``, no relativization is done. *want_plus_prefix* is a ``bool``. If True, add a '+' to the beginning of the returned number. Returns a ``str``. """ if origin is not None: name = name.relativize(origin) dlabels = [d for d in name.labels if d.isdigit() and len(d) == 1] if len(dlabels) != len(name.labels): raise dns.exception.SyntaxError("non-digit labels in ENUM domain name") dlabels.reverse() text = b"".join(dlabels) if want_plus_prefix: text = b"+" + text return text.decode() def query( number: str, domains: Iterable[Union[dns.name.Name, str]], resolver: Optional[dns.resolver.Resolver] = None, ) -> dns.resolver.Answer: """Look for NAPTR RRs for the specified number in the specified domains. e.g. lookup('16505551212', ['e164.dnspython.org.', 'e164.arpa.']) *number*, a ``str`` is the number to look for. *domains* is an iterable containing ``dns.name.Name`` values. *resolver*, a ``dns.resolver.Resolver``, is the resolver to use. If ``None``, the default resolver is used. """ if resolver is None: resolver = dns.resolver.get_default_resolver() e_nx = dns.resolver.NXDOMAIN() for domain in domains: if isinstance(domain, str): domain = dns.name.from_text(domain) qname = dns.e164.from_e164(number, domain) try: return resolver.resolve(qname, "NAPTR") except dns.resolver.NXDOMAIN as e: e_nx += e raise e_nx