3 ¢báW'ã@s`dZddlZddlZddlZddlZddlZddlZddlZddl m Z Gdd„dej j ƒZ dS)zDNS Dynamic Update SupportéNé)Ú string_typescsxeZdZejjddejjf‡fdd„ Zddd„Z dd„Z dd „Z d d „Z d d „Z dd„Zddd„Zd‡fdd„ Z‡ZS)ÚUpdateNcsštt|ƒjƒ|jtjjtjjƒO_t|t ƒr>tj j |ƒ}||_ t|t ƒrZtj j |ƒ}||_|j|j|j |tjjddd�|dk r–|j|||d�dS)aäInitialize 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__ÚflagsÚdnsZopcodeZto_flagsZUPDATEÚ isinstancerÚnameÚ from_textÚoriginÚ 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)Ú authorityÚcoversrrÚrdtypeÚadd)rr ÚttlÚrdZdeletingÚsectionrZrrsetrrrÚ_add_rrEs  zUpdate._add_rrc Gs:t|tƒrtjj|dƒ}t|dtjjƒrnx@|D]8}|rF|j||jƒx |D]}|j ||j ||d�qLWq0WnÈt |ƒ}t |j dƒƒ}t|dtjjƒrÎ|r¬|j||djƒxˆ|D]}|j ||||d�q²Wnh|j dƒ}t|tƒrîtjj|ƒ}|rþ|j||ƒx6|D].} tjj|j|| |jƒ}|j ||||d��qWdS)aœAdd 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 ÚrdatasetÚRdatasetÚdeleterrrÚlistÚintÚpopÚrdataÚRdatarrr ) rÚreplacerr ÚargsÚrdsrrrÚsrrrÚ_addOs0         z Update._addcGs|jd|j|f|žŽdS)zÁAdd 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|tƒrtjj|dƒ}t|ƒdkrR|j|j|tjj tj j tj j tj j ddƒ�nt|dtj j ƒr–xü|D]&}x |D]}|j|d|tjj ƒqtWqjWnÌt|ƒ}t|dtjjƒrÔx°|D]}|j|d|tjj ƒq¶WnŽ|jdƒ}t|tƒrôtj j|ƒ}t|ƒdk�r(|j|j||j|tj j tjj ddƒn:x8|D]0}tjj|j|||jƒ}|j|d|tjj ƒ�q.WdS)zÚDelete records. The first argument is always a name. The other arguments can be: - I{nothing} - rdataset... - rdata... - rdtype, [string...]NrT)r rr r r ÚlenrrrÚANYrÚNONErrrr!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 Gsþt|tƒrtjj|dƒ}t|ƒdkrL|j|j|tjj tj j tj j dddƒn®t|dtj j ƒs|t|dtjjƒs|t|ƒdkrºt|dtj j ƒs¢t|ƒ}|jddƒ|jd|j|f|žŽn@|d}t|tƒrØtj j|ƒ}|j|j|tjj |tj j dddƒdS)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+rÚanswerrr,rr-rrr$r%r!Úinsertr*)rr r'rrrrÚpresent¼s*          zUpdate.presentc Cs„t|tƒrtjj|dƒ}|dkrH|j|j|tjjtj j tj jdddƒn8t|tƒr^tj j|ƒ}|j|j|tjj|tj jdddƒdS)z‚Require 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 rrrrÚabsentàs       z Update.absentéÿÿcs |dkr|j}tt|ƒj||ƒS)zcReturn a string containing the update in DNS compressed wire format. @rtype: stringN)r rrÚto_wire)rr Zmax_size)rrrr3ószUpdate.to_wire)NN)N)Nr2)Ú__name__Ú __module__Ú __qualname__r rÚINZtsigZdefault_algorithmrrr*rr r&r0r1r3Ú __classcell__rr)rrrs% ( +$ r)Ú__doc__Z dns.messager Zdns.nameZ dns.opcodeZ dns.rdataZdns.rdataclassZ dns.rdatasetZdns.tsigZ_compatrÚmessageZMessagerrrrrÚs