
    ,                     V   S r SSK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Jr  \R                  R                  r " S S\R                   R"                  5      r " S S	\R                   R"                  5      r " S
 S\R                  R                  5      rS rS rS rS rg)zHDNS rdatasets (an rdataset is a set of rdatas of a given type and class)    N)StringIO   )string_typesc                       \ rS rSrSrSrg)DifferingCovers#   zzAn attempt was made to add a DNS SIG/RRSIG whose covered type
is not the same as that of the other rdatas in the rdataset. N__name__
__module____qualname____firstlineno____doc____static_attributes__r	       lib/third_party/dns/rdataset.pyr   r   #   s    Dr   r   c                       \ rS rSrSrSrg)IncompatibleTypes(   z?An attempt was made to add DNS RR data of an incompatible type.r	   Nr
   r	   r   r   r   r   (   s    Ir   r   c                      ^  \ rS rSrSr/ SQr\R                  R                  S4U 4S jjr	U 4S jr
S rSU 4S jjrU 4S	 jrU 4S
 jrU 4S jrS rS rU 4S jrS r  SS jr  SS jrS rSrU =r$ )Rdataset,   zA DNS rdataset.)rdclassrdtypecoversttlr   c                 Z   > [         [        U ]  5         Xl        X l        X0l        X@l        g)zCreate a new rdataset of the specified class and type.

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

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

*covers*, an ``int``, the covered rdatatype.

