
    Eqg                         d Z ddlZddlmZmZmZ ddlZddlZej	        Z	ej
        Z
dededefdZdededefd	Zdedefd
ZdedefdZdedefdZ	 ddeeef         dee         defdZd ZdedefdZdS )z*Generic Internet address helper functions.    N)AnyOptionalTuplefamilytextreturnc                     | t           k    rt          j                            |          S | t          k    r t          j                            |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   s     :/var/www/html/env/lib/python3.11/site-packages/dns/inet.py	inet_ptonr   !   sN     x!!$'''	8		x!!$---!!    addressc                     | t           k    rt          j                            |          S | t          k    rt          j                            |          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   s     r   	inet_ntopr   6   sL     x!!'***	8		x!!'***!!r   c                     	 t           j                            |            t          S # t          $ r@ 	 t           j                            | d           t          cY S # t          $ r t          w xY ww xY w)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``.
    T)r   r   r   r
   	Exceptionr   r   
ValueErrorr   s    r   af_for_addressr   K   s    4      	HtT***OOO 	 	 			s    %( 
A2&AA2A..A2c                 
   	 t           j                            |           d         }|dk    o|dk    S # t          $ rE 	 t           j                            | d          d         }|dk    cY S # t          $ r t
          w xY ww xY w)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   )r   r   r   r   r   r   )r   firsts     r   is_multicastr"   a   s    ""4((+|,,   	H&&tT2215EC< 	 	 			s    03 
B+A,)B,A>>Bc                     	 t           j                            |            dS # t          $ r7 	 t           j                            | d           Y dS # t          $ r Y Y dS w xY ww xY 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   s    r   
is_addressr$   w   s    4   t   	HtT***44 	 	 	555		s&   # 
A$ A
A A$A  A$
high_tupleafc                    | \  }}|t          |          }|t          k    r||fS |t          k    r|                    d          }|dk     r||ddfS |d|         }||dz   d         }|                                r||dt          |          fS 	 ||dt          j        |          fS # t          $ r- t          j	        }t          j
        |||          ^^ }}	}|	cY S w xY wt          d|           )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_tups
             r   low_level_address_tupler;      s+    MGT	zG$$	W}}	xLLq55T1a((2A2;A ==?? 	3dAs5zz22	dAv'<U'C'CDD 	 	 	,H$0$hOOOOYq#JJJ	
 ""@B"@"@AAAs   B) )4C C c                 n    | t           j        k    rdS | t           j        k    rdS t          d|            )z:Return the 'any' address for the specified address family.z0.0.0.0z::r+   )r/   r
   r   r   )r&   s    r   
any_for_afr=      s=    	V^y	v		t
<<<
=
==r   c                     	 t           j                            |           S # t          $ r8 	 t           j                            |           cY S # t          $ r t
          w xY ww xY w)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.
    )r   r   canonicalizer   r   r   r   s    r   r?   r?      sz    x$$T***   	8((..... 	 	 		s    ! 
A#A
A#AA#)N)__doc__r/   typingr   r   r   dns.ipv4r   dns.ipv6r
   r   r.   strbytesr   r   r   boolr"   r$   r;   r=   r?    r   r   <module>rH      s  $ 1 0  ' ' ' ' ' ' ' ' ' '  
 .?"c " " " " " "*"c "E "c " " " "*     ,s t    ,S T    ( 6:!B !Bc3h!B%-c]!B!B !B !B !BH> > >s s      r   