
    s8                        S r SSKJ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K
rSSKrSSKJrJrJr   SSKrSr\4S jrSr\4S jr\" S	5      rS
 rS r " S S\5      r " S S\5      r0 rSr \RB                  " 5       r"S r#SS jr$SS jr% " S S\RL                  RN                  5      r(S\RR                  RT                  4S jr+g! \ a    SSKr Nf = f)z
DNS rdata.    )BytesION   )xrangestring_types	text_type    c           	          [         R                  " U 5      nSR                  [        S[	        U5      U5       Vs/ s H	  nX#X1-    PM     sn5      R                  5       $ s  snf )zsConvert a binary string into its hex encoding, broken up into chunks
of chunksize characters separated by a space.
    r   )binasciihexlifyjoinrangelendecodedata	chunksizelineis       lib/third_party/dns/rdata.py_hexifyr   (   sd    
 D!D99q#d)Y797  Q]+79 ::@&(C 9   Ac           	          [         R                  " U 5      nSR                  [        S[	        U5      U5       Vs/ s H	  nX#X1-    PM     sn5      R                  5       $ s  snf )zvConvert a binary string into its base64 encoding, broken up into chunks
of chunksize characters separated by a space.
r
   r   )base64	b64encoder   r   r   r   r   s       r   
_base64ifyr   5   sd    
 D!D99q#d)Y797  Q]+79 ::@&(C 9r   s   "\c                 (   [        U [        5      (       a  U R                  5       n [        U [        5      (       d  [        U 5      n SnU  HD  nU[        ;   a  US[        U5      -   -  nM   US:  a  US:  a  U[        U5      -  nM<  USU-  -  nMF     U$ )z7Escape the characters in a quoted string which need it. \r      z\%03d)
isinstancer   encode	bytearray	__escapedchr)qstringtextcs      r   	_escapifyr)   A   s     '9%%.."gy))G$D	>D3q6M!D$Y1t8CFNDHqL D  K    c                 p    [        [        U 5      S-
  SS5       H  nX   S:w  d  M  U SUS-    s  $    U SS $ )zDetermine the index of greatest byte that isn't all zeros, and
return the bitmap that contains all the bytes less than that index.
r   r   )r   r   )whatr   s     r   _truncate_bitmapr.   T   sF    
 CIM2r*7a<1q5>! + !9r*   c                       \ rS rSrSrSS/rS rS rS rSS	 jr	SS
 jr
SS jrS rS rS rS rS rS rS rS rS rS rS r\SS j5       r\SS j5       rSS jrSrg)Rdata_   z#Base class for all DNS rdata types.rdclassrdtypec                     Xl         X l        g)zInitialize an rdata.

*rdclass*, an ``int`` is the rdataclass of the Rdata.
*rdtype*, an ``int`` is the rdatatype of the Rdata.
Nr2   r3   )selfr2   r3   s      r   __init__Rdata.__init__d   s     r*   c                 6    [         R                  R                  $ )aY  Return the type a Rdata covers.

DNS SIG/RRSIG rdatas apply to a specific type; this type is
returned by the covers() function.  If the rdata type is not
SIG or RRSIG, dns.rdatatype.NONE is returned.  This is useful when
creating rdatasets, allowing the rdataset to contain only RRSIGs
of a particular type, e.g. RRSIG(NS).

Returns an ``int``.
)dns	rdatatypeNONEr6   s    r   coversRdata.coversn   s     }}!!!r*   c                 B    U R                  5       S-  U R                  -  $ )zReturn a 32-bit type value, the least significant 16 bits of
which are the ordinary DNS type, and the upper 16 bits of which are
the "covered" type, if any.

