U mf-@sdZddlZddlZddlmZmZmZmZmZddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ Gddde jjZe jjZe jjZe jjZe jjZe jjZe jjZGddde jjZdS)zDNS Versioned Zones.N)CallableDequeOptionalSetUnionc@seZdZdZdS)UseTransactionz-To alter a versioned zone, use a transaction.N)__name__ __module__ __qualname____doc__r r ;/opt/hc_python/lib/python3.8/site-packages/dns/versioned.pyrsrc sbeZdZdddddddgZeZejjdd fe e ej j e fejjee edege efd fd d Zd=e ee eed ddZd>eedddZddZddZddZe ed dddZe edege efd dddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Z d*d+Z!d?e ej j e feej"jd,fd-d. Z#e ej j e fd d/d0d1Z$ej%j&dfe ej j e fe ej%j'e fe ej%j'e feej(j)d2fd3d4 Z*ej%j&dfe ej j e fe ej%j'e fe ej%j'e fee ej(j)d2fd5d6 Z+ej%j&fe ej j e fe ej%j'e fe ej%j'e fd d7d8d9Z,e ej j e fej(j)d d:d;d<Z-Z.S)@Zone _versionsZ_versions_lock _write_txn_write_waiters _write_event_pruning_policy_readersTN)originrdclass relativizepruning_policycstt|||t|_t|_|dkr6|j|_ n||_ d|_ d|_ t|_ t |_|dt|dd|dS)aInitialize a versioned zone object. *origin* is the origin of the zone. It may be a ``dns.name.Name``, a ``str``, or ``None``. If ``None``, then the zone's origin will be set by the first ``$ORIGIN`` line in a zone file. *rdclass*, an ``int``, the zone's rdata class; the default is class IN. *relativize*, a ``bool``, determine's whether domain names are relativized to the zone's origin. The default is ``True``. *pruning policy*, a function taking a ``Zone`` and a ``Version`` and returning a ``bool``, or ``None``. Should the version be pruned? If ``None``, the default policy, which retains one version is used. NT) replacement)super__init__ collectionsdequer threadingLock _version_lock_default_pruning_policyrrrrsetr_commit_version_unlockedWritableVersion)selfrrrr __class__r r r.s     z Zone.__init__)idserialreturnc Cs,|dk r|dk rtd|j|dk rbd}t|jD]}|j|kr8|}qPq8|dkrtdn|dk r|jrztjj }n|j dk st |j }d}t|jD]@}|j |}|r||jtjj}|r|dj|kr|}qq|dkrtdn |jd}t|d|}|j||W5QRSQRXdS)Nz!cannot specify both id and serialzversion not foundrzserial not foundF) ValueErrorr reversedrr(KeyErrorrdnsnameemptyrAssertionErrornodesget get_rdatasetr rdatatypeZSOAr) Transactionradd) r%r(r)versionvZonamenZrdstxnr r r readerSs<         z Zone.readerF)rr*c Cszd}|jP|jdkrB||jkrBt||dd|_d|_W5QRqjt}|j|W5QRX|q|j |jS)NT)Zmake_immutable) r rrr7rEventrappendwaitZ_setup_version)r%reventr r r writerws   z Zone.writercCs(t|jdkr$|j|_|jdS)Nr)lenrpopleftrr")r%r r r !_maybe_wakeup_one_waiter_unlockeds z&Zone._maybe_wakeup_one_waiter_unlockedcCsdS)NTr )r%zoner9r r r r!szZone._default_pruning_policycCstt|jdkstt|jdkr6tdd|jD}n |jdj}|jdj|krp|||jdrp|jqBdS)Nrcss|]}|jjVqdSN)r9r().0r<r r r sz0Zone._prune_versions_unlocked..r+)rCrr2rminr(rrD)r%Z least_keptr r r _prune_versions_unlockeds zZone._prune_versions_unlocked) max_versionsr*csDdk rdkrtddkr*dd}n fdd}||dS)zYSet a pruning policy that retains up to the specified number of versions Nzmax versions must be at least 1cSsdS)NFr rF_r r r policysz%Zone.set_max_versions..policycst|jkSrG)rCrrNrLr r rPs)r,set_pruning_policy)r%rLrPr rQr set_max_versionss   zZone.set_max_versions)rPr*c Cs2|dkr|j}|j||_|W5QRXdS)aSet the pruning policy for the zone. The *policy* function takes a `Version` and returns `True` if the version should be pruned, and `False` otherwise. `None` may also be specified for policy, in which case the default policy is used. Pruning checking proceeds from the least version and the first time the function returns `False`, the checking stops. I.e. the retained versions are always a consecutive sequence. N)r!r rrK)r%rPr r r rRs zZone.set_pruning_policyc Cs*|j|j||W5QRXdSrG)r rremoverKr%r<r r r _end_reads zZone._end_readcCs |j|kstd|_|dSrG)rr2rErUr r r _end_write_unlockedszZone._end_write_unlockedc Cs |j||W5QRXdSrG)r rWrUr r r _end_writeszZone._end_writecCsB|j|||j|_|jdkr,||_|dk r>||dSrG)rr?rKr3rrWr%r<r9rr r r r#s  zZone._commit_version_unlockedc Cs$|j||||W5QRXdSrG)r r#rYr r r _commit_versionszZone._commit_versioncCs(t|jdkr |jdjd}nd}|S)Nrr+rM)rCrr()r%r(r r r _get_next_version_idszZone._get_next_version_id)r0creater*cs|rtt|SrG)rr find_node)r%r0r\r&r r r]szZone.find_node)r0r*cCstdSrGr)r%r0r r r delete_nodeszZone.delete_node)r0rdtypecoversr\r*cs$|rtt|||}tj|SrG)rr find_rdatasetr/rdatasetImmutableRdatasetr%r0r`rar\rcr&r r rbszZone.find_rdatasetcs4|rtt|||}|dk r,tj|SdSdSrG)rrr5r/rcrdrer&r r r5$s  zZone.get_rdataset)r0r`rar*cCstdSrGr^)r%r0r`rar r r delete_rdataset3szZone.delete_rdataset)r0rr*cCstdSrGr^)r%r0rr r r replace_rdataset;szZone.replace_rdataset)NN)F)F)/rr r __slots__NodeZ node_factoryr/Z rdataclassINrrr0NamestrZ RdataClassboolrVersionrintr7r=rBrEr!rKrSrRrVrWrXr#rZr[noder]r_r6NONEZ RdataTypercZRdatasetrbr5rfrg __classcell__r r r&r r!s & $1    r) r rrtypingrrrrrZ dns.exceptionr/Z dns.immutableZdns.nameZdns.nodeZdns.rdataclassZ dns.rdatasetZ dns.rdatatypeZdns.rdtypes.ANY.SOAZdns.zone exceptionZ DNSExceptionrrFZ VersionedNoderiZImmutableVersionedNodeZ ImmutableNodernr$ZImmutableVersionr7rr r r r s(