3 bW'@s`dZddlZddlZddlZddlZddlZddlZddlZddl m Z Gdddej j Z dS)zDNS Dynamic Update SupportN) string_typescsxeZdZejjddejjffdd ZdddZ ddZ dd Z d d Z d d Z ddZdddZdfdd ZZS)UpdateNcstt|j|jtjjtjjO_t|t r>tj j |}||_ t|t rZtj j |}||_|j|j|j |tjjddd|dk r|j|||ddS)aInitialize a new DNS Update object. @param zone: The zone which is being updated. @type zone: A dns.name.Name or string @param rdclass: The class of the zone; defaults to dns.rdataclass.IN. @type rdclass: An int designating the class, or a string whose value is the name of a class. @param keyring: The TSIG keyring to use; defaults to None. @type keyring: dict @param keyname: The name of the TSIG key to use; defaults to None. The key must be defined in the keyring. If a keyring is specified but a keyname is not, then the key used will be the first key in the keyring. Note that the order of keys in a dictionary is not defined, so applications should supply a keyname when a keyring is used, unless they know the keyring contains only one key. @type keyname: dns.name.Name or string @param keyalgorithm: The TSIG algorithm to use; defaults to dns.tsig.default_algorithm. Constants for TSIG algorithms are defined in dns.tsig, and the currently implemented algorithms are HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, and HMAC_SHA512. @type keyalgorithm: string T)ZcreateZ force_uniqueN) algorithm)superr__init__flagsdnsZopcodeZto_flagsZUPDATE isinstancername from_textorigin rdataclass zone_rdclass find_rrsetZquestion rdatatypeZSOAZuse_tsig)selfZzoneZrdclassZkeyringZkeynameZ keyalgorithm) __class__/usr/lib/python3.6/update.pyrs     zUpdate.__init__c CsB|dkr|j}|j}|j|||j|j||dd}|j||dS)z&Add a single RR to the update section.NT) authoritycoversrrrdtypeadd)rr ttlrdZdeletingsectionrZrrsetrrr_add_rrEs  zUpdate._add_rrc Gs:t|trtjj|d}t|dtjjrnx@|D]8}|rF|j||jx |D]}|j ||j ||dqLWq0Wnt |}t |j d}t|dtjjr|r|j||djx|D]}|j ||||dqWnh|j d}t|trtjj|}|r|j||x6|D].} tjj|j|| |j}|j ||||dqWdS)aAdd records. The first argument is the replace 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 rr r r rdatasetRdatasetdeleterrrlistintpoprdataRdatarrr ) rreplacerr argsrdsrrrsrrr_addOs0         z Update._addcGs|jd|j|f|dS)zAdd records. The first argument is always a name. The other arguments can be: - rdataset... - ttl, rdata... - ttl, rdtype, string...FN)r*r)rr r'rrrrws z Update.addc Gsft|trtjj|d}t|dkrR|j|j|tjj tj j tj j tj j ddnt|dtj j rx|D]&}x |D]}|j|d|tjj qtWqjWnt|}t|dtjjrx|D]}|j|d|tjj qWn|jd}t|trtj j|}t|dkr(|j|j||j|tj j tjj ddn:x8|D]0}tjj|j|||j}|j|d|tjj q.WdS)zDelete records. The first argument is always a name. The other arguments can be: - I{nothing} - rdataset... - rdata... - rdtype, [string...]NrT)r rr r r lenrrrANYrNONErrrr!r$r%r#rr )rr r'r(rrr)rrrr s6            z Update.deletecGs|jd|j|f|dS)aQReplace 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.TN)r*r)rr r'rrrr&s zUpdate.replacec Gst|trtjj|d}t|dkrL|j|j|tjj tj j tj j dddnt|dtj j s|t|dtjjs|t|dkrt|dtj j st|}|jdd|jd|j|f|n@|d}t|trtj j|}|j|j|tjj |tj j ddddS)aBRequire 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...NrTrF)r rr r r r+ranswerrr,rr-rrr$r%r!insertr*)rr r'rrrrpresents*          zUpdate.presentc Cst|trtjj|d}|dkrH|j|j|tjjtj j tj jdddn8t|tr^tj j|}|j|j|tjj|tj jddddS)zRequire that an owner name (and optionally an rdata type) does not exist as a prerequisite to the execution of the update.NT) r rr r r rr.rr-rr,)rr rrrrabsents       z Update.absentcs |dkr|j}tt|j||S)zcReturn a string containing the update in DNS compressed wire format. @rtype: stringN)r rrto_wire)rr Zmax_size)rrrr3szUpdate.to_wire)NN)N)Nr2)__name__ __module__ __qualname__r rINZtsigZdefault_algorithmrrr*rr r&r0r1r3 __classcell__rr)rrrs% ( +$ r)__doc__Z dns.messager Zdns.nameZ dns.opcodeZ dns.rdataZdns.rdataclassZ dns.rdatasetZdns.tsigZ_compatrmessageZMessagerrrrrs