U
    h/                     @   s   d Z ddlmZmZmZm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ZG dd dejjZG dd dejjZeZejZejZejZejZdS )zDNS Dynamic Update Support    )AnyListOptionalUnionNc                   @   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
   0./venv/lib/python3.8/site-packages/dns/update.py_maximum(   s    zUpdateSection._maximumN)
__name__
__module____qualname____doc__ZONEPREREQUPDATE
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e
eejjef  ejje
e e
ejj eejjef e
e d fddZeeejj dddZejdd Zeeejj dd	d
Zejdd
 Zeeejj dddZejdd Zd#ddZdd Zeejjef eddddZeejjef eddddZeejjef eddddZeejjef eddddZ d$eejjef e
eej!j"ef  ddddZ#dd  Z$d!d" Z%  Z&S )%UpdateMessageN)zonerdclasskeyringkeynamekeyalgorithmidc                    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k	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.
        )r   T)ZcreateZforce_uniqueN)	algorithm)super__init__flagsdnsZopcodeZto_flagsr   
isinstancestrname	from_textorigin
rdataclass
RdataClassmakezone_rdclass
find_rrsetr   	rdatatypeSOAZuse_tsig)selfr   r   r   r   r   r   	__class__r
   r   r    1   s$    
zUpdateMessage.__init__)returnc                 C   s
   | j d S )zThe zone section.r   Zsectionsr/   r
   r
   r   r   \   s    zUpdateMessage.zonec                 C   s   || j d< d S )Nr   r3   r/   vr
   r
   r   r   a   s    c                 C   s
   | j d S )zThe prerequisite section.r   r3   r4   r
   r
   r   prerequisitee   s    zUpdateMessage.prerequisitec                 C   s   || j d< d S )Nr   r3   r5   r
   r
   r   r7   j   s    c                 C   s
   | j d S )zThe update section.r   r3   r4   r
   r
   r   updaten   s    zUpdateMessage.updatec                 C   s   || j d< d S )Nr   r3   r5   r
   r
   r   r8   s   s    c              
   C   sB   |dkr| j }| }| ||| j|j||dd}||| dS )z&Add a single RR to the update section.NT)r8   coversr,   r+   rdtypeadd)r/   r%   ttlrddeletingsectionr9   rrsetr
   r
   r   _add_rrw   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   )r?   )r#   r$   r"   r%   r&   rdatasetRdatasetdeleter:   rA   r<   listintpoprdataRdatar-   	RdataTyper*   r+   r'   )
r/   replacer?   r%   argsrdsr=   r<   r:   sr
   r
   r   _add   s*    
zUpdateMessage._add)r%   rL   r2   c                 G   s   | j d| j|f|  dS )zAdd records.

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

                - rdataset...

                - ttl, rdata...

                - ttl, rdtype, string...
        FNrO   r8   r/   r%   rL   r
   r
   r   r;      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,   r8   r(   ANYr-   NONErB   rC   rA   rE   rH   rI   rJ   r*   rG   r+   r'   )r/   r%   rL   rM   r=   largsr:   rN   r
   r
   r   rD      sR    

zUpdateMessage.deletec                 G   s   | j d| j|f|  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.
        TNrP   rQ   r
   r
   r   rK      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|f|  n| jd| j|f|  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&   rR   r,   r7   r(   rS   r-   rT   rB   rC   rH   rI   rE   insertrO   rJ   r*   )r/   r%   rL   rU   r:   r
   r
   r   present  sF    

zUpdateMessage.present)r%   r:   r2   c              
   C   s|   t |trtj|d}|dk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,   r7   r(   rT   r-   rS   rJ   r*   )r/   r%   r:   r
   r
   r   absent<  s0    
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k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	FormErrorrS   rT   r   r   )r/   r?   r%   r   r:   r>   emptyr
   r
   r   _parse_rr_headerb  s$    



zUpdateMessage._parse_rr_header)NN)N)'r   r   r   r   Z_section_enumr"   r(   INZtsigZdefault_algorithmr   r   r%   Namer$   r)   r   rF   r    propertyr   r@   ZRRsetr   setterr7   r8   rA   rO   r;   rD   rK   rW   r-   rJ   rX   rZ   r\   __classcell__r
   r
   r0   r   r   -   sR   
+



(<8 "r   )r   typingr   r   r   r   Zdns.messager"   Zdns.nameZ
dns.opcodeZ	dns.rdataZdns.rdataclassZdns.rdatasetZdns.rdatatypeZdns.tsigenumIntEnumr   messageZMessager   ZUpdater   r   r   r   r
   r
   r
   r   <module>   s$     N