o
    2cC                     @   s   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d dl	ZG dd dZ
G dd dejjZG dd dejjZG dd	 d	ejjZG d
d dZdS )    Nc                   @   s6   e Zd Zdd ZdddZdd Zdd	 Zd
d ZdS )TransactionManagerc                 C      t )zBegin a read-only transaction.NotImplementedErrorself r   E/var/www/html/gps/gps/lib/python3.10/site-packages/dns/transaction.pyreader      zTransactionManager.readerFc                 C   r   )a  Begin a writable transaction.

        *replacement*, a ``bool``.  If `True`, the content of the
        transaction completely replaces any prior content.  If False,
        the default, then the content of the transaction updates the
        existing content.
        r   )r   replacementr   r   r	   writer   s   zTransactionManager.writerc                 C   r   )aq  Returns a tuple

            (absolute_origin, relativize, effective_origin)

        giving the absolute name of the default origin for any
        relative domain names, the "effective origin", and whether
        names should be relativized.  The "effective origin" is the
        absolute origin if relativize is False, and the empty name if
        relativize is true.  (The effective origin is provided even
        though it can be computed from the absolute_origin and
        relativize setting because it avoids a lot of code
        duplication.)

        If the returned names are `None`, then no origin information is
        available.

        This information is used by code working with transactions to
        allow it to coordinate relativization.  The transaction code
        itself takes what it gets (i.e. does not change name
        relativity).

        r   r   r   r   r	   origin_information   s   z%TransactionManager.origin_informationc                 C   r   )z.The class of the transaction manager.
        r   r   r   r   r	   	get_class7   s   zTransactionManager.get_classc                 C   s   |   \}}}|r|S dS )z,Origin to use in from_wire() calls.
        N)r   )r   absolute_origin
relativize_r   r   r	   from_wire_origin<   s   z#TransactionManager.from_wire_originN)F)__name__
__module____qualname__r
   r   r   r   r   r   r   r   r	   r      s    

r   c                   @      e Zd ZdZdS )DeleteNotExactz>Existing data did not match data specified by an exact delete.Nr   r   r   __doc__r   r   r   r	   r   F       r   c                   @   r   )ReadOnlyz*Tried to write to a read-only transaction.Nr   r   r   r   r	   r   J   r   r   c                   @   r   )AlreadyEndedz*Tried to use an already-ended transaction.Nr   r   r   r   r	   r   N   r   r   c                   @   s  e Zd ZdAddZejjfddZdd Zdd	 Z	d
d Z
dd Zdd Zdd ZddejjfddZdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"d:d; Z#d<d= Z$d>d? Z%d@S )BTransactionFc                 C   s   || _ || _|| _d| _d S NF)managerr   	read_only_ended)r   r    r   r!   r   r   r	   __init__T   s   
zTransaction.__init__c                 C   sb   |    t|trtj|d}tjj|}| 	|||}|dur/t|tj
js/tj
|}|S )zReturn the rdataset associated with *name*, *rdtype*, and *covers*,
        or `None` if not found.

        Note that the returned rdataset is immutable.
        N)_check_ended
isinstancestrdnsname	from_text	rdatatype	RdataTypemake_get_rdatasetrdatasetImmutableRdataset)r   r(   rdtypecoversr.   r   r   r	   get^   s   
zTransaction.getc                 C      | j rtd S N)r!   r   r   r   r   r	   _check_read_onlyn      zTransaction._check_read_onlyc                 G      |    |   | d|S )zAdd records.

        The arguments may be:

            - rrset

            - name, rdataset...

            - name, ttl, rdata...
        Fr$   r5   _addr   argsr   r   r	   addr   s   zTransaction.addc                 G   r7   )a  Replace the existing rdataset at the name with the specified
        rdataset, or add the specified rdataset if there was no existing
        rdataset.

        The arguments may be:

            - rrset

            - name, rdataset...

            - name, ttl, rdata...

        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() or
        replace().
        Tr8   r:   r   r   r	   replace   s   zTransaction.replacec                 G   r7   )a,  Delete records.

        It is not an error if some of the records are not in the existing
        set.

        The arguments may be:

            - rrset

            - name

            - name, rdataclass, rdatatype, [covers]

            - name, rdataset...

            - name, rdata...
        Fr$   r5   _deleter:   r   r   r	   delete   s   zTransaction.deletec                 G   r7   )a@  Delete records.

        The arguments may be:

            - rrset

            - name

            - name, rdataclass, rdatatype, [covers]

            - name, rdataset...

            - name, rdata...

        Raises dns.transaction.DeleteNotExact if some of the records
        are not in the existing set.

        Tr>   r:   r   r   r	   delete_exact   s   zTransaction.delete_exactc                 C   s*   |    t|trtj|d}| |S )zDoes the specified name exist?N)r$   r%   r&   r'   r(   r)   _name_existsr   r(   r   r   r	   name_exists   s   

