
    ui^,                        S r SSKrSSKrSSKrSSKrSSKrSSKr " S S\R                  R                  5      r
 " S S5      r " S S\5      r " S	 S
\5      r\
R                  \0rS rS rS rS r\
R(                  r\
R*                  r\
R,                  r\
R.                  r\
R                  r\
R0                  r\
R2                  r\
R4                  r\
R6                  r\
R8                  rg)zEDNS Options    Nc                   L    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSr\S 5       rSrg)
OptionType                  	   
            c                     g)Ni   )clss    ?/home/kodi/.kodi/addons/script.module.dnspython/lib/dns/edns.py_maximumOptionType._maximum3   s        r   N)__name__
__module____qualname____firstlineno__NSIDDAUDHUN3UECSEXPIRECOOKIE	KEEPALIVEPADDINGCHAINclassmethodr   __static_attributes__r   r   r   r   r      sF    D
C
C
C
CFFIGE r   r   c                   h    \ rS rSrSrS rSS jr\S 5       rS r	S r
S	 rS
 rS rS rS rS rSrg)Option8   z%Base class for all EDNS option types.c                 8    [         R                  U5      U l        g)z@Initialize an option.

*otype*, an ``int``, is the option type.
N)r   makeotype)selfr,   s     r   __init__Option.__init__<   s    
  __U+
r   Nc                     [         e)zEConvert an option to wire format.

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

NotImplementedErrorr-   files     r   to_wireOption.to_wireC   s
     "!r   c                     [         e)zBuild an EDNS option object from wire format.

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

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

Returns a ``dns.edns.Option``.
r1   r   r,   parsers      r   from_wire_parserOption.from_wire_parserK   s
     "!r   c                 \    U R                  5       nUR                  5       nX#:X  a  gX#:  a  gg)zCompare an EDNS option with another option of the same type.

