509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
¢báW'  ã               @   s`   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„ dejjƒZdS )zDNS Dynamic Update Supporté    Né   )Ústring_typesc                   sx   e Zd Zejjddejjf‡ fdd„	Zddd„Z	dd„ Z
dd	„ Zd
d„ Zdd„ Zdd„ Zddd„Zd‡ fdd„	Z‡  ZS )ÚUpdateNc                sš   t t| ƒjƒ  |  jtjjtjjƒO  _t|t	ƒr>tj
j|ƒ}|| _t|t	ƒrZtjj|ƒ}|| _| j| j| j|tjjddd� |dk	r–| j|||d� dS )aä  Initialize a new DNS Update object.

        @param zone: The zone which is being updated.
        @type zone: A dns.name.Name or string
        @param rdclass: The class of the zone; defaults to dns.rdataclass.IN.
        @type rdclass: An int designating the class, or a string whose value
        is the name of a class.
        @param keyring: The TSIG keyring to use; defaults to None.
        @type keyring: dict
        @param keyname: The name of the TSIG key to use; defaults to None.
        The key must be defined in the keyring.  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.
        @type keyname: dns.name.Name or string
        @param keyalgorithm: The TSIG algorithm to use; defaults to
        dns.tsig.default_algorithm.  Constants for TSIG algorithms are defined
        in dns.tsig, and the currently implemented algorithms are
        HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, and
        HMAC_SHA512.
        @type keyalgorithm: string
        T)ZcreateZforce_uniqueN)Ú	algorithm)Úsuperr   Ú__init__ÚflagsÚdnsZopcodeZto_flagsZUPDATEÚ
isinstancer   ÚnameÚ	from_textÚoriginÚ
rdataclassÚzone_rdclassÚ
find_rrsetZquestionÚ	rdatatypeZSOAZuse_tsig)ÚselfZzoneZrdclassZkeyringZkeynameZkeyalgorithm)Ú	__class__© ú/usr/lib/python3.6/update.pyr      s    


zUpdate.__init__c          	   C   sB   |dkr| j }|jƒ }| j||| j|j||ddƒ}|j||ƒ dS )z&Add a single RR to the update section.NT)Ú	authorityÚcoversr   r   ÚrdtypeÚadd)r   r   ÚttlÚrdZdeletingÚsectionr   Zrrsetr   r   r   Ú_add_rrE   s    zUpdate._add_rrc       
      G   s:  t |tƒrtjj|dƒ}t |d tjjƒrnx@|D ]8}|rF| j||jƒ x |D ]}| j	||j
||d� qLW q0W nÈt|ƒ}t|jdƒƒ}t |d tjjƒrÎ|r¬| j||d jƒ xˆ|D ]}| j	||||d� q²W nh|jdƒ}t |tƒrîtjj|ƒ}|rþ| j||ƒ x6|D ].}	tjj| j||	| jƒ}| j	||||d� �qW dS )aœ  Add records.  The first argument is the replace 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   r   r   ÚlistÚintÚpopÚrdataÚRdatar   r   r   )
r   Úreplacer   r   ÚargsÚrdsr   r   r   Úsr   r   r   Ú_addO   s0    






zUpdate._addc             G   s   | j d| j|f|žŽ  dS )zÁAdd 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'   r   r   r   r   w   s    	z
Update.addc          	   G   sf  t |tƒrtjj|dƒ}t|ƒdkrR| j| j|tjj	tj
j	tj
jtj
j	ddƒ �nt |d tjjƒr–xü|D ]&}x |D ]}| j|d|tjjƒ qtW qjW nÌt|ƒ}t |d tjjƒrÔx°|D ]}| j|d|tjjƒ q¶W nŽ|jdƒ}t |tƒrôtj
j|ƒ}t|ƒdk�r(| j| j|| j|tj
jtjj	ddƒ n:x8|D ]0}tjj| j||| jƒ}| j|d|tjjƒ �q.W dS )zÚDelete records.  The first argument is always a name.  The other
        arguments can be:

                - I{nothing}

                - rdataset...

                - rdata...

                - rdtype, [string...]Nr   T)r
   r   r	   r   r   Úlenr   r   r   ÚANYr   ÚNONEr   r   r   r!   r$   r%   r#   r   r   )r   r   r'   r(   r   r   r)   r   r   r   r    ‚   s6    








zUpdate.deletec             G   s   | j d| j|f|žŽ  dS )aQ  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.TN)r*   r   )r   r   r'   r   r   r   r&   ­   s    zUpdate.replacec          	   G   sþ   t |tƒrtjj|dƒ}t|ƒdkrL| j| j|tjj	tj
j	tj
jdddƒ n®t |d tjjƒs|t |d tjjƒs|t|ƒdkrºt |d tjjƒs¢t|ƒ}|jddƒ | jd| j|f|žŽ  n@|d }t |tƒrØtj
j|ƒ}| j| j|tjj	|tj
jdddƒ dS )aB  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   r+   r   Úanswerr   r,   r   r-   r   r   r$   r%   r!   Úinsertr*   )r   r   r'   r   r   r   r   Úpresent¼   s*    




zUpdate.presentc          	   C   s„   t |tƒrtjj|dƒ}|dkrH| j| j|tjjtj	j
tj	jdddƒ n8t |tƒr^tj	j|ƒ}| j| j|tjj|tj	jdddƒ dS )z‚Require 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   r.   r   r-   r   r,   )r   r   r   r   r   r   Úabsentà   s    




zUpdate.absentéÿÿ  c                s    |dkr| j }tt| ƒj||ƒS )zcReturn a string containing the update in DNS compressed wire
        format.
        @rtype: stringN)r   r   r   Úto_wire)r   r   Zmax_size)r   r   r   r3   ó   s    zUpdate.to_wire)NN)N)Nr2   )Ú__name__Ú
__module__Ú__qualname__r	   r   ÚINZtsigZdefault_algorithmr   r   r*   r   r    r&   r0   r1   r3   Ú__classcell__r   r   )r   r   r      s   %

(+$
r   )Ú__doc__Zdns.messager	   Zdns.nameZ
dns.opcodeZ	dns.rdataZdns.rdataclassZdns.rdatasetZdns.tsigZ_compatr   ÚmessageZMessager   r   r   r   r   Ú<module>   s   