a
    sd_)                     @   sz   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G dd dej	j
Ze ej G dd dejjZeZdS )zDNS Dynamic Update Support    Nc                   @   s,   e Zd ZdZdZdZdZdZedd Z	dS )	UpdateSectionzUpdate sectionsr            c                 C   s   dS )Nr    )clsr   r   ,/usr/lib/python3/dist-packages/dns/update.py_maximum%   s    zUpdateSection._maximumN)
__name__
__module____qualname____doc__ZONEPREREQUPDATEZ
ADDITIONALclassmethodr	   r   r   r   r   r      s   r   c                       s   e Zd ZeZdejjddejj	df fdd	Z
edd Zejdd Zedd Zejd	d Zed
d Zej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d Zdd Z  ZS )!UpdateMessageNc                    s   t  j|d |  jtjtjjO  _t|tr>tj	
|}|| _tjj|}|| _| jr|| j| j| j|tjjddd |dur| j|||d dS )ax  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``, ``str``, or ``None``, the zone
        which is being updated.  ``None`` should only be used by dnspython's
        message constructors, as a zone is required for the convenience
        methods like ``add()``, ``replace()``, etc.

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

        The *keyring*, *keyname*, and *keyalgorithm* parameters are passed to
        ``use_tsig()``; see its documentation for details.
        )idT)ZcreateZforce_uniqueN)	algorithm)super__init__flagsdnsZopcodeZto_flagsr   
isinstancestrname	from_textorigin
rdataclassZ
RdataClassmakezone_rdclass
find_rrsetzone	rdatatypeSOAZuse_tsig)selfr"   rdclassZkeyringZkeynameZkeyalgorithmr   	__class__r   r   r   0   s    
zUpdateMessage.__init__c                 C   s
   | j d S )zThe zone section.r   Zsectionsr%   r   r   r   r"   O   s    zUpdateMessage.zonec                 C   s   || j d< d S )Nr   r)   r%   vr   r   r   r"   T   s    c                 C   s
   | j d S )zThe prerequisite section.r   r)   r*   r   r   r   prerequisiteX   s    zUpdateMessage.prerequisitec                 C   s   || j d< d S )Nr   r)   r+   r   r   r   r-   ]   s    c                 C   s
   | j d S )zThe update section.r   r)   r*   r   r   r   updatea   s    zUpdateMessage.updatec                 C   s   || j d< d S )Nr   r)   r+   r   r   r   r.   f   s    c              
   C   sB   |du r| j }| }| ||| j|j||dd}||| dS )z&Add a single RR to the update section.NT)r.   coversr!   r    rdtypeadd)r%   r   ttlrddeletingsectionr/   Zrrsetr   r   r   _add_rrj   s    zUpdateMessage._add_rrc           
      G   s  t |trtj|d}t |d tjjrf|D ]4}|rD| ||j |D ]}| j	||j
||d qHq.nt|}t|d}t |d tjjr|r| ||d j |D ]}| j	||||d qnVtjj|d}|r| || |D ],}	tj| j||	| j}| j	||||d qdS )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   )r5   )r   r   r   r   r   rdatasetRdatasetdeleter0   r6   r2   listintpoprdataRdatar#   	RdataTyper   r    r   )
r%   replacer5   r   argsrdsr3   r2   r0   sr   r   r   _addt   s.    
zUpdateMessage._addc                 G   s   | j d| j|g|R   dS )zAdd records.

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

                - rdataset...

                - ttl, rdata...

                - ttl, rdtype, string...
        FNrD   r.   r%   r   rA   r   r   r   r1      s    zUpdateMessage.addc              
   G   sH  t |trtj|d}t|dkrP| | j|tjj	tj
j	tj
jtj
j	dd nt |d tjjr|D ]"}|D ]}| |d|tjj qnqfnt|}t |d tjjr|D ]}| |d|tjj qn~tj
j|d}t|dkr| | j|| j|tj
jtjj	dd n6|D ]0}tj| j||| j}| |d|tjj qdS )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#   NONEr7   r8   r6   r:   r=   r>   r?   r   r<   r    r   )r%   r   rA   rB   r3   r0   rC   r   r   r   r9      s8    


zUpdateMessage.deletec                 G   s   | j d| j|g|R   dS )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.
        TNrE   rF   r   r   r   r@      s    zUpdateMessage.replacec              
   G   s   t |trtj|d}t|dkrL| | j|tjj	tj
j	tj
jddd nt |d tjjs|t |d tjjs|t|dkrt |d tjjst|}|dd | jd| j|g|R   n4tj
j|d }| | j|tjj	|tj
jddd dS )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   rG   r!   r-   r   rH   r#   rI   r7   r8   r=   r>   r:   insertrD   r?   r   )r%   r   rA   r0   r   r   r   present   s.    



zUpdateMessage.presentc              
   C   s|   t |trtj|d}|du rH| | j|tjjtj	j
tj	jddd n0tj	j|}| | j|tjj|tj	jddd dS )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!   r-   r   rI   r#   rH   r?   r   )r%   r   r0   r   r   r   absent  s    


zUpdateMessage.absentc                 C   s   dS )NTr   )r%   valuer   r   r   _get_one_rr_per_rrset!  s    z#UpdateMessage._get_one_rr_per_rrsetc                 C   s   d }d}|t jkr:tj|s0|tjjks0| jrtjj	nH| jsHtjj	|tjj
tjjfv r|}| jd j}|tjj
kp|t jk}||||fS )NFr   )r   r   r   r   Zis_metaclassr#   r$   r"   Z	exceptionZ	FormErrorrH   rI   r&   r   )r%   r5   r   r&   r0   r4   emptyr   r   r   _parse_rr_header%  s$    


zUpdateMessage._parse_rr_header)NN)N)r
   r   r   r   Z_section_enumr   r   INZtsigZdefault_algorithmr   propertyr"   setterr-   r.   r6   rD   r1   r9   r@   rK   rL   rN   rP   __classcell__r   r   r'   r   r   ,   s4   








),%
r   )r   Zdns.messager   Zdns.nameZ
dns.opcodeZ	dns.rdataZdns.rdataclassZdns.rdatasetZdns.tsigenumIntEnumr   globalsr.   __members__messageZMessager   ZUpdater   r   r   r   <module>   s     