관리-도구
편집 파일: inet.cpython-38.pyc
U /?�f� � @ s� d Z ddlZddlmZmZmZ ddlZddlZej Z ej Z eee d�dd�Zee ed�dd �Zeed �dd�Zeed �d d�Zeed �dd�Zdeeef ee ed�dd�Zdd� Zeed �dd�ZdS )z*Generic Internet address helper functions.� N)�Any�Optional�Tuple)�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 �6/opt/hc_python/lib/python3.8/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_ntop6 s r )r r c C s^ zt j�| � tW S tk rX zt j�| d� tW Y S tk rR 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_addressK s r c C sv z"t j�| �d }|dko |dkW S tk rp z t j�| d�d }|dkW Y S tk rj 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_multicasta s r c C s\ zt j�| � W dS tk rV zt j�| d� W Y dS tk rP Y Y 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_addressw s r )� high_tuple�afr c C s� | \}}|dkrt |�}|tkr(||fS |tkr�|�d�}|dk rN||ddfS |d|� }||d d� }|�� r�||dt|�fS z||dt�|�fW S tk r� tj }tj |||d�^�^ }} }| Y 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 � )�flags�unknown address family )r r r �find�isdigit�int�socket�if_nametoindex�AttributeError�AI_NUMERICHOST�getaddrinfor ) r r r �port�iZaddrpart�scopeZai_flags�_�tupr r r �low_level_address_tuple� s( r2 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 r3 c C sT zt j�| �W S tk rN zt j�| �W Y S tk rH t�Y nX Y nX 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 r4 � s r4 )N)�__doc__r( �typingr r r Zdns.ipv4r Zdns.ipv6r r r'