File: //opt/alt/python37/lib/python3.7/site-packages/dns/__pycache__/inet.cpython-37.pyc
B
��f� � @ s� d Z ddlmZmZmZ ddlZddlZddlZej Z ej
Z
eee
d�dd�Zee
ed�dd �Zeed
�dd�Zeed
�d
d�Zeed
�dd�Zdeeef ee ed�dd�ZdS )z*Generic Internet address helper functions.� )�Any�Optional�TupleN)�family�text�returnc C s2 | t krtj�|�S | tkr*tj�|d�S t�dS )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_INET�dns�ipv4� inet_aton�AF_INET6�ipv6�NotImplementedError)r r � r �9/opt/alt/python37/lib/python3.7/site-packages/dns/inet.py� inet_pton# s
r )r �addressr c C s0 | t krtj�|�S | tkr(tj�|�S t�dS )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
� inet_ntoar r
r )r r r r r � inet_ntop8 s
r )r r c C sV yt j�| � tS tk
rP yt j�| d� tS tk
rJ t�Y nX Y nX dS )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``.
TN)r r
r r � Exceptionr
r �
ValueError)r r r r �af_for_addressM s r c C sn y t j�| �d }|dko |dkS tk
rh yt j�| d�d }|dkS tk
rb t�Y nX Y nX dS )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� N)r r
r r r
r )r �firstr r r �is_multicastc s r c C sR yt j�| � dS tk
rL yt j�| d� dS tk
rF dS X Y nX 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_addressy s r )�
high_tuple�afr c
C s� | \}}|dkrt |�}|tkr(||fS |tkr�|�d�}|dk rN||ddfS |d|� }||d d� }|�� r�||dt|�fS y||dt�|�fS tk
r� tj }tj
|||d�^�^ }} }| S X 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 � )�flagszunknown address family )r r r �find�isdigit�int�socket�if_nametoindex�AttributeError�AI_NUMERICHOST�getaddrinfor )
r r r �port�iZaddrpartZscopeZai_flags�_�tupr r r �low_level_address_tuple� s(
r/ )N)�__doc__�typingr r r r&