
    ,h                         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y)z*Generic Internet address helper functions.    N)AnyOptionalTuplefamilytextreturnc                     | t         k(  rt        j                  j                  |      S | t        k(  r t        j
                  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     J/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/dns/inet.py	inet_ptonr   !   sF     xx!!$''	8	xx!!$--!!    addressc                     | t         k(  rt        j                  j                  |      S | t        k(  rt        j
                  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   sD     xx!!'**	8	xx!!'**!!r   c                     	 t         j                  j                  |        t        S # t        $ r= 	 t         j
                  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  	HHtT*O 			s    $' 	A-%AA-A))A-c                     	 t         j                  j                  |       d   }|dk\  xr |dk  S # t        $ r? 	 t         j                  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(+|,, 	HH&&tT215EC< 			s    -0 	A8'A$!A8$A44A8c                     	 t         j                  j                  |        y# t        $ r4 	 t         j                  j                  | d       Y y# t        $ r Y Y y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   sY    4  	HHtT* 			s&   " 	A A	AAAA
high_tupleafc                    | \  }}|t        |      }|t        k(  r||fS |t        k(  rb|j                  d      }|dk  r||ddfS |d| }||dz   d }|j	                         r||dt        |      fS 	 ||dt        j                  |      fS t        d|       # t        $ r2 t        j                  }t        j                  |||      ^^ }}	}|	cY S w xY w)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q5T1a((2A;A ==?dAs5z22	dAv'<'<U'CDD "$;B4"@AA  	,,H$00$hOOYq#J	s   2B 8CCc                 n    | t         j                  k(  ry| t         j                  k(  ry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=      s3    	V^^	v	
 7t<
==r   c                     	 t         j                  j                  |       S # t        $ r6 	 t         j                  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    xx$$T** 	88((.. 		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  ' '  
 ..??"c " " "*"c "E "c "*  ,s t ,S T ( 6:!Bc3h!B%-c]!B!BH>s s r   