
    g(                         d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
  G d dej                  j                        Zy)zDNS Dynamic Update Support    N   )string_typesc                        e Zd Zej                  j
                  ddej                  j                  f fd	ZddZ	d Z
d Zd Zd Zd Zdd	Zd fd
	Z xZS )UpdateNc                 J   t         t        |           | xj                  t        j
                  j                  t        j
                  j                        z  c_        t        |t              rt        j                  j                  |      }|| _        t        |t              rt        j                  j                  |      }|| _        | j                  | j                   | j                  |t        j"                  j$                  dd       || j'                  |||       yy)a  Initialize a new DNS Update object.

        See the documentation of the Message class for a complete
        description of the keyring dictionary.

        *zone*, a ``dns.name.Name`` or ``text``, the zone which is being
        updated.

        *rdclass*, an ``int`` or ``text``, the class of the zone.

        *keyring*, a ``dict``, the TSIG keyring to use.  If a
        *keyring* is specified but a *keyname* is not, then the key
        used will be the first key in the *keyring*.  Note that the
        order of keys in a dictionary is not defined, so applications
        should supply a keyname when a keyring is used, unless they
        know the keyring contains only one key.

        *keyname*, a ``dns.name.Name`` or ``None``, the name of the TSIG key
        to use; defaults to ``None``. The key must be defined in the keyring.

        *keyalgorithm*, a ``dns.name.Name``, the TSIG algorithm to use.
        T)createforce_uniqueN)	algorithm)superr   __init__flagsdnsopcodeto_flagsUPDATE
isinstancer   name	from_textorigin
rdataclasszone_rdclass
find_rrsetquestion	rdatatypeSOAuse_tsig)selfzonerdclasskeyringkeynamekeyalgorithm	__class__s         lib/third_party/dns/update.pyr   zUpdate.__init__!   s    0 	fd$&

cjj))#***;*;<<
dL)88%%d+Dg|,nn..w7G#t{{GS]]=N=N#$ 	 	8MM'7lMC     c           
          || j                   }|j                         }| j                  ||| j                  |j                  ||dd      }|j                  ||       y)z&Add a single RR to the update section.NT)	authoritycoversr   r   rdtypeadd)r   r   ttlrddeletingsectionr(   rrsets           r$   _add_rrzUpdate._add_rrF   sT     ?nnGt/@/@")) &$>		"cr%   c                    t        |t              r t        j                  j	                  |d      }t        |d   t        j
                  j                        rL|D ]F  }|r| j                  ||j                         |D ]!  }| j                  ||j                  ||       # H yt        |      }t        |j                  d            }t        |d   t        j                  j                        r>|r| j                  ||d   j                         |D ]  }| j                  ||||        y|j                  d      }t        |t              rt        j                   j	                  |      }|r| j                  ||       |D ]M  }	t        j                  j	                  | j"                  ||	| j$                        }| j                  ||||       O y)a  Add records.

        *replace* is the replacement mode.  If ``False``,
        RRs are added to an existing RRset; if ``True``, the RRset
        is replaced with the specified contents.  The second
        argument is the section to add to.  The third argument
        is always a name.  The other arguments can be:

                - rdataset...

                - ttl, rdata...

                - ttl, rdtype, string...
        Nr   )r.   )r   r   r   r   r   rdatasetRdatasetdeleter)   r0   r+   listintpoprdataRdatar   r   r   )
r   replacer.   r   argsrdsr,   r+   r)   ss
             r$   _addzUpdate._addP   sj     dL)88%%dD1Dd1gs||445KKcjj1BLLswwGLD   :Ddhhqk"C$q'399??3KKd1gnn5BLLsBL@  !fl3 ]]44V<FKKf-A,,T->->-1[[:BLLsBL@ r%   c                 B     | j                   d| j                  |g|  y)zAdd records.

        The first argument is always a name.  The other
        arguments can be:

                - rdataset...

                - ttl, rdata...

                - ttl, rdtype, string...
        FNr>   r'   r   r   r;   s      r$   r*   z
