
    *DCf;              
          U d Z ddlZddlZddlZddlZddlmZmZmZm	Z	 ddl
ZddlZddlZddlZ G d dej                  j                         Z G d d      Z G d d	e      Z G d
 de      Z G d dej                  j                         Z G d de      Z G d de      Zej0                  eej2                  eej4                  eiZeeef   ed<   dedefdZde	eef   dddefdZde	eef   de de!de!def
dZ"dededdfdZ#ej4                  ZejH                  Z$ejJ                  Z%ejL                  Z&ej0                  ZejN                  Z'ejP                  Z(ejR                  Z)ejT                  Z*ejV                  Z+ej2                  Zy)zEDNS Options    N)AnyDictOptionalUnionc                   H    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZed        Zy)
OptionType               	   
               c                      yNi   clss    H/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/dns/edns.py_maximumzOptionType._maximum8           N)__name__
__module____qualname__NSIDDAUDHUN3UECSEXPIRECOOKIE	KEEPALIVEPADDINGCHAINEDEclassmethodr   r   r   r   r   r       sK    D
C
C
C
CFFIGE
C r   r   c                       e Zd ZdZdeeef   fdZddee	   dee
   fdZdefdZeded	d
dd fd       Zd Zd Zd Zd Zd Zd Zd Zd Zy)Optionz%Base class for all EDNS option types.otypec                 8    t         j                  |      | _        y)z_Initialize an option.

        *otype*, a ``dns.edns.OptionType``, is the option type.
        N)r   maker.   )selfr.   s     r   __init__zOption.__init__@   s    
  __U+
r   Nfilereturnc                     t         )zUConvert an option to wire format.

        Returns a ``bytes`` or ``None``.

        NotImplementedErrorr1   r3   s     r   to_wirezOption.to_wireG   s
     "!r   c                     t         Nr6   r1   s    r   to_textzOption.to_textO   s    !!r   parserdns.wire.Parserc                     t         )a  Build an EDNS option object from wire format.

        *otype*, a ``dns.edns.OptionType``, is the option type.

        *parser*, a ``dns.wire.Parser``, the parser, which should be
        restructed to the option length.

        Returns a ``dns.edns.Option``.
        r6   r   r.   r>   s      r   from_wire_parserzOption.from_wire_parserR   s
     "!r   c                 \    | j                         }|j                         }||k(  ry||kD  ryy)zCompare an EDNS option with another option of the same type.

        Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*.
        r      )r9   )r1   otherwireowires       r   _cmpzOption._cmp_   s1    
 ||~5=%<r   c                     t        |t              sy| j                  |j                  k7  ry| j                  |      dk(  S )NFr   
isinstancer-   r.   rI   r1   rF   s     r   __eq__zOption.__eq__l   s6    %(::$yy1$$r   c                     t        |t              sy| j                  |j                  k7  ry| j                  |      dk7  S )NTr   rK   rM   s     r   __ne__zOption.__ne__s   s6    %(::$yy1$$r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk  S Nr   rL   r-   r.   NotImplementedrI   rM   s     r   __lt__zOption.__lt__z   5    %(DJJ%++,E!!yy!##r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk  S rR   rS   rM   s     r   __le__zOption.__le__   5    %(DJJ%++,E!!yy1$$r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dk\  S rR   rS   rM   s     r   __ge__zOption.__ge__   rY   r   c                     t        |t              r| j                  |j                  k7  rt        S | j	                  |      dkD  S rR   rS   rM   s     r   __gt__zOption.__gt__   rV   r   c                 "    | j                         S r;   )r=   r<   s    r   __str__zOption.__str__   s    ||~r   r;   )r   r   r   __doc__r   r   strr2   r   r   bytesr9   r=   r+   rB   rI   rN   rP   rU   rX   r[   r]   r_   r   r   r   r-   r-   =   s    /,eJO4 ,"HSM "Xe_ "" " 
"Z 
"9J 
"x 
" 
"%%$
%
%
$
r   r-   c                        e Zd ZdZdeeef   deeef   f fdZdde	e
   de	e   fdZdefdZedeeef   d	d
defd       Z xZS )GenericOptionzwGeneric Option Class

    This class is used for EDNS option types for which we have no better
    implementation.
    r.   datac                     t         |   |       t        j                  j                  j                  |d      | _        y )NT)superr2   dnsrdataRdata	_as_bytesre   )r1   r.   re   	__class__s      r   r2   zGenericOption.__init__   s,    IIOO--dD9	r   r3   r4   c                 V    |r|j                  | j                         y | j                  S r;   )writere   r8   s     r   r9   zGenericOption.to_wire   "    JJtyy!99r   c                      d| j                   z  S )Nz
