File: //home/arjun/projects/env/lib64/python3.10/site-packages/dns/__pycache__/inet.cpython-310.pyc
o
!we� � @ s� d Z ddlZddlmZmZmZ ddlZddlZej Z ej
Z
dedede
fdd�Zded e
defd
d�Zdedefdd
�Zdedefdd�Zdedefdd�Z ddeeef dee defdd�Zdd� ZdS )z*Generic Internet address helper functions.� N)�Any�Optional�Tuple�family�text�returnc C s. | t kr
tj�|�S | tkrtj�|d�S t�)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``.
T)�AF_INET�dns�ipv4� inet_aton�AF_INET6�ipv6�NotImplementedError)r r � r �A/home/arjun/projects/env/lib/python3.10/site-packages/dns/inet.py� inet_pton! s
r �addressc C s, | t kr
tj�|�S | tkrtj�|�S t�)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``.
)r r r
� inet_ntoar r
r )r r r r r � inet_ntop6 s
r c C sN z t j�| � tW S ty& zt j�| d� tW Y S ty% t�w w )z�Determine 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``.
T)r r
r r � Exceptionr
r �
ValueError�r r r r �af_for_addressK s
��r c C sf zt j�| �d }|dko|dkW S ty2 zt j�| d�d }|dkW Y S ty1 t�w w )z�Is 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� )r r
r r r
r )r �firstr r r �is_multicasta s ��r c C sP z t j�| � W dS ty' zt j�| d� W Y dS ty& Y Y dS w w )z{Is the specified string an IPv4 or IPv6 address?
*text*, a ``str``, the textual address.
Returns a ``bool``.
TF)r r
r r r
r r r r �
is_addressw s ��r �
high_tuple�afc
C s� | \}}|du rt |�}|tkr||fS |tkrg|�d�}|dk r'||ddfS |d|� }||d d� }|�� rA||dt|�fS z
||dt�|�fW S tyf tj }tj
|||d�^�^ }} }| Y S w td|� ���)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 � )�flags�unknown address family )r r r �find�isdigit�int�socket�if_nametoindex�AttributeError�AI_NUMERICHOST�getaddrinfor )
r r r �port�i�addrpart�scope�ai_flags�_�tupr r r �low_level_address_tuple� s*
�r4 c C s* | t jkrdS | t jkrdS td| � ���)z:Return the 'any' address for the specified address family.z0.0.0.0z::r$ )r( r r r )r r r r �
any_for_af� s
r5 )N)�__doc__r( �typingr r r �dns.ipv4r �dns.ipv6r r r'