Update.add{   s     			%55r%   c           
      >   t        |t              r t        j                  j	                  |d      }t        |      dk(  r| j                  | j                  |t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  dd       yt        |d   t        j                  j                        r;|D ]5  }|D ].  }| j                  |d|t        j                  j                         0 7 yt        |      }t        |d   t        j                   j"                        r4|D ].  }| j                  |d|t        j                  j                         0 y|j%                  d      }t        |t              rt        j                  j	                  |      }t        |      dk(  r]| j                  | j                  || j&                  |t        j                  j                  t        j                  j                  dd       y|D ]d  }t        j                   j	                  | j&                  ||| j(                        }| j                  |d|t        j                  j                         f y)zDelete records.

        The first argument is always a name.  The other
        arguments can be:

                - *empty*

                - rdataset...

                - rdata...

                - rdtype, [string...]
        Nr   T)r   r   r   r   r   lenr   r'   r   ANYr   NONEr2   r3   r0   r5   r8   r9   r7   r   r   )r   r   r;   r<   r,   r)   r=   s          r$   r4   zUpdate.delete   s    dL)88%%dD1Dt9>OODNND#..2D2DMM--s}}/A/AMM--tT; Q!6!67BLLq"cnn.A.AB   :D$q'399??3BLLq"cnn.A.AB  !fl3 ]]44V<Ft9>OODNND$($5$5v$'MM$6$6$'NN$6$6$($	0 " YY001B1BFA15>T1b#..2E2EF "r%   c                 B     | j                   d| j                  |g|  y)ab  Replace records.

        The first argument is always a name.  The other
        arguments can be:

                - rdataset...

                - ttl, rdata...

                - ttl, rdtype, string...

        Note that if you want to replace the entire node, you should do
        a delete of the name followed by one or more calls to add.
        TNr@   rA   s      r$   r:   zUpdate.replace   s      			$4t4r%   c           
         t        |t              r t        j                  j	                  |d      }t        |      dk(  rk| j                  | j                  |t        j                  j                  t        j                  j                  t        j                  j                  ddd       yt        |d   t        j                  j                        s5t        |d   t        j                  j                        st        |      dkD  rdt        |d   t        j                  j                        st!        |      }|j#                  dd        | j$                  d| j                  |g|  y|d   }t        |t              rt        j                  j	                  |      }| j                  | j                  |t        j                  j                  |t        j                  j                  ddd       y)aS  Require that an owner name (and optionally an rdata type,
        or specific rdataset) exists as a prerequisite to the
        execution of the update.

        The first argument is always a name.
        The other arguments can be:

                - rdataset...

                - rdata...

                - rdtype, string...
        Nr   Tr   F)r   r   r   r   r   rC   r   answerr   rD   r   rE   r2   r3   r8   r9   r5   insertr>   )r   r   r;   r)   s       r$   presentzUpdate.present   sS    dL)88%%dD1Dt9>OODKKNN..0A0AMM.. $( Q!6!67tAw		0D	Ad1gs||'<'<=DzAq!DIIeT[[$66!WF&,/008OODKKNN..MM.. $(r%   c           
      @   t        |t              r t        j                  j	                  |d      }|k| j                  | j                  |t        j                  j                  t        j                  j                  t        j                  j                  ddd       yt        |t              rt        j                  j	                  |      }| j                  | j                  |t        j                  j                  |t        j                  j                  ddd       y)zRequire that an owner name (and optionally an rdata type) does
        not exist as a prerequisite to the execution of the update.NT)r   r   r   r   r   r   rH   r   rE   r   rD   )r   r   r)   s      r$   absentzUpdate.absent   s     dL)88%%dD1D>OODKKNN//1B1BMM.. $(
 &,/008OODKKNN//MM.. $(r%   c                 H    || j                   }t        t        |   ||      S )aL  Return a string containing the update in DNS compressed wire
        format.

        *origin*, a ``dns.name.Name`` or ``None``, the origin to be
        appended to any relative names.  If *origin* is ``None``, then
        the origin of the ``dns.update.Update`` message object is used
        (i.e. the *zone* parameter passed when the Update object was
        created).

        *max_size*, an ``int``, the maximum size of the wire format
        output; default is 0, which means "the message's request
        payload, if nonzero, or 65535".

        Returns a ``binary``.
        )r   r   r   to_wire)r   r   max_sizer#   s      r$   rN   zUpdate.to_wire  s'    " >[[FVT*68<<r%   )NN)N)Ni  )__name__
__module____qualname__r   r   INtsigdefault_algorithmr   r0   r>   r*   r4   r:   rJ   rL   rN   __classcell__)r#   s   @r$   r   r      sZ    %(^^%6%6CHH,F,F#DJ)AV6,G\5$%(N(&= =r%   r   )__doc__dns.messager   dns.name
dns.opcode	dns.rdatadns.rdataclassdns.rdatasetdns.tsig_compatr   messageMessager    r%   r$   <module>rc      s<   $ !        !x=S[[   x=r%   