zTransaction.name_exists   Tc                 C   s   |    |dk rtdt|trtj|d}| |tjj	tjj
}|du s-t|dkr/t|r=tj|d j| }ntj|}|j}|dkrLd}|d j|d}tj|j|}| || dS )a  Update the serial number.

        *value*, an `int`, is an increment if *relative* is `True`, or the
        actual value to set if *relative* is `False`.

        Raises `KeyError` if there is no SOA rdataset at *name*.

        Raises `ValueError` if *value* is negative or if the increment is
        so large that it would cause the new serial to be less than the
        prior value.
        r   znegative update_serial() valueNrE   )serial)r$   
ValueErrorr%   r&   r'   r(   r)   r-   r*   SOANONElenKeyErrorrF   Serialvaluer=   r.   
from_rdatattl)r   rM   relativer(   r.   rF   rdatanew_rdatasetr   r   r	   update_serial   s&   
zTransaction.update_serialc                 C      |    |  S r4   )r$   _iterate_rdatasetsr   r   r   r	   __iter__   s   zTransaction.__iter__c                 C   rT   )a   Has this transaction changed anything?

        For read-only transactions, the result is always `False`.

        For writable transactions, the result is `True` if at some time
        during the life of the transaction, the content was changed.
        )r$   _changedr   r   r   r	   changed   s   zTransaction.changedc                 C      |  d dS )a  Commit the transaction.

        Normally transactions are used as context managers and commit
        or rollback automatically, but it may be done explicitly if needed.
        A ``dns.transaction.Ended`` exception will be raised if you try
        to use a transaction after it has been committed or rolled back.

        Raises an exception if the commit fails (in which case the transaction
        is also rolled back.
        TN_endr   r   r   r	   commit   s   zTransaction.commitc                 C   rY   )av  Rollback the transaction.

        Normally transactions are used as context managers and commit
        or rollback automatically, but it may be done explicitly if needed.
        A ``dns.transaction.AlreadyEnded`` exception will be raised if you try
        to use a transaction after it has been committed or rolled back.

        Rollback cannot otherwise fail.
        FNrZ   r   r   r   r	   rollback  s   
zTransaction.rollbackc                 C   s   t |dkrtd| d S )Nr   zextra parameters to )rJ   	TypeError)r   methodr;   r   r   r	   _raise_if_not_empty  s   zTransaction._raise_if_not_emptyc                 C   s   z[|  }t|tjjr| }|W S t|tjjr|}|W S |r$d}n t|tr9|}|tj	j
kr8t| dnt| d|  }t|tjjrUtj||}|W S t| d tyn   |rgY d S t| dw )Nr   z: TTL value too bigz: expected a TTLz: expected an Rdataz: expected more arguments)popleftr%   r'   rrsetRRsetto_rdatasetr.   RdatasetintrO   MAX_TTLrG   r^   rQ   RdatarN   
IndexError)r   r_   deletingr;   argr.   rO   r   r   r	   _rdataset_from_args  s4   
zTransaction._rdataset_from_argsc                 C   sv  zt |}|rd}nd}| }t|trtj|d }t|tjjr.|}| 	|d|}nt|tj
jr?|}|j}| }n	t| dd |j| j krWt| d|jtjjkrq| j \}}}	||	krqt| d| || |s| ||j|j}
|
d urt|
tjjrtj|
j|
j|
j}||
 |}
|
|}| || W d S  ty   td| w )	Nz	replace()zadd()F requires a name or RRset as the first argument  has objects of wrong RdataClassz has non-origin SOAnot enough parameters to ) collectionsdequera   r%   r&   r'   r(   r)   Namerl   rb   rc   rd   r^   rdclassr    r   rG   r0   r*   rH   r   r`   r-   r1   r.   r/   re   updateunion_put_rdatasetri   )r   r=   r;   r_   rk   r(   r.   rb   r   originexistingtrdsr   r   r	   r9   8  sT   