Generic %d)r.   r<   s    r   r=   zGenericOption.to_text   s    djj((r   r>   r?   c                 0     | ||j                               S r;   get_remainingrA   s      r   rB   zGenericOption.from_wire_parser   s     5&..011r   r;   )r   r   r   r`   r   r   ra   rb   r2   r   r   r9   r=   r+   r-   rB   __classcell__rl   s   @r   rd   rd      s    :eJO4 :E%*<M :HSM Xe_ ) ) 2*c/*24E2	2 2r   rd   c                        e Zd ZdZddedee   def fdZdefdZe	dede
fd	       Zdd
ee   dee   fdZedeeef   ddde
fd       Z xZS )	ECSOptionz!EDNS Client Subnet (ECS, RFC7871)addresssrclenscopelenc                    t         	|   t        j                         t        j
                  j                  |      }|t        j                  k(  rd| _	        |d}t        j                  j                  j                  |      }t        j                  j                  j                  |dd      }t        j                  j                  j                  |dd      }n|t        j                  k(  rd| _	        |d}t        j                  j                  j                  |      }t        j                  j                  j                  |dd      }t        j                  j                  j                  |dd      }nt!        d	      |J || _        || _        || _        t        j
                  j)                  ||      }t+        t-        j.                  |d
z              }|d| | _        |dz  }|dk7  rMt3        j4                  dt7        | j0                  dd       dd|z
  z  z        }| j0                  dd |z   | _        yy)a  *address*, a ``str``, is the client address information.

        *srclen*, an ``int``, the source prefix length, which is the
        leftmost number of bits of the address to be used for the
        lookup.  The default is 24 for IPv4 and 56 for IPv6.

        *scopelen*, an ``int``, the scope prefix length.  This value
        must be 0 in queries, and should be set in responses.
           N8   r      rD          zBad address family       @r   BrE      )rg   r2   r   r$   rh   inetaf_for_addresssocketAF_INET6familyri   rj   _as_ipv6_address_as_intAF_INET_as_ipv4_address
ValueErrorrx   ry   rz   	inet_ptonintmathceiladdrdatastructpackord)
r1   rx   ry   rz   afr   nbytesnbitslastrl   s
            r   r2   zECSOption.__init__   s    	(XX$$W- DK~iioo66w?GYY__,,VQ<Fyy..xC@H6>>!DK~iioo66w?GYY__,,VQ;Fyy..xB?H122!!! 88%%b'2TYYv|,- !&)
A:;;sCbc(:$;tE	?R$STD MM#2.5DM r   r4   c                 d    dj                  | j                  | j                  | j                        S )NzECS {}/{} scope/{})formatrx   ry   rz   r<   s    r   r=   zECSOption.to_text   s#    #**4<<dmmTTr   textc                    d}| j                         }d}t        |      dk(  r|d   }nPt        |      dk(  r(|d   |k7  rt        dj                  |             |d   }nt        dj                  |             |j	                  d      }|dk(  r|j                  d      \  }}d}n5|dk(  r|j                  d      \  }}}nt        dj                  |             	 t        |      }	 t        |      }	t        ||	|      S # t        $ r t        d	d
j                  |      z         w xY w# t        $ r t        ddj                  |      z         w xY w)a  Convert a string into a `dns.edns.ECSOption`

        *text*, a `str`, the text form of the option.

        Returns a `dns.edns.ECSOption`.

        Examples:

        >>> import dns.edns
        >>>
        >>> # basic example
        >>> dns.edns.ECSOption.from_text('1.2.3.4/24')
        >>>
        >>> # also understands scope
        >>> dns.edns.ECSOption.from_text('1.2.3.4/24/32')
        >>>
        >>> # IPv6
        >>> dns.edns.ECSOption.from_text('2001:4b98::1/64/64')
        >>>
        >>> # it understands results from `dns.edns.ECSOption.to_text()`
        >>> dns.edns.ECSOption.from_text('ECS 1.2.3.4/24/32')
        r$   NrD   r   r|   zcould not parse ECS from "{}"/0zinvalid scope z"{}": scope must be an integerzinvalid srclen z"{}": srclen must be an integer)splitlenr   r   countr   rw   )
r   optional_prefixtokensecs_text	n_slashesrx   tsrclentscopescopery   s
             r   	from_textzECSOption.from_text   sm   0  v;!ayH[AayO+ !@!G!G!MNNayH<CCDIJJNN3'	>'~~c2GWF!^'/~~c':$GWf<CCDIJJ	KE
	\F
 &%00  	 #C#J#J6#RR 	  	!$E$L$LW$UU 	s   D  (D*  'D'*'Er3   c                     t        j                  d| j                  | j                  | j                        | j
                  z   }|r|j                  |       y |S )N!HBB)r   r   r   ry   rz   r   rn   r1   r3   values      r   r9   zECSOption.to_wire  sG    KKT[[$--H4==X 	 JJuLr   r.   r>   r?   c                 z   |j                  d      \  }}}t        t        j                  |dz              }|j	                  |      }|dk(  r+d|z
  }t
        j                  j                  |d|z  z         }	n;|dk(  r+d|z
  }t
        j                  j                  |d|z  z         }	nt        d       | |	||      S )	Nr   r   rD          r|      zunsupported family)

get_structr   r   r   	get_bytesrh   ipv4	inet_ntoaipv6r   )
r   r.   r>   r   srcr   addrlenprefixpadaddrs
             r   rB   zECSOption.from_wire_parser&  s     $..v6Udiic	*+!!'*Q;g+C88%%fw}&<=Dq[w,C88%%fw}&<=D1224e$$r   rR   r;   )r   r   r   r`   ra   r   r   r2   r=   staticmethodr-   r   r   rb   r9   r+   r   r   rB   rt   ru   s   @r   rw   rw      s    +-6 -6Xc] -6S -6^U U 61 61 61 61pHSM Xe_  %*c/*%4E%	% %r   rw   c                       e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZed        Zy)EDECoder   rD   r|   r	   r   r
   r   r   r   r   r   r   r   r      r   r                        r   c                      yr   r   r   s    r   r   zEDECode._maximumT  r   r   N)r   r   r   OTHERUNSUPPORTED_DNSKEY_ALGORITHMUNSUPPORTED_DS_DIGEST_TYPESTALE_ANSWERFORGED_ANSWERDNSSEC_INDETERMINATEDNSSEC_BOGUSSIGNATURE_EXPIREDSIGNATURE_NOT_YET_VALIDDNSKEY_MISSINGRRSIGS_MISSINGNO_ZONE_KEY_BIT_SETNSEC_MISSINGCACHED_ERROR	NOT_READYBLOCKEDCENSOREDFILTERED
PROHIBITEDSTALE_NXDOMAIN_ANSWERNOT_AUTHORITATIVENOT_SUPPORTEDNO_REACHABLE_AUTHORITYNETWORK_ERRORINVALID_DATAr+   r   r   r   r   r   r   9  s    E#$ !"LMLNNLLIGHHJMML r   r   c                        e Zd ZdZh dZddeeef   dee   f fdZ	defdZ
ddee   dee   fd	Zed
eeef   dddefd       Z xZS )	EDEOptionz!Extended DNS Error (EDE, RFC8914)>   DSNSECDNSKEYDNSSECRRSIGsNXDOMAINcoder   c                     t         |   t        j                         t        j                  |      | _        |t        |t              st        d      || _
        y)z*code*, a ``dns.edns.EDECode`` or ``str``, the info code of the
        extended error.

        *text*, a ``str`` or ``None``, specifying additional information about
        the error.
        Nztext must be string or None)rg   r2   r   r*   r   r0   r   rL   ra   r   r   )r1   r   r   rl   s      r   r2   zEDEOption.__init__^  sH     	(LL&	JtS$9:;;	r   r4   c                 (    d j                    } j                   t        v rQt        j                   j                         }dj                   fd|j	                  d      D              }|d| dz  } j
                  |d j
                   z  }|S )NzEDE  c              3   ^   K   | ]$  }|j                   v r|n|j                          & y wr;   )_preserve_casetitle).0wordr1   s     r   	<genexpr>z$EDEOption.to_text.<locals>.<genexpr>q  s1        3 33Es   *-_z ()z: )r   r   r=   joinr   r   )r1   outputdescs   `  r   r=   zEDEOption.to_textm  s    		{#99??499-D88  JJsO D 4&l"F99 499+&&Fr   r3   c                     t        j                  d| j                        }| j                  || j                  j	                  d      z  }|r|j                  |       y |S )Nz!Hutf8)r   r   r   r   encodern   r   s      r   r9   zEDEOption.to_wirez  sP    D$)),99 TYY%%f--EJJuLr   r.   r>   r?   c                     t         j                  |j                               }|j                         }|r|d   dk(  r|d d }|j	                  d      }nd } | ||      S )NrE   r   r   )r   r0   
get_uint16rs   decode)r   r.   r>   r   r   btexts         r   rB   zEDEOption.from_wire_parser  sb     ||F--/0##%Bx1}CRyKK'EE4r   r;   )r   r   r   r`   r   r   r   ra   r   r2   r=   r   rb   r9   r+   r   r-   rB   rt   ru   s   @r   r   r   Y  s    +MNU7C<0   	HSM 	Xe_ 	  *c/* 4E 	   r   r   c                        e Zd Zdef fdZd
dedee   fdZdefdZ	e
deeef   dej                  j                  defd	       Z xZS )
NSIDOptionnsidc                 N    t         |   t        j                         || _        y r;   )rg   r2   r   r    r  )r1   r  rl   s     r   r2   zNSIDOption.__init__  s    )	r   r3   r4   c                 V    |r|j                  | j                         y | j                  S r;   )rn   r  r8   s     r   r9   zNSIDOption.to_wire  ro   r   c                     t        d | j                  D              r| j                  j                         }n-t        j                  | j                        j                         }d| S )Nc              3   4   K   | ]  }|d k\  xr |dk    yw)r   ~   Nr   )r   cs     r   r   z%NSIDOption.to_text.<locals>.<genexpr>  s      :1qDy&Q$Y&:s   zNSID )allr  r   binasciihexlify)r1   r   s     r   r=   zNSIDOption.to_text  sO    :		::II$$&E$$TYY/668Eugr   r.   r>   c                 .     | |j                               S r;   rr   rA   s      r   rB   zNSIDOption.from_wire_parser  s     6'')**r   r;   )r   r   r   rb   r2   r   r   r9   ra   r=   r+   r   r   rh   rG   Parserr-   rB   rt   ru   s   @r   r  r    so    U C 8E?   +*c/*+47HHOO+	+ +r   r  _type_to_classr.   r4   c                 @    t         j                  |       }|t        }|S )zReturn the class for the specified option type.

    The GenericOption class is used if a more specific class is not
    known.
    )r  getrd   )r.   r   s     r   get_option_classr    s#     

U
#C
{Jr   r>   r?   c                 f    t         j                  |       } t        |       }|j                  | |      S )a  Build an EDNS option object from wire format.

    *otype*, an ``int``, is the option type.

    *parser*, a ``dns.wire.Parser``, the parser, which should be
    restricted to the option length.

    Returns an instance of a subclass of ``dns.edns.Option``.
    )r   r0   r  rB   )r.   r>   r   s      r   option_from_wire_parserr    s/     OOE"E
5
!Cv..r   rG   currentolenc                     t         j                  j                  ||      }|j                  |      5  t	        | |      cddd       S # 1 sw Y   yxY w)ar  Build an EDNS option object from wire format.

    *otype*, an ``int``, is the option type.

    *wire*, a ``bytes``, is the wire-format message.

    *current*, an ``int``, is the offset in *wire* of the beginning
    of the rdata.

    *olen*, an ``int``, is the length of the wire-format option data

    Returns an instance of a subclass of ``dns.edns.Option``.
    N)rh   rG   r  restrict_tor  )r.   rG   r  r  r>   s        r   option_from_wirer    sE      XX__T7+F			D	! 6&uf56 6 6s   AAimplementationc                     | t         |<   y)zRegister the implementation of an option type.

    *implementation*, a ``class``, is a subclass of ``dns.edns.Option``.

    *otype*, an ``int``, is the option type.
    N)r  )r  r.   s     r   register_typer    s     +N5r   ),r`   r
  r   r   r   typingr   r   r   r   dns.enumrh   dns.inet	dns.rdatadns.wireenumIntEnumr   r-   rd   rw   r   r   r  r$   r*   r    r  __annotations__r  ra   r  rb   r   r  r  r!   r"   r#   r%   r&   r'   r(   r)   r   r   r   <module>r$     s  $      - -    !! :R Rj2F 28H% H%Vchh @:  : z+ +8 NNINNIOOZ)Z_% 
J 
3 
/S!/+<//"6S!6).69<6DG66*+# +j +T + nnnnnnnn						  	


nnr   