U mflX@s.ddlZddlmZmZmZmZmZmZmZddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ GdddZGddde jjZGddde jjZGd d d e jjZd d Zd dZede jje jjgdfZede jje j j!e j j!gdfZ"ede jjgdfZ#GdddZ$dS)N)AnyCallableIteratorListOptionalTupleUnionc@s|eZdZddddZdeddddZeeej j eeej j fdd d Z ej j dd d Zeej j dd dZdS)TransactionManager TransactionreturncCstdS)zBegin a read-only transaction.NNotImplementedErrorselfr=/opt/hc_python/lib/python3.8/site-packages/dns/transaction.pyreaderszTransactionManager.readerF) replacementr cCstdS)aBegin 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. Nr )rrrrrwriterszTransactionManager.writercCstdS)aqReturns 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). Nr rrrrorigin_information sz%TransactionManager.origin_informationcCstdS)z%The class of the transaction manager.Nr rrrr get_class;szTransactionManager.get_classcCs|\}}}|r|SdSdS)z#Origin to use in from_wire() calls.N)r)rZabsolute_originZ relativize_rrrfrom_wire_origin?sz#TransactionManager.from_wire_originN)F)__name__ __module__ __qualname__rboolrrrdnsnameNamerZ rdataclassZ RdataClassrrrrrrr s   r c@seZdZdZdS)DeleteNotExactz>Existing data did not match data specified by an exact delete.Nrrr__doc__rrrrr!Hsr!c@seZdZdZdS)ReadOnlyz*Tried to write to a read-only transaction.Nr"rrrrr$Lsr$c@seZdZdZdS) AlreadyEndedz*Tried to use an already-ended transaction.Nr"rrrrr%Psr%cCs&|dkst|tjjr|Stj|SN) isinstancerrdatasetImmutableRdataset)r(rrr_ensure_immutable_rdatasetTsr*cCs |dks|r|Stj|Sr&)Z is_immutablernodeZ ImmutableNode)r+rrr_ensure_immutable_nodeZsr,r c@sdeZdZd`eeedddZejjfe e ej j e fe ejje fe ejje fejjdddZej j e ejjdd d Zd d d dZed dddZed dddZed dddZed dddZe ej j e fedddZddej jfeeej j d dddZdd Zed d!d"Z d d d#d$Z!d d d%d&Z"e#d d'd(d)Z$e%d d'd*d+Z&e'd d'd,d-Z(e)e*ej j ejjfd d.d/Z+e)ej j d d0d1Z,d2d3Z-d4d5Z.d6d7Z/d8d9Z0d:d;Z1dd?Z3d@dAZ4dBdCZ5dDdEZ6dFdGZ7dHdIZ8dJdKZ9dLdMZ:dNdOZ;dPdQZdVdWZ?dXdYZ@dZd[ZAd\d]ZBd^d_ZCd S)ar F)managerr read_onlycCs.||_||_||_d|_g|_g|_g|_dSNF)r-rr._ended_check_put_rdataset_check_delete_rdataset_check_delete_name)rr-rr.rrr__init__kszTransaction.__init__)rrdtypecoversr cCsR|t|tr tj|d}tjj|}tjj|}| |||}t |S)zReturn the rdataset associated with *name*, *rdtype*, and *covers*, or `None` if not found. Note that the returned rdataset is immutable. N) _check_endedr'strrr from_text rdatatype RdataTypemake _get_rdatasetr*)rrr5r6r(rrrgets  zTransaction.get)rr cCst||S)z[Return the node at *name*, if any. Returns an immutable node or ``None``. )r, _get_noderrrrrget_nodeszTransaction.get_nodeNr cCs|jr tdSr&)r.r$rrrr_check_read_onlyszTransaction._check_read_only)argsr cGs |||d|dS)zAdd records. The arguments may be: - rrset - name, rdataset... - name, ttl, rdata... FNr7rB_addrrCrrradds zTransaction.addcGs |||d|dS)aReplace 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(). TNrDrFrrrreplaceszTransaction.replacecGs |||d|dS)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, rdatatype, [covers] - name, rdataset... - name, rdata... FNr7rB_deleterFrrrdeleteszTransaction.deletecGs |||d|dS)a4Delete records. The arguments may be: - rrset - name - name, rdatatype, [covers] - name, rdataset... - name, rdata... Raises dns.transaction.DeleteNotExact if some of the records are not in the existing set. TNrIrFrrr delete_exactszTransaction.delete_exactcCs*|t|tr tj|d}||S)zDoes the specified name exist?N)r7r'r8rrr9 _name_existsr@rrr name_existss zTransaction.name_existsT)valuerelativerr cCs||dkrtdt|tr0tj|d}||tjj tjj }|dksZt |dkr^t |rztj |dj |}n tj |}|j}|dkrd}|dj|d}tj|j|}|||dS)aUpdate 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. rznegative update_serial() valueNrO)serial)r7 ValueErrorr'r8rrr9r=r:SOANONElenKeyErrorrRZSerialrPrHr( from_rdatattl)rrPrQrr(rRrdataZ new_rdatasetrrr update_serials"  zTransaction.update_serialcCs||Sr&r7_iterate_rdatasetsrrrr__iter__szTransaction.__iter__cCs||S)aHas 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. )r7_changedrrrrchangedszTransaction.changedcCs|ddS)aCommit 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_endrrrrcommit)s zTransaction.commitcCs|ddS)avRollback 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. FNrarrrrrollback6s zTransaction.rollback)checkr cCs|j|dS)aCall *check* before putting (storing) an rdataset. The function is called with the transaction, the name, and the rdataset. The check function may safely make non-mutating transaction method calls, but behavior is undefined if mutating transaction methods are called. The check function should raise an exception if it objects to the put, and otherwise should return ``None``. N)r1appendrrerrrcheck_put_rdatasetBs zTransaction.check_put_rdatasetcCs|j|dS)aCall *check* before deleting an rdataset. The function is called with the transaction, the name, the rdatatype, and the covered rdatatype. The check function may safely make non-mutating transaction method calls, but behavior is undefined if mutating transaction methods are called. The check function should raise an exception if it objects to the put, and otherwise should return ``None``. N)r2rfrgrrrcheck_delete_rdatasetNs z!Transaction.check_delete_rdatasetcCs|j|dS)aCall *check* before putting (storing) an rdataset. The function is called with the transaction and the name. The check function may safely make non-mutating transaction method calls, but behavior is undefined if mutating transaction methods are called. The check function should raise an exception if it objects to the put, and otherwise should return ``None``. N)r3rfrgrrrcheck_delete_name[s zTransaction.check_delete_namecCs||S)a@Iterate all the rdatasets in the transaction, returning (`dns.name.Name`, `dns.rdataset.Rdataset`) tuples. Note that as is usual with python iterators, adding or removing items while iterating will invalidate the iterator and may raise `RuntimeError` or fail to iterate over all entries.r\rrrriterate_rdatasetsgs zTransaction.iterate_rdatasetscCs||S)zIterate all the names in the transaction. Note that as is usual with python iterators, adding or removing names while iterating will invalidate the iterator and may raise `RuntimeError` or fail to iterate over all entries.)r7_iterate_namesrrrr iterate_namessszTransaction.iterate_namescCst|dkrtd|dS)Nrzextra parameters to )rV TypeError)rmethodrCrrr_raise_if_not_emptys zTransaction._raise_if_not_emptycCsz|}t|tjjr"|}nt|tjjr6|}nv|r@d}n@t|trj|}|tj j krxt |dnt |d|}t|tj jrtj||}nt |d|WStk r|rYdSt |dYnXdS)Nrz: TTL value too bigz: expected a TTLz: expected an Rdataz: expected more arguments)popleftr'rrrsetRRset to_rdatasetr(RdatasetintrYZMAX_TTLrSrnrZZRdatarX IndexError)rroZdeletingrCargr(rYrrr_rdataset_from_argss,   zTransaction._rdataset_from_argsc CszVt|}|rd}nd}|}t|trszTransaction._get_rdatasetcCstdS)zStore the rdataset.Nr )rrr(rrrrDszTransaction._put_rdatasetcCstdS)zhDelete all data associated with *name*. It is not an error if the name does not exist. Nr r@rrrrHszTransaction._delete_namecCstdS)zDelete all data associated with *name*, *rdtype*, and *covers*. It is not an error if the rdataset does not exist. Nr rrrrrOszTransaction._delete_rdatasetcCstdS)z2Does name exist? Returns a bool. Nr r@rrrrMVszTransaction._name_existscCstdS)z&Has this transaction changed anything?Nr rrrrr_]szTransaction._changedcCstdS)zEnd the transaction. *commit*, a bool. If ``True``, commit the transaction, otherwise roll it back. If committing and the commit fails, then roll back and raise an exception. Nr rrrrras zTransaction._end_transactioncCstdS)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). Nr )rrrrr _set_originlszTransaction._set_origincCstdS)z7Return an iterator that yields (name, rdataset) tuples.Nr rrrrr]uszTransaction._iterate_rdatasetscCstdS)z&Return an iterator that yields a name.Nr rrrrrlyszTransaction._iterate_namescCstdS)zPReturn the node at *name*, if any. Returns a node or ``None``. Nr r@rrrr?}szTransaction._get_nodecCs |jSr&)r-rrrrrrszTransaction._origin_information)FF)Drrrr rr4rr:rUrrrr r8r;r(rur>r+NoderArBrrGrHrKrLrNemptyrvr[r^r`rcrdCheckPutRdatasetTyperhCheckDeleteRdatasetTyperiCheckDeleteNameTyperjrrrkrmrpryrErJr7rbrrrrrr=rrrrMr_rrr]rlr?rrrrrr js~    $       ,@      )%r}typingrrrrrrrZ dns.exceptionrZdns.nameZdns.nodeZdns.rdataclassZ dns.rdatasetZ dns.rdatatypeZ dns.rrsetZ dns.serialZdns.ttlr exceptionZ DNSExceptionr!r$r%r*r,rr r(rurr:r;rrr rrrrs4$7