3 ¢báW' ã @ s` d Z ddlZddlZddlZddlZddlZddlZddlZddl m Z G dd„ dejjƒZ dS )zDNS Dynamic Update Supporté Né )Ústring_typesc sx e Zd Zejjddejjf‡ fdd„ Zddd„Z dd„ Z dd „ Zd d„ Zdd „ Z dd„ Zddd„Zd‡ fdd„ Z‡ ZS )ÚUpdateNc sš t t| ƒ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)ZcreateZforce_uniqueN)Ú algorithm)Úsuperr Ú__init__ÚflagsÚdnsZopcodeZto_flagsZUPDATEÚ isinstancer ÚnameÚ from_textÚoriginÚ rdataclassÚzone_rdclassÚ find_rrsetZquestionÚ rdatatypeZSOAZuse_tsig)ÚselfZzoneZrdclassZkeyringZkeynameZkeyalgorithm)Ú __class__© ú/usr/lib/python3.6/update.pyr s zUpdate.__init__c C sB |dkr| j }|jƒ }| j||| j|j||ddƒ}|j||ƒ dS )z&Add a single RR to the update section.NT)Ú authorityÚcoversr r ÚrdtypeÚadd)r r ÚttlÚrdZdeletingÚsectionr Zrrsetr r r Ú_add_rrE s zUpdate._add_rrc G s: t |tƒrtjj|dƒ}t |d tjjƒrnx@|D ]8}|rF| j||jƒ x |D ]}| j ||j ||d� qLW q0W nÈt|ƒ}t|j dƒƒ}t |d tjjƒrÎ|r¬| j||d jƒ xˆ|D ]}| j ||||d� q²W nh|j dƒ}t |tƒrîtjj|ƒ}|rþ| j||ƒ x6|D ].} tjj| j|| | jƒ}| j ||||d� �qW dS )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 r r r r ÚrdatasetÚRdatasetÚdeleter r r ÚlistÚintÚpopÚrdataÚRdatar r r ) r Úreplacer r ÚargsÚrdsr r r Úsr r r Ú_addO s0 zUpdate._addc G s | j d| 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 )r r r' r r r r w s z Update.addc G sf t |tƒrtjj|dƒ}t|ƒdkrR| j| j|tjj tj j tj jtj j ddƒ �nt |d tjj ƒr–xü|D ]&}x |D ]}| j|d|tjjƒ qtW qjW nÌt|ƒ}t |d tjjƒrÔx°|D ]}| j|d|tjjƒ q¶W nŽ|jdƒ}t |tƒrôtj j|ƒ}t|ƒdk�r(| j| j|| j|tj jtjj ddƒ n:x8|D ]0}tjj| j||| jƒ}| j|d|tjjƒ �q.W dS )zÚDelete records. The first argument is always a name. The other arguments can be: - I{nothing} - rdataset... - rdata... - rdtype, [string...]Nr T)r r r r r Úlenr r r ÚANYr ÚNONEr r r r! r$ r% r# r r )r r r' r( r r r) r r r r ‚ s6 z Update.deletec G s | j d| j|f|žŽ dS )aQ Replace 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 )r r r' r r r r&