U
    <{f/                     @   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
   I/var/www/html/Darija-Ai-API/env/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)createZforce_uniqueN)	algorithm)super__init__flagsdns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   sectionsr1   r
   r
   r   r   \   s    zUpdateMessage.zonec                 C   s   || j d< d S )Nr   r5   r1   vr
   r
   r   r   a   s    c                 C   s
   | j d S )zThe prerequisite section.r   r5   r7   r
   r
   r   prerequisitee   s    zUpdateMessage.prerequisitec                 C   s   || j d< d S )Nr   r5   r8   r
   r
   r   r:   j   s    c                 C   s
   | j d S )zThe update section.r   r5   r7   r
   r
   r   updaten   s    zUpdateMessage.updatec                 C   s   || j d< d S )Nr   r5   r8   r
   r
   r   r;   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)r;   coversr.   r-   rdtypeadd)r1   r'   ttlrddeletingsectionr<   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   )rB   )r%   r&   r#   r'   r(   rdatasetRdatasetdeleter=   rD   r?   listintpoprdataRdatar/   	RdataTyper,   r-   r)   )
r1   replacerB   r'   argsrdsr@   r?   r=   sr
   r
   r   _add   s*    
zUpdateMessage._add)r'   rO   r4   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rR   r;   r1   r'   rO   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.   r;   r*   ANYr/   NONErE   rF   rD   rH   rK   rL   rM   r,   rJ   r-   r)   )r1   r'   rO   rP   r@   largsr=   rQ   r
   r
   r   rG      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.
        TNrS   rT   r
   r
   r   rN      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(   rU   r.   r:   r*   rV   r/   rW   rE   rF   rK   rL   rH   insertrR   rM   r,   )r1   r'   rO   rX   r=   r
   r
   r   present  sF    

zUpdateMessage.present)r'   r=   r4   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.   r:   r*   rW   r/   rV   rM   r,   )r1   r'   r=   r
   r
   r   absent<  s0    
zUpdateMessage.absentc                 C   s   dS )NTr
   )r1   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/   r0   r   	exceptionZ	FormErrorrV   rW   r   r   )r1   rB   r'   r   r=   rA   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   rI   r!   propertyr   rC   ZRRsetr   setterr:   r;   rD   rR   r>   rG   rN   rZ   r/   rM   r[   r]   r`   __classcell__r
   r
   r2   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   messageMessager   ZUpdater   r   r   r   r
   r
   r
   r   <module>   s$     N