zTransaction._addc                 C   sL  zt |}|rd}nd}| }t|trtj|d }t|tjjr|}t	|dkrt|d t
s;t|d trtjj| }t	|dkrTtjj| }ntjj}| || | |||}|d u ru|rrt| dW d S | ||| W d S | |d|}	nt|tjjr|}	|	j}n	t| dd | || |	r|	j| j krt| d| ||	j|	j}|d ur|r||	}
|
|	krt| d	||	}	t	|	dkr| ||	j|	j W d S | ||	 W d S |rt| dW d S |r|  |st| d
| !| W d S  t"y%   td| w )Nzdelete_exact()zdelete()r   z: missing rdatasetTrm   rn   ro   z: missing rdatasz: name not knownrp   )#rq   rr   ra   r%   r&   r'   r(   r)   rs   rJ   rf   r*   r+   r,   rI   r`   r-   r   _delete_rdatasetrl   rb   rc   r^   rt   r    r   rG   r0   r1   intersection
differencerw   rB   _delete_nameri   )r   exactr;   r_   rk   r(   r0   r1   ry   r.   r|   r   r   r	   r?   d  sv   







zTransaction._deletec                 C   r3   r4   )r"   r   r   r   r   r	   r$     r6   zTransaction._check_endedc                 C   s2   |    | jr	tz| | W d| _d S d| _w )NT)r$   r"   r   _end_transactionr   r\   r   r   r	   r[     s   zTransaction._endc                 C   s   | S r4   r   r   r   r   r	   	__enter__  s   zTransaction.__enter__c                 C   s&   | j s|d u r|   dS |   dS r   )r"   r\   r]   )r   exc_typeexc_valexc_tbr   r   r	   __exit__  s   zTransaction.__exit__c                 C   r   )zlReturn the rdataset associated with *name*, *rdtype*, and *covers*,
        or `None` if not found.
        r   r   r(   r0   r1   r   r   r	   r-     s   zTransaction._get_rdatasetc                 C   r   )zStore the rdataset.r   )r   r(   r.   r   r   r	   rw     r   zTransaction._put_rdatasetc                 C   r   )zlDelete all data associated with *name*.

        It is not an error if the rdataset does not exist.
        r   rC   r   r   r	   r~        zTransaction._delete_namec                 C   r   )zDelete all data associated with *name*, *rdtype*, and *covers*.

        It is not an error if the rdataset does not exist.
        r   r   r   r   r	   r{     r   zTransaction._delete_rdatasetc                 C   r   )z2Does name exist?

        Returns a bool.
        r   rC   r   r   r	   rB     r   zTransaction._name_existsc                 C   r   )z&Has this transaction changed anything?r   r   r   r   r	   rW     r   zTransaction._changedc                 C   r   )zEnd the transaction.

        *commit*, a bool.  If ``True``, commit the transaction, otherwise
        roll it back.

        If committing adn the commit fails, then roll back and raise an
        exception.
        r   r   r   r   r	   r     s   	zTransaction._end_transactionc                 C   r   )zSet the origin.

        This method is called when reading a possibly relativized
        source, and an origin setting operation occurs (e.g. $ORIGIN
        in a zone file).
        r   )r   rx   r   r   r	   _set_origin  s   zTransaction._set_originc                 C   r   )zxReturn an iterator that yields (name, rdataset) tuples.

        Not all Transaction subclasses implement this.
        r   r   r   r   r	   rU     r   zTransaction._iterate_rdatasetsN)FF)&r   r   r   r#   r'   r*   rI   r2   r5   r<   r=   r@   rA   rD   r(   emptyrS   rV   rX   r\   r]   r`   rl   r9   r?   r$   r[   r   r   r-   rw   r~   r{   rB   rW   r   r   rU   r   r   r   r	   r   R   s>    

 ,?	r   )rq   dns.exceptionr'   dns.namedns.rdataclassdns.rdatasetdns.rdatatype	dns.rrset
dns.serialdns.ttlr   	exceptionDNSExceptionr   r   r   r   r   r   r   r	   <module>   s   7