Returns < 0 if < *other*, 0 if == *other*, and > 0 if > *other*.
r      )r5   )r-   otherwireowires       r   _cmpOption._cmpX   s-    
 ||~=<r   c                     [        U[        5      (       d  gU R                  UR                  :w  a  gU R                  U5      S:H  $ )NFr   
isinstancer(   r,   rB   r-   r?   s     r   __eq__Option.__eq__e   s9    %((::$yy1$$r   c                     [        U[        5      (       d  gU R                  UR                  :w  a  gU R                  U5      S:g  $ )NTr   rE   rG   s     r   __ne__Option.__ne__l   s9    %((::$yy1$$r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:  $ Nr   rF   r(   r,   NotImplementedrB   rG   s     r   __lt__Option.__lt__s   9    %((

ekk)!!yy!##r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:*  $ rN   rO   rG   s     r   __le__Option.__le__y   9    %((

ekk)!!yy1$$r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:  $ rN   rO   rG   s     r   __ge__Option.__ge__   rW   r   c                     [        U[        5      (       a  U R                  UR                  :w  a  [        $ U R	                  U5      S:  $ rN   rO   rG   s     r   __gt__Option.__gt__   rS   r   c                 "    U R                  5       $ N)to_textr-   s    r   __str__Option.__str__   s    ||~r   r,   r_   )r   r   r   r   __doc__r.   r5   r%   r:   rB   rH   rK   rQ   rU   rY   r\   rb   r&   r   r   r   r(   r(   8   sK    /," 
" 
"%%$%%$r   r(   c                   L   ^  \ rS rSrSrU 4S jrSS jrS r\S 5       r	Sr
U =r$ )	GenericOption   zkGeneric Option Class

This class is used for EDNS option types for which we have no better
implementation.
c                    > [         TU ]  U5        [        R                  R                  R                  US5      U l        g )NT)superr.   dnsrdataRdata	_as_bytesdata)r-   r,   ro   	__class__s      r   r.   GenericOption.__init__   s,    IIOO--dD9	r   c                 `    U(       a  UR                  U R                  5        g U R                  $ r_   )writero   r3   s     r   r5   GenericOption.to_wire   s    JJtyy!99r   c                      SU R                   -  $ )Nz
Generic %drd   ra   s    r   r`   GenericOption.to_text   s    djj((r   c                 .    U " XR                  5       5      $ r_   )get_remainingr8   s      r   r:   GenericOption.from_wire_parser   s    5..011r   )ro   r_   )r   r   r   r   re   r.   r5   r`   r%   r:   r&   __classcell__rp   s   @r   rg   rg      s+    :) 2 2r   rg   c                   `   ^  \ rS rSrSrS	U 4S jjrS r\S 5       rS
S jr	\
S 5       rSrU =r$ )	ECSOption   z!EDNS Client Subnet (ECS, RFC7871)c                   > [         T	U ]  [        R                  5        [        R
                  R                  U5      nU[        R                  :X  a  SU l	        Uc  Sn[        R                  R                  R                  U5      n[        R                  R                  R                  USS5      n[        R                  R                  R                  USS5      nOU[        R                  :X  a  SU l	        Uc  Sn[        R                  R                  R                  U5      n[        R                  R                  R                  USS5      n[        R                  R                  R                  USS5      nO[!        S	5      eXl        X l        X0l        [        R
                  R)                  XA5      n[+        [,        R.                  " US
-  5      5      nUSU U l        US-  nUS:w  aN  [2        R4                  " S[7        U R0                  SS 5      SSU-
  -  -  5      nU R0                  SS U-   U l        gg)aZ  *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.
   Nr)   r      r=          zBad address family       @r
   Br>      )rj   r.   r   r   rk   inetaf_for_addresssocketAF_INET6familyrl   rm   _as_ipv6_address_as_intAF_INET_as_ipv4_address
ValueErroraddresssrclenscopelen	inet_ptonintmathceiladdrdatastructpackord)
r-   r   r   r   afr   nbytesnbitslastrp   s
            r   r.   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:;;s"4==#56$1u9:MNPD MM#2.5DM r   c                 d    SR                  U R                  U R                  U R                  5      $ )NzECS {}/{} scope/{})formatr   r   r   ra   s    r   r`   ECSOption.to_text   s(    #**4<<+/==: 	:r   c                    SnU R                  5       nSn[        U5      S:X  a  US   nOR[        U5      S:X  a)  US   U:w  a  [        SR                  U 5      5      eUS   nO[        SR                  U 5      5      eUR	                  S5      nUS:X  a  UR                  S5      u  pVSnO5US:X  a  UR                  S5      u  pVnO[        SR                  U 5      5      e [        U5      n [        U5      n[        XVU5      $ ! [         a    [        SS	R                  U5      -   5      ef = f! [         a    [        S
SR                  U5      -   5      ef = f)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   Nr=   r   r   zcould not parse ECS from "{}"/zinvalid scope z"{}": scope must be an integerzinvalid srclen z"{}": srclen must be an integer)splitlenr   r   countr   r}   )textoptional_prefixtokensecs_text	n_slashesr   r   scopes           r   	from_textECSOption.from_text   sv   0  v;!ayH[AayO+ !@!G!G!MNNayH<CCDIJJNN3'	>&nnS1OGE!^%-^^C%8"GU<CCDIJJ	MJE	O[F %00  	M-=DDUKL M M	M
  	O.>EEfMN O O	Os   D +D- (D*-(Ec                     [         R                  " SU R                  U R                  U R                  5      U R
                  -   nU(       a  UR                  U5        g U$ )N!HBB)r   r   r   r   r   r   rs   )r-   r4   values      r   r5   ECSOption.to_wire  sB    VT[[$++t}}MJJuLr   c                 |   UR                  S5      u  p4n[        [        R                  " US-  5      5      nUR	                  U5      nUS:X  a+  SU-
  n[
        R                  R                  USU-  -   5      n	O<US:X  a+  SU-
  n[
        R                  R                  USU-  -   5      n	O[        S5      eU " XU5      $ )	Nr   r   r=          r      zunsupported family)

get_structr   r   r   	get_bytesrk   ipv4	inet_ntoaipv6r   )
r   r,   r9   r   srcr   addrlenprefixpadaddrs
             r   r:   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4e$$r   )r   r   r   r   r   rN   r_   )r   r   r   r   re   r.   r`   staticmethodr   r5   r%   r:   r&   rz   r{   s   @r   r}   r}      s?    +-6^: 41 41l % %r   r}   c                 B    [         R                  U 5      nUc  [        nU$ )zxReturn the class for the specified option type.

The GenericOption class is used if a more specific class is not
known.
)_type_to_classgetrg   )r,   r   s     r   get_option_classr   3  s#     

U
#C
{Jr   c                 d    [        U 5      n[        R                  U 5      n UR                  X5      $ )zBuild 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   r   r+   r:   )r,   r9   r   s      r   option_from_wire_parserr   @  s-     5
!COOE"E..r   c                     [         R                  R                  X5      nUR                  U5         [	        X5      sSSS5        $ ! , (       d  f       g= f)aV  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)rk   r@   Parserrestrict_tor   )r,   r@   currentolenr9   s        r   option_from_wirer   O  s8     XX__T+F			D	!&u5 
"	!	!s   A
Ac                     U [         U'   g)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   )implementationr,   s     r   register_typer   a  s     +N5r   )re   r   r   r   dns.enumrk   dns.inet	dns.rdataenumIntEnumr   r(   rg   r}   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r   r   r   <module>r      s   $       !! 6T Tn2F 24C% C%N NNI
/6$+ nnnnnnnn						  	


r   