Returns an ``int``.
   )r>   r3   r=   s    r   extended_rdatatypeRdata.extended_rdatatype|   s     {{}"T[[00r*   Nc                     [         e)z6Convert an rdata to text format.

Returns a ``text``.
NotImplementedErrorr6   origin
relativizekws       r   to_textRdata.to_text   
     "!r*   c                     [         e)z8Convert an rdata to wire format.

Returns a ``binary``.
rE   r6   filecompressrH   s       r   to_wireRdata.to_wire   rM   r*   c                 \    [        5       nU R                  USU5        UR                  5       $ )z|Convert rdata to a format suitable for digesting in hashes.  This
is also the DNSSEC canonical form.

Returns a ``binary``.
N)r   rR   getvalue)r6   rH   fs      r   to_digestableRdata.to_digestable   s'     IQf%zz|r*   c                     [         R                  R                  U R                  U R                  U R                  5       5        g)a  Check that the current contents of the rdata's fields are
valid.

If you change an rdata by assigning to its fields,
it is a good idea to call validate() when you are done making
changes.

Raises various exceptions if there are problems.

Returns ``None``.
N)r:   rdata	from_textr2   r3   rK   r=   s    r   validateRdata.validate   s(     			DLL$++t||~Fr*   c                    U R                  5       nU[        R                  R                  :X  a  SnO%S[        R                  R	                  U5      -   S-   nS[        R
                  R	                  U R                  5      -   S-   [        R                  R	                  U R                  5      -   U-   S-   [        U 5      -   S-   $ )Nr   ()z<DNS  z rdata: >)	r>   r:   r;   r<   rK   
rdataclassr2   r3   str)r6   r>   ctexts      r   __repr__Rdata.__repr__   s    S]]'''E#--//77#=E//==C}}$$T[[1249:<FG4y 	r*   c                 "    U R                  5       $ N)rK   r=   s    r   __str__Rdata.__str__   s    ||~r*   c                     U R                  [        R                  R                  5      nUR                  [        R                  R                  5      nX#:X  a  gX#:  a  gg)zCompare an rdata with another rdata of the same rdtype and
rdclass.

Return < 0 if self < other in the DNSSEC ordering, 0 if self
== other, and > 0 if self > other.

r   r   r,   )rW   r:   nameroot)r6   otherourtheirs       r   _cmp
Rdata._cmp   sG       /##CHHMM2<[r*   c                     [        U[        5      (       d  gU R                  UR                  :w  d  U R                  UR                  :w  a  gU R	                  U5      S:H  $ )NFr   r!   r0   r2   r3   rr   r6   ro   s     r   __eq__Rdata.__eq__   sH    %''<<5==(DKK5<<,Gyy1$$r*   c                     [        U[        5      (       d  gU R                  UR                  :w  d  U R                  UR                  :w  a  gU R	                  U5      S:g  $ )NTr   ru   rv   s     r   __ne__Rdata.__ne__   sH    %''<<5==(DKK5<<,Gyy1$$r*   c                     [        U[        5      (       a4  U R                  UR                  :w  d  U R                  UR                  :w  a  [        $ U R                  U5      S:  $ Nr   r!   r0   r2   r3   NotImplementedrr   rv   s     r   __lt__Rdata.__lt__   sH    %''-1L!!yy!##r*   c                     [        U[        5      (       a4  U R                  UR                  :w  d  U R                  UR                  :w  a  [        $ U R                  U5      S:*  $ r}   r~   rv   s     r   __le__Rdata.__le__   H    %''-1L!!yy1$$r*   c                     [        U[        5      (       a4  U R                  UR                  :w  d  U R                  UR                  :w  a  [        $ U R                  U5      S:  $ r}   r~   rv   s     r   __ge__Rdata.__ge__   r   r*   c                     [        U[        5      (       a4  U R                  UR                  :w  d  U R                  UR                  :w  a  [        $ U R                  U5      S:  $ r}   r~   rv   s     r   __gt__Rdata.__gt__   sH    %''-1L!!yy!##r*   c                 f    [        U R                  [        R                  R                  5      5      $ ri   )hashrW   r:   rm   rn   r=   s    r   __hash__Rdata.__hash__   s     D&&sxx}}566r*   c                     [         eri   rE   )clsr2   r3   tokrH   rI   s         r   r[   Rdata.from_text       !!r*   c                     [         eri   rE   r   r2   r3   wirecurrentrdlenrH   s          r   	from_wireRdata.from_wire   r   r*   c                     g)zGConvert any domain names in the rdata to the specified
relativization.
N )r6   rH   rI   s      r   choose_relativityRdata.choose_relativity   s    r*   r5   NTNNri   )__name__
__module____qualname____firstlineno____doc__	__slots__r7   r>   rB   rK   rR   rW   r\   rf   rj   rr   rw   rz   r   r   r   r   r   classmethodr[   r   r   __static_attributes__r   r*   r   r0   r0   _   s    -H%I"1""	G"%%$%%$7 " " " "r*   r0   c                   n   ^  \ rS rSrSrS/rU 4S jrS
S jr\S
S j5       r	SS jr
\SS j5       rS	rU =r$ )GenericRdatai  zGeneric Rdata Class

This class is used for rdata types for which we have no better
implementation.  It implements the DNS "unknown RRs" scheme.
r   c                 8   > [         [        U ]  X5        X0l        g ri   )superr   r7   r   )r6   r2   r3   r   	__class__s       r   r7   GenericRdata.__init__  s    lD*7;	r*   c                 ^    S[        U R                  5      -  [        U R                  5      -   $ )Nz\# %d )r   r   r   rG   s       r   rK   GenericRdata.to_text  s#    3tyy>)GDII,>>>r*   c                 .   UR                  5       nUR                  5       (       a  UR                  S:w  a  [        R                  R                  S5      eUR                  5       n/ n UR                  5       nUR                  5       (       a  O+UR                  UR                  R                  5       5        MQ  SR                  U5      n	[        R                  " U	5      n
[        U
5      U:w  a  [        R                  R                  S5      eU " XU
5      $ )N\#z$generic rdata does not start with \#r*   z'generic rdata hex data has wrong length)getis_identifiervaluer:   	exceptionSyntaxErrorget_intis_eol_or_eofappendr"   r   r   	unhexlifyr   )r   r2   r3   r   rH   rI   tokenlengthchunkshexr   s              r   r[   GenericRdata.from_text  s    	""$$u(<--++79 9GGIE""$$MM%++,,./	 
 hhv!!#&t9--++9; ;7D))r*   c                 :    UR                  U R                  5        g ri   )writer   rO   s       r   rR   GenericRdata.to_wire*  s    

499r*   c                     U " XX4XE-    5      $ ri   r   r   s          r   r   GenericRdata.from_wire-  s    7D'/$BCCr*   )r   r   r   ri   )r   r   r   r   r   r   r7   rK   r   r[   rR   r   r   __classcell__)r   s   @r   r   r     sJ     I? * *& D Dr*   r   zdns.rdtypesc                    S n[         R                  X45      n[        R                  R	                  U 5      n[        R
                  R	                  U5      nUR                  SS5      nU(       d^  [         R                  [        R
                  R                  U45      nU(       d(   U" SR                  [        XE/5      5      nU[         X4'   U(       a  [        X55      nU$ [        nU$ ! [         aX     U" SR                  [        SU/5      5      nU[         [        R                  R                  U4'    Nj! [         a    S n  Nyf = ff = f)Nc                     [            [        U 5      nU R                  S5      nUSS   H  n[        X5      nM     UsS S S 5        $ ! , (       d  f       g = f)N.r   )_import_lock
__import__splitgetattr)rm   mod
componentscomps       r   import_module&get_rdata_class.<locals>.import_module7  sC    T"CCJ"12c( ' \\s   5A
A-_r   ANY)_rdata_modulesr   r:   rc   rK   r;   replacer   r   _module_prefixImportErrorr   r   )r2   r3   r   r   rdclass_textrdtype_textr   s          r   get_rdata_classr   5  s8    

g.
/C>>))'2L--''/K%%c3/K  #--"3"3V!<=
#CHHn.:.I %J K4701 c' J J  '.272F )G HCCFNCNN$6$6#?@" Cs+   ('C+ +
E6AD99E	EE		Ec           	         [        U[        5      (       a  [        R                  R	                  U5      n[        X5      nU[        :w  a  UR                  5       nUR                  U5        UR                  5       (       aS  UR                  S:X  aC  [        R                  XX#U5      n[        XUR                  S[        UR                  5      U5      $ UR                  XX#U5      $ )a
  Build an rdata object from text format.

This function attempts to dynamically load a class which
implements the specified rdata class and type.  If there is no
class-and-type-specific implementation, the GenericRdata class
is used.

Once a class is chosen, its from_text() class method is called
with the parameters to this function.

If *tok* is a ``text``, then a tokenizer is created and the string
is used as its input.

*rdclass*, an ``int``, the rdataclass.

*rdtype*, an ``int``, the rdatatype.

*tok*, a ``dns.tokenizer.Tokenizer`` or a ``text``.

*origin*, a ``dns.name.Name`` (or ``None``), the
origin to use for relative names.

*relativize*, a ``bool``.  If true, name will be relativized to
the specified origin.

Returns an instance of the chosen Rdata subclass.
r   r   )r!   r   r:   	tokenizer	Tokenizerr   r   r   ungetr   r   r[   r   r   r   )r2   r3   r   rH   rI   r   r   rZ   s           r   r[   r[   X  s    : #|$$mm%%c*
'
*C
l			%  ;;% !**7C+57EWejj!S_#% %==#zBBr*   c                 |    [         R                  R                  U5      n[        X5      nUR	                  XX#XE5      $ )a  Build an rdata object from wire format

This function attempts to dynamically load a class which
implements the specified rdata class and type.  If there is no
class-and-type-specific implementation, the GenericRdata class
is used.

Once a class is chosen, its from_wire() class method is called
with the parameters to this function.

*rdclass*, an ``int``, the rdataclass.

*rdtype*, an ``int``, the rdatatype.

*wire*, a ``binary``, the wire-format message.

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

*rdlen*, an ``int``, the length of the wire-format rdata

*origin*, a ``dns.name.Name`` (or ``None``).  If not ``None``,
then names will be relativized to this origin.

Returns an instance of the chosen Rdata subclass.
)r:   wiredata
maybe_wrapr   r   )r2   r3   r   r   r   rH   r   s          r   r   r     s5    8 <<""4(D
'
*C==$GGr*   c                   $    \ rS rSrSrSS1rSrSrg)RdatatypeExistsi  zDNS rdatatype already exists.r2   r3   zGThe rdata type with class {rdclass} and rdtype {rdtype} already exists.r   N)r   r   r   r   r   supp_kwargsfmtr   r   r*   r   r   r     s    'h'KCr*   r   Fc                     [        XA5      nU[        :w  a	  [        XAS9eU [        XA4'   [        R
                  R                  XU5        g)a  Dynamically register a module to handle an rdatatype.

*implementation*, a module implementing the type in the usual dnspython
way.

*rdtype*, an ``int``, the rdatatype to register.

*rdtype_text*, a ``text``, the textual form of the rdatatype.

*is_singleton*, a ``bool``, indicating if the type is a singleton (i.e.
RRsets of the type can have only one member.)

*rdclass*, the rdataclass of the type, or ``dns.rdataclass.ANY`` if
it applies to all classes.
r5   N)r   r   r   r   r:   r;   register_type)implementationr3   r   is_singletonr2   existing_clss         r   r   r     sB    $ #73L|#g==(6NG$%MM\Br*   r   ri   ),r   ior   r   r   dns.exceptionr:   dns.namedns.rdataclassdns.rdatatypedns.tokenizerdns.wiredata_compatr   r   r   	threading
_threadingr   dummy_threading_hex_chunksizer   _base64_chunksizer   r#   r$   r)   r.   objectr0   r   r   r   Lockr   r   r[   r   r   DNSExceptionr   rc   INr   r   r*   r   <module>r      s   $           4 4)"  + C    1 C f	&dF dL*D5 *DX   F/CdHBcmm00  EJ..++Ca  )()s   C	 	
CC