*ttl*, an ``int``, the TTL.
N)superr   __init__r   r   r   r   )selfr   r   r   r   	__class__s        r   r   Rdataset.__init__2   s&     	h&(r   c                    > [         [        U ]  5       nU R                  Ul        U R                  Ul        U R
                  Ul        U R                  Ul        U$ N)r   r   _cloner   r   r   r   )r    objr!   s     r   r%   Rdataset._cloneD   sC    Hd*,ll[[
[[
((
r   c                 \    [        U 5      S:X  a  Xl        gXR                  :  a  Xl        gg)zPerform TTL minimization.

Set the TTL of the rdataset to be the lesser of the set's current
TTL or the specified TTL.  If the set contains no rdatas, set the TTL
to the specified TTL.

*ttl*, an ``int``.
r   N)lenr   )r    r   s     r   
update_ttlRdataset.update_ttlL   s'     t9>H88^H r   c                   > U R                   UR                   :w  d  U R                  UR                  :w  a  [        eUb  U R                  U5        U R                  [        R
                  R                  :X  d(  U R                  [        R
                  R                  :X  ad  UR                  5       n[        U 5      S:X  a/  U R                  [        R
                  R                  :X  a  X0l        OU R                  U:w  a  [        e[        R
                  R                  UR                  5      (       a  [        U 5      S:  a  U R                  5         [        [        U ]C  U5        g)a  Add the specified rdata to the rdataset.

If the optional *ttl* parameter is supplied, then
``self.update_ttl(ttl)`` will be called prior to adding the rdata.

*rd*, a ``dns.rdata.Rdata``, the rdata

*ttl*, an ``int``, the TTL.

Raises ``dns.rdataset.IncompatibleTypes`` if the type and class
do not match the type and class of the rdataset.

Raises ``dns.rdataset.DifferingCovers`` if the type is a signature
type and the covered type does not match that of the rdataset.
Nr   )r   r   r   r*   dns	rdatatypeRRSIGSIGr   r)   NONEr   is_singletonclearr   r   add)r    rdr   r   r!   s       r   r4   Rdataset.add[   s    . <<2::%		)A##?OOC ;;#-----;;#--+++YY[F4yA~$++1C1C"C$&%%==%%bii00SY]JJLh!"%r   c                 b   > U R                  UR                  5        [        [        U ]  U5        g r$   )r*   r   r   r   union_updater    otherr!   s     r   r8   Rdataset.union_update   s"    		"h*51r   c                 b   > U R                  UR                  5        [        [        U ]  U5        g r$   )r*   r   r   r   intersection_updater9   s     r   r=   Rdataset.intersection_update   s"    		"h1%8r   c                 b   > U R                  UR                  5        [        [        U ]  U5        g)zkAdd all rdatas in other to self.

*other*, a ``dns.rdataset.Rdataset``, the rdataset from which
to update.
N)r*   r   r   r   updater9   s     r   r@   Rdataset.update   s$     			"h$U+r   c                 D   U R                   S:X  a  SnO/S[        R                  R                  U R                   5      -   S-   nS[        R                  R                  U R
                  5      -   S-   [        R                  R                  U R                  5      -   U-   S-   $ )Nr    ()z<DNS  z
 rdataset>)r   r-   r.   to_text
rdataclassr   r   )r    ctexts     r   __repr__Rdataset.__repr__   s    ;;!E#--//<<sBE//==C}}$$T[[1249:<HI 	Ir   c                 "    U R                  5       $ r$   )rG   )r    s    r   __str__Rdataset.__str__   s    ||~r   c                    > [        U[        5      (       d  gU R                  UR                  :w  d4  U R                  UR                  :w  d  U R                  UR                  :w  a  g[
        [        U ]  U5      $ )NF)
isinstancer   r   r   r   r   __eq__r9   s     r   rQ   Rdataset.__eq__   sX    %**<<5==(;;%,,&;;%,,&Xt+E22r   c                 .    U R                  U5      (       + $ r$   )rQ   )r    r:   s     r   __ne__Rdataset.__ne__   s    ;;u%%%r   c                    Ub  UR                  X#5      n[        U5      nSnOSnSn[        5       nUb  Un	OU R                  n	[	        U 5      S:X  ag  UR                  SR                  Xg[        R                  R                  U	5      [        R                  R                  U R                  5      5      5        OU  H|  n
UR                  SXgU R                  [        R                  R                  U	5      [        R                  R                  U R                  5      U
R                  " S	X#S.UD64-  5        M~     UR                  5       SS $ )
a  Convert the rdataset into DNS master file format.

See ``dns.name.Name.choose_relativity`` for more information
on how *origin* and *relativize* determine the way names
are emitted.

Any additional keyword arguments are passed on to the rdata
``to_text()`` method.

*name*, a ``dns.name.Name``.  If name is not ``None``, emit RRs with
*name* as the owner name.

*origin*, a ``dns.name.Name`` or ``None``, the origin for relative
names.

*relativize*, a ``bool``.  If ``True``, names will be relativized
to *origin*.
NrF   rC   r   z
{}{}{} {}
z%s%s%d %s %s %s
)origin
relativizer	   )choose_relativitystrr   r   r)   writeformatr-   rH   rG   r.   r   r   getvalue)r    namerW   rX   override_rdclasskwntextpadsr   r5   s              r   rG   Rdataset.to_text   s$   * ))&=DIECECJ'&GllGt9> GGN))%*-..*@*@*I*---*?*?*LN O ,TXXs~~/E/Eg/N..t{{; 6    !  zz|CR  r   c                 4   Ub  UnSnOU R                   nUR                  SS5        [        U 5      S:X  aH  UR                  X#U5        [        R
                  " SU R                  USS5      nUR                  U5        gU(       a"  [        U 5      n	[        R                  " U	5        OU n	U	 H  n
UR                  X#U5        [        R
                  " SU R                  UU R                  S5      nUR                  U5        UR                  5       nU
R                  X#U5        UR                  5       nX-
  S:  d   eUR                  US-
  5        [        R
                  " SX-
  5      nUR                  U5        UR                  SS5        M     [        U 5      $ )a  Convert the rdataset to wire format.

*name*, a ``dns.name.Name`` is the owner name to use.

*file* is the file where the name is emitted (typically a
BytesIO file).

*compress*, a ``dict``, is the compression table to use.  If
``None`` (the default), names will not be compressed.

*origin* is a ``dns.name.Name`` or ``None``.  If the name is
relative and origin is not ``None``, then *origin* will be appended
to it.

*override_rdclass*, an ``int``, is used as the class instead of the
class of the rdataset.  This is useful when rendering rdatasets
associated with dynamic updates.

*want_shuffle*, a ``bool``.  If ``True``, then the order of the
Rdatas within the Rdataset will be shuffled before rendering.

Returns an ``int``, the number of records emitted.
Fr      z!HHIHr   i   z!H)r   seekr)   to_wirestructpackr   r\   listrandomshuffler   tell)r    r_   filecompressrW   r`   want_shuffler   stufflr5   startends                r   ri   Rdataset.to_wire   sI   4 '&G LllG		!Qt9>LL0KKgq!DEJJuJq!TV4GT[['$(HHa1

5!		

462iik{U***		%!)$D#+6

5!		!Q  t9r   c                 f    U R                   U:X  a!  U R                  U:X  a  U R                  U:X  a  gg)zQReturns ``True`` if this rdataset matches the specified class,
type, and covers.
TF)r   r   r   )r    r   r   r   s       r   matchRdataset.match  s.     <<7";;& ;;& r   )r   r   r   r   r$   )NNTN)NNNT)r   r   r   r   r   	__slots__r-   r.   r1   r   r%   r*   r4   r8   r=   r@   rJ   rM   rQ   rT   rG   ri   ry   r   __classcell__)r!   s   @r   r   r   ,   sy    6I/2}}/A/Aq $$&L29,I3& :>!%4!l 9=488t r   r   c                    [        U [        5      (       a  [        R                  R	                  U 5      n [        U[        5      (       a  [        R
                  R	                  U5      n[        X5      nUR                  U5        U HI  n[        R                  R	                  UR                  UR                  U5      nUR                  U5        MK     U$ )zCreate an rdataset with the specified class, type, and TTL, and with
the specified list of rdatas in text format.

Returns a ``dns.rdataset.Rdataset`` object.
)rP   r   r-   rH   	from_textr.   r   r*   rdatar   r   r4   )r   r   r   text_rdatasrtr5   s          r   from_text_listr   %  s     '<((..**73&,''((0!ALLYY  AHHa8	b	  Hr   c                     [        XX#5      $ )zCreate an rdataset with the specified class, type, and TTL, and with
the specified rdatas in text format.

Returns a ``dns.rdataset.Rdataset`` object.
)r   )r   r   r   r   s       r   r~   r~   8  s     '3<<r   c                     [        U5      S:X  a  [        S5      eSnU HH  nUc1  [        UR                  UR                  5      nUR                  U 5        UR                  U5        MJ     U$ )zCreate an rdataset with the specified TTL, and with
the specified list of rdata objects.

Returns a ``dns.rdataset.Rdataset`` object.
r   zrdata list must not be emptyN)r)   
ValueErrorr   r   r   r*   r4   )r   rdatasr   r5   s       r   from_rdata_listr   B  sb     6{a788A9RYY/ALL	b		 
 Hr   c                     [        X5      $ )z~Create an rdataset with the specified TTL, and with
the specified rdata objects.

Returns a ``dns.rdataset.Rdataset`` object.
)r   )r   r   s     r   
from_rdatar   T  s     3''r   )r   rm   ior   rj   dns.exceptionr-   dns.rdatatypedns.rdataclass	dns.rdatadns.set_compatr   setSet	SimpleSet	exceptionDNSExceptionr   r   r   r   r~   r   r   r	   r   r   <module>r      s   $ O         ! GGKK	Dcmm00 D
J22 Jvsww{{ vr&=$(r   