/usr/lib/python3.9/site-packages/dns/__pycache__
Edit: /usr/lib/python3.9/site-packages/dns/__pycache__/inet.cpython-39.pyc (4603B)
a
Me @ s d Z ddlZddlmZmZmZ ddlZddlZej Z ej
Z
eee
dddZee
eddd Zeed
ddZeed
d
dZeed
ddZdeeef ee edddZdd Zeed
ddZdS )z*Generic Internet address helper functions. N)AnyOptionalTuple)familytextreturnc C s2 | t krtj|S | tkr*tj|dS tdS )a Convert the textual form of a network address into its binary form.
*family* is an ``int``, the address family.
*text* is a ``str``, the textual address.
Raises ``NotImplementedError`` if the address family specified is not
implemented.
Returns a ``bytes``.
TN)AF_INETdnsipv4 inet_atonAF_INET6ipv6NotImplementedError)r r r ,/usr/lib/python3.9/site-packages/dns/inet.py inet_pton! s
r )r addressr c C s0 | t krtj|S | tkr(tj|S tdS )a0 Convert the binary form of a network address into its textual form.
*family* is an ``int``, the address family.
*address* is a ``bytes``, the network address in binary form.
Raises ``NotImplementedError`` if the address family specified is not
implemented.
Returns a ``str``.
N)r r r
Z inet_ntoar r
r )r r r r r inet_ntop6 s
r )r r c C sZ zt j| tW S tyT zt j| d tW Y S tyN tY n0 Y n0 dS )zDetermine the address family of a textual-form network address.
*text*, a ``str``, the textual address.
Raises ``ValueError`` if the address family cannot be determined
from the input.
Returns an ``int``.
TN)r r
r r Exceptionr
r
ValueErrorr r r r af_for_addressK s
r c C sr z"t j| d }|dko |dkW S tyl z t j| dd }|dkW Y S tyf tY n0 Y n0 dS )zIs the textual-form network address a multicast address?
*text*, a ``str``, the textual address.
Raises ``ValueError`` if the address family cannot be determined
from the input.
Returns a ``bool``.
r T N)r r
r r r
r )r firstr r r is_multicasta s r c C sX zt j| W dS tyR zt j| d W Y dS tyL Y Y dS 0 Y n0 dS )z{Is the specified string an IPv4 or IPv6 address?
*text*, a ``str``, the textual address.
Returns a ``bool``.
TFN)r r
r r r
r r r r
is_addressw s r )
high_tupleafr c
C s | \}}|du rt |}|tkr(||fS |tkr|d}|dk rN||ddfS |d| }||d d }| r||dt|fS z||dt|fW S ty tj }tj
|||d^^ }} }| Y S 0 ntd| dS )aX Given a "high-level" address tuple, i.e.
an (address, port) return the appropriate "low-level" address tuple
suitable for use in socket calls.
If an *af* other than ``None`` is provided, it is assumed the
address in the high-level tuple is valid and has that af. If af
is ``None``, then af_for_address will be called.
N%r )flagsunknown address family )r r r findisdigitintsocketZif_nametoindexAttributeErrorZAI_NUMERICHOSTZgetaddrinfor )
r r r portiZaddrpartZscopeZai_flags_tupr r r low_level_address_tuple s(
r- c C s. | t jkrdS | t jkrdS td| dS )z:Return the 'any' address for the specified address family.z0.0.0.0z::r# N)r' r r r )r r r r
any_for_af s
r. c C sP zt j| W S tyJ zt j| W Y S tyD tY n0 Y n0 dS )a Verify that *address* is a valid text form IPv4 or IPv6 address and return its
canonical text form. IPv6 addresses with scopes are rejected.
*text*, a ``str``, the address in textual form.
Raises ``ValueError`` if the text is not valid.
N)r r
canonicalizer r
r r r r r r/ s r/ )N)__doc__r' typingr r r Zdns.ipv4r Zdns.ipv6r r r&