AlkantarClanX12

Your IP : 3.21.12.88


Current Path : /lib/python3.6/site-packages/dns/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/dns/__pycache__/zone.cpython-36.pyc

3

ӕ�WZ��@sNdZddlmZddlZddlZddlZddlmZddlZ	ddl
Z	ddlZ	ddlZ	ddl
Z	ddlZ	ddlZ	ddlZ	ddlZ	ddlZ	ddlmZmZejdkZGdd	�d	e	jj�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�Z de	j!j"dedddfdd�Z#de	j!j"dedddfdd�Z$eddfdd�Z%dS)z
DNS Zones.�)�
generatorsN)�BytesIO�)�string_types�	text_type�c@seZdZdZdS)�BadZonezThe DNS zone is malformed.N)�__name__�
__module__�__qualname__�__doc__�r
r
�/usr/lib/python3.6/zone.pyr)src@seZdZdZdS)�NoSOAz)The DNS zone has no SOA RR at its origin.N)r	r
rrr
r
r
rr.src@seZdZdZdS)�NoNSz+The DNS zone has no NS RRset at its origin.N)r	r
rrr
r
r
rr3src@seZdZdZdS)�
UnknownOriginz!The DNS zone's origin is unknown.N)r	r
rrr
r
r
rr8src@sjeZdZdZejjZddddgZej	j
dfdd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZeZd!d"�Zd#d$�ZdCd&d'�ZdDd(d)�Zd*d+�Zejjd%fd,d-�Z ejjd%fd.d/�Z!ejjfd0d1�Z"d2d3�Z#ejjfd4d5�Z$ejjfd6d7�Z%ejj&ejjfd8d9�Z'ejj&ejjfd:d;�Z(dEd=d>�Z)dFd?d@�Z*dAdB�Z+d<S)G�ZoneaZA DNS zone.

    A Zone is a mapping from names to nodes.  The zone object may be
    treated like a Python dictionary, e.g. zone[name] will retrieve
    the node associated with that name.  The I{name} may be a
    dns.name.Name object, or it may be a string.  In the either case,
    if the name is relative it is treated as relative to the origin of
    the zone.

    @ivar rdclass: The zone's rdata class; the default is class IN.
    @type rdclass: int
    @ivar origin: The origin of the zone.
    @type origin: dns.name.Name object
    @ivar nodes: A dictionary mapping the names of nodes in the zone to the
    nodes themselves.
    @type nodes: dict
    @ivar relativize: should names in the zone be relativized?
    @type relativize: bool
    @cvar node_factory: the factory used to create a new node
    @type node_factory: class or callable
    �rdclass�origin�nodes�
relativizeTcCsb|dk	rFt|t�r tjj|�}nt|tjj�s6td��|j�sFtd��||_||_	i|_
||_dS)z�Initialize a zone object.

        @param origin: The origin of the zone.
        @type origin: dns.name.Name object
        @param rdclass: The zone's rdata class; the default is class IN.
        @type rdclass: intNz2origin parameter must be convertible to a DNS namez)origin parameter must be an absolute name)�
isinstancer�dns�name�	from_text�Name�
ValueError�is_absoluterrrr)�selfrrrr
r
r�__init__Ys
z
Zone.__init__cCs:t|t�sdS|j|jks2|j|jks2|j|jkr6dSdS)ziTwo zones are equal if they have the same origin, class, and
        nodes.
        @rtype: bool
        FT)rrrrr)r�otherr
r
r�__eq__ns
zZone.__eq__cCs|j|�S)z6Are two zones not equal?
        @rtype: bool
        )r!)rr r
r
r�__ne__|szZone.__ne__cCsbt|t�rtjj|d�}nt|tjj�s0td��|j�r^|j|j	�sLtd��|j
r^|j
|j	�}|S)Nz0name parameter must be convertible to a DNS namez5name parameter must be a subdomain of the zone origin)rrrrrr�KeyErrorr�is_subdomainrr)rrr
r
r�_validate_name�s
zZone._validate_namecCs|j|�}|j|S)N)r%r)r�keyr
r
r�__getitem__�s
zZone.__getitem__cCs|j|�}||j|<dS)N)r%r)rr&�valuer
r
r�__setitem__�s
zZone.__setitem__cCs|j|�}|j|=dS)N)r%r)rr&r
r
r�__delitem__�s
zZone.__delitem__cCs
|jj�S)N)r�__iter__)rr
r
rr+�sz
Zone.__iter__cCstr|jj�S|jj�SdS)N)�_py3r�keys�iterkeys)rr
r
rr.�s
z
Zone.iterkeyscCs
|jj�S)N)rr-)rr
r
rr-�sz	Zone.keyscCstr|jj�S|jj�SdS)N)r,r�values�
itervalues)rr
r
rr0�s
zZone.itervaluescCs
|jj�S)N)rr/)rr
r
rr/�szZone.valuescCs
|jj�S)N)r�items)rr
r
rr1�sz
Zone.itemscCs|j|�}|jj|�S)N)r%r�get)rr&r
r
rr2�s
zZone.getcCs
||jkS)N)r)rr r
r
r�__contains__�szZone.__contains__FcCs<|j|�}|jj|�}|dkr8|s&t�|j�}||j|<|S)arFind a node in the zone, possibly creating it.

        @param name: the name of the node to find
        @type name: dns.name.Name object or string
        @param create: should the node be created if it doesn't exist?
        @type create: bool
        @raises KeyError: the name is not known and create was not specified.
        @rtype: dns.node.Node object
        N)r%rr2r#�node_factory)rr�create�noder
r
r�	find_node�s

zZone.find_nodecCs.y|j||�}Wntk
r(d}YnX|S)a�Get a node in the zone, possibly creating it.

        This method is like L{find_node}, except it returns None instead
        of raising an exception if the node does not exist and creation
        has not been requested.

        @param name: the name of the node to find
        @type name: dns.name.Name object or string
        @param create: should the node be created if it doesn't exist?
        @type create: bool
        @rtype: dns.node.Node object or None
        N)r7r#)rrr5r6r
r
r�get_node�s

z
Zone.get_nodecCs |j|�}||jkr|j|=dS)zhDelete the specified node if it exists.

        It is not an error if the node does not exist.
        N)r%r)rrr
r
r�delete_node�s

zZone.delete_nodecCsT|j|�}t|t�r tjj|�}t|t�r6tjj|�}|j||�}|j|j|||�S)a�Look for rdata with the specified name and type in the zone,
        and return an rdataset encapsulating it.

        The I{name}, I{rdtype}, and I{covers} parameters may be
        strings, in which case they will be converted to their proper
        type.

        The rdataset returned is not a copy; changes to it will change
        the zone.

        KeyError is raised if the name or type are not found.
        Use L{get_rdataset} if you want to have None returned instead.

        @param name: the owner name to look for
        @type name: DNS.name.Name object or string
        @param rdtype: the rdata type desired
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        @param create: should the node and rdataset be created if they do not
        exist?
        @type create: bool
        @raises KeyError: the node or rdata could not be found
        @rtype: dns.rrset.RRset object
        )	r%rrr�	rdatatyperr7�
find_rdatasetr)rr�rdtype�coversr5r6r
r
rr;�s


zZone.find_rdatasetcCs2y|j||||�}Wntk
r,d}YnX|S)a�Look for rdata with the specified name and type in the zone,
        and return an rdataset encapsulating it.

        The I{name}, I{rdtype}, and I{covers} parameters may be
        strings, in which case they will be converted to their proper
        type.

        The rdataset returned is not a copy; changes to it will change
        the zone.

        None is returned if the name or type are not found.
        Use L{find_rdataset} if you want to have KeyError raised instead.

        @param name: the owner name to look for
        @type name: DNS.name.Name object or string
        @param rdtype: the rdata type desired
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        @param create: should the node and rdataset be created if they do not
        exist?
        @type create: bool
        @rtype: dns.rrset.RRset object
        N)r;r#)rrr<r=r5�rdatasetr
r
r�get_rdatasets

zZone.get_rdatasetcCsr|j|�}t|t�r tjj|�}t|t�r6tjj|�}|j|�}|dk	rn|j|j||�t	|�dkrn|j
|�dS)a�Delete the rdataset matching I{rdtype} and I{covers}, if it
        exists at the node specified by I{name}.

        The I{name}, I{rdtype}, and I{covers} parameters may be
        strings, in which case they will be converted to their proper
        type.

        It is not an error if the node does not exist, or if there is no
        matching rdataset at the node.

        If the node has no rdatasets after the deletion, it will itself
        be deleted.

        @param name: the owner name to look for
        @type name: DNS.name.Name object or string
        @param rdtype: the rdata type desired
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        Nr)r%rrrr:rr8�delete_rdatasetr�lenr9)rrr<r=r6r
r
rr@4s



zZone.delete_rdatasetcCs.|j|jkrtd��|j|d�}|j|�dS)a:Replace an rdataset at name.

        It is not an error if there is no rdataset matching I{replacement}.

        Ownership of the I{replacement} object is transferred to the zone;
        in other words, this method does not store a copy of I{replacement}
        at the node, it stores I{replacement} itself.

        If the I{name} node does not exist, it is created.

        @param name: the owner name
        @type name: DNS.name.Name object or string
        @param replacement: the replacement rdataset
        @type replacement: dns.rdataset.Rdataset
        z#replacement.rdclass != zone.rdclassTN)rrr7�replace_rdataset)rrZreplacementr6r
r
rrBUszZone.replace_rdatasetcCsn|j|�}t|t�r tjj|�}t|t�r6tjj|�}|j|j|j||�}tj	j
||j||�}|j|�|S)a�Look for rdata with the specified name and type in the zone,
        and return an RRset encapsulating it.

        The I{name}, I{rdtype}, and I{covers} parameters may be
        strings, in which case they will be converted to their proper
        type.

        This method is less efficient than the similar
        L{find_rdataset} because it creates an RRset instead of
        returning the matching rdataset.  It may be more convenient
        for some uses since it returns an object which binds the owner
        name to the rdata.

        This method may not be used to create new nodes or rdatasets;
        use L{find_rdataset} instead.

        KeyError is raised if the name or type are not found.
        Use L{get_rrset} if you want to have None returned instead.

        @param name: the owner name to look for
        @type name: DNS.name.Name object or string
        @param rdtype: the rdata type desired
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        @raises KeyError: the node or rdata could not be found
        @rtype: dns.rrset.RRset object
        )r%rrrr:rrr;r�rrsetZRRset�update)rrr<r=r>rCr
r
r�
find_rrsetks



zZone.find_rrsetcCs0y|j|||�}Wntk
r*d}YnX|S)aJLook for rdata with the specified name and type in the zone,
        and return an RRset encapsulating it.

        The I{name}, I{rdtype}, and I{covers} parameters may be
        strings, in which case they will be converted to their proper
        type.

        This method is less efficient than the similar L{get_rdataset}
        because it creates an RRset instead of returning the matching
        rdataset.  It may be more convenient for some uses since it
        returns an object which binds the owner name to the rdata.

        This method may not be used to create new nodes or rdatasets;
        use L{find_rdataset} instead.

        None is returned if the name or type are not found.
        Use L{find_rrset} if you want to have KeyError raised instead.

        @param name: the owner name to look for
        @type name: DNS.name.Name object or string
        @param rdtype: the rdata type desired
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        @rtype: dns.rrset.RRset object
        N)rEr#)rrr<r=rCr
r
r�	get_rrset�s

zZone.get_rrsetccs~t|t�rtjj|�}t|t�r,tjj|�}xL|j�D]@\}}x6|D].}|tjjksh|j|krD|j|krD||fVqDWq6WdS)a�Return a generator which yields (name, rdataset) tuples for
        all rdatasets in the zone which have the specified I{rdtype}
        and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
        then all rdatasets will be matched.

        @param rdtype: int or string
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        N)	rrrr:r�	iteritems�ANYr<r=)rr<r=rr6�rdsr
r
r�iterate_rdatasets�s


zZone.iterate_rdatasetsccs�t|t�rtjj|�}t|t�r,tjj|�}x^|j�D]R\}}xH|D]@}|tjjksh|j|krD|j|krDx|D]}||j	|fVqnWqDWq6WdS)a�Return a generator which yields (name, ttl, rdata) tuples for
        all rdatas in the zone which have the specified I{rdtype}
        and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
        then all rdatas will be matched.

        @param rdtype: int or string
        @type rdtype: int or string
        @param covers: the covered type (defaults to None)
        @type covers: int or string
        N)
rrrr:rrGrHr<r=�ttl)rr<r=rr6rI�rdatar
r
r�iterate_rdatas�s



zZone.iterate_rdatasNcCs8t|t�rt|d�}d}nd}t|dd�}|dkr6d}|dkrPtjj|�}d}n"t|t�rf|j|�}n|}|j�}z�|r�t|j	��}|j
�n|j�}x�|D]�}	||	j|	|j
|d�}
t|
t�r�|
j|�}n|
}|
j�}
y|j|�|j|�Wq�tk
�r|j|
�|j|�Yq�Xq�WWd|�r2|j�XdS)	aWrite a zone to a file.

        @param f: file or string.  If I{f} is a string, it is treated
        as the name of a file to open.
        @param sorted: if True, the file will be written with the
        names sorted in DNSSEC order from least to greatest.  Otherwise
        the names will be written in whatever order they happen to have
        in the zone's dictionary.
        @param relativize: if True, domain names in the output will be
        relativized to the zone's origin (if possible).
        @type relativize: bool
        @param nl: The end of line string.  If not specified, the
        output will use the platform's native end-of-line marker (i.e.
        LF on POSIX, CRLF on Windows, CR on Macintosh).
        @type nl: string or None
        �wbTF�encodingNzutf-8�
)rr)rr�open�getattr�os�linesep�encode�decode�listr-�sortr.�to_textrr�write�	TypeError�close)r�f�sortedr�nl�
want_closeZfile_encZnl_b�names�n�lZl_br
r
r�to_file�sD







zZone.to_filecCs*t�}|j||||�|j�}|j�|S)a�Return a zone's text as though it were written to a file.

        @param sorted: if True, the file will be written with the
        names sorted in DNSSEC order from least to greatest.  Otherwise
        the names will be written in whatever order they happen to have
        in the zone's dictionary.
        @param relativize: if True, domain names in the output will be
        relativized to the zone's origin (if possible).
        @type relativize: bool
        @param nl: The end of line string.  If not specified, the
        output will use the platform's native end-of-line marker (i.e.
        LF on POSIX, CRLF on Windows, CR on Macintosh).
        @type nl: string or None
        )rrd�getvaluer\)rr^rr_Ztemp_bufferZreturn_valuer
r
rrY$s
zZone.to_textcCsJ|jrtjj}n|j}|j|tjj�dkr.t�|j|tjj	�dkrFt
�dS)z�Do some simple checking of the zone's origin.

        @raises dns.zone.NoSOA: there is no SOA RR
        @raises dns.zone.NoNS: there is no NS RRset
        @raises KeyError: there is no origin node
        N)rrr�emptyrr?r:ZSOArZNSr)rrr
r
r�check_origin9s
zZone.check_origin)F)F)TTN)TTN),r	r
rrrr6ZNoder4�	__slots__�
rdataclass�INrr!r"r%r'r)r*r+r.r-r0r/r1rGr2r3r7r8r9r:ZNONEr;r?r@rBrErFrHrJrMrdrYrgr
r
r
rr=sJ



# !("
@
rc@sHeZdZdZeddfdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
_MasterReadera�Read a DNS master file

    @ivar tok: The tokenizer
    @type tok: dns.tokenizer.Tokenizer object
    @ivar ttl: The default TTL
    @type ttl: int
    @ivar last_name: The last name read
    @type last_name: dns.name.Name object
    @ivar current_origin: The current origin
    @type current_origin: dns.name.Name object
    @ivar relativize: should names in the zone be relativized?
    @type relativize: bool
    @ivar zone: the zone
    @type zone: dns.zone.Zone object
    @ivar saved_state: saved reader state (used when processing $INCLUDE)
    @type saved_state: list of (tokenizer, current_origin, last_name, file)
    tuples.
    @ivar current_file: the file object of the $INCLUDed file being parsed
    (None if no $INCLUDE is active).
    @ivar allow_include: is $INCLUDE allowed?
    @type allow_include: bool
    @ivar check_origin: should sanity checks of the origin node be done?
    The default is True.
    @type check_origin: bool
    FTcCsbt|t�rtjj|�}||_||_||_d|_|j|_	||||d�|_
g|_d|_||_
||_dS)Nr)r)rrrrr�tok�current_originrrK�	last_name�zone�saved_state�current_file�
allow_includerg)rrlrrr�zone_factoryrrrgr
r
rrfs
z_MasterReader.__init__cCsx|jj�}|j�rPqWdS)N)rlr2�
is_eol_or_eof)r�tokenr
r
r�	_eat_lineus
z_MasterReader._eat_linec"Cs�|jdkrt�|jjdd�}|j�s:tjj|j|j�|_	n"|jj�}|j
�rPdS|jj|�|j	}|j|j
j�s||j�dS|jr�|j|j
j�}|jj�}|j�s�tjj�y,tjj|j�}|jj�}|j�s�tjj�Wntjjk
r�|j}YnXy.tjj|j�}|jj�}|j��s"tjj�Wn>tjjk
�rFtjj�Yntk
�rb|j
j}YnX||j
jk�r~tjjd��ytjj|j�}Wntjjd|j��YnX|j
jj|�}|dk�r�|j
j�}||j
j|<ytjj|||j|jd�}Wnltjjk
�r,tj�dd�\}}	|	�Yn<tj�dd�\}}	tjjdt|�t|	�f��YnX|j |j
j|j�|j!�}
|j"|||
d�}|j#||�dS)	z(Process one line from a DNS master file.NT)Zwant_leadingzRR class is not zone's classzunknown rdatatype '%s'F�zcaught exception %s: %s)$rmrrlr2Z
is_whitespacerrrr(rnrt�ungetr$rorrvr�
is_identifier�	exception�SyntaxErrorrK�BadTTLri�	Exceptionrr:rr4rL�sys�exc_info�str�choose_relativityr=r;�add)rrurrKrr<rb�rd�ty�var=rIr
r
r�_rr_line{sx







z_MasterReader._rr_linec
Cs�tjd�}tjd�}tjd�}|j|�}|rJ|j�\}}}}	}
|dkrJd}|j|�}|rz|j�\}}}|dkrrd}d}	d}
|j|�}|r�|j�\}}}}	|dkr�d}|j�d}	d}
|p�|p�|s�d}d}d}d}	d}
|
dkr�t��||||	|
fS)	Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$��+r�drw)�re�compile�match�groups�NotImplementedError)
rZsideZis_generate1Zis_generate2Zis_generate3Zg1�modZsign�offset�width�baseZg2Zg3r
r
r�
_parse_modify�s>





z_MasterReader._parse_modifyc!7Cs|jdkrt�|jj�}y2tjj|j�\}}}|jj�}|j�sHtj	j
�Wntj	j
�YnXy$|j}|jj�}|j�s�tj	j
�Wntj	j
�YnXy,tjj|j�}|jj�}|j�s�tj	j
�Wntjjk
r�|j}YnXy.tj
j|j�}|jj�}|j��stj	j
�Wn>tj	j
k
�r6tj	j
�Yntk
�rR|jj}YnX||jjk�rntj	j
d��y.tjj|j�}|jj�}|j��s�tj	j
�Wn(tk
�r�tj	j
d|j��YnXy
|j}	Wntj	j
�YnX|j|�\}
}}}
}|j|	�\}}}}}�x�t||d|�D�]�}|dk�r@|t|�}n|dk�rV|t|�}|dk�rn|t|�}n|dk�r�|t|�}t|�jt|
��}t|�jt|��}|jd|
|�}|	jd||�}tjj||j�|_|j}|j|jj��s�|j�dS|j�r|j|jj�}|jjj|�}|dk�r@|jj�}||jj|<ytj j||||jd�}Wnltj	j
k
�r�t!j"�dd	�\}}|�Yn<t!j"�dd	�\}}tj	j
d
t|�t|�f��YnX|j#|jj|j�|j$�}|j%|||d�} | j&||��q"WdS)zRProcess one line containing the GENERATE statement from a DNS
        master file.NzRR class is not zone's classzunknown rdatatype '%s'rr��-z$%sFrwzcaught exception %s: %sT)'rmrrlr2rZgrangerr(ryrzr{rKr|rir}rorr:r��range�intr��zfill�replacerrnr$rrvrrr4rLr~rr�r=r;r�)!rru�start�stop�stepZlhsrKrr<ZrhsZlmodZlsignZloffsetZlwidthZlbaseZrmodZrsignZroffsetZrwidthZrbase�iZlindex�rindexZlzfindexZrzfindexrrLrbr�r�r�r=rIr
r
r�_generate_line�s�















z_MasterReader._generate_linecCs��y�x|jjdd�}|j�rh|jdk	r2|jj�t|j�dkrb|jjd�\|_|_|_	|_|_
qP�n�|j�rvq�n�|j�r�|jj
�q�nx|jddk�r|jj�}|dkr�|jj�}|j�s�tjjd��tj
j|j�|_
|jj
�q|dk�r$|jj�|_|jj
�|jjdk�r|j|j_q|d	k�r�|j�r�|jj�}|j}|jj�}|j��rxtjj|j|j�}|jj
�n|j��s�tjjd
��n|j}|jj|j|j|j	|j|j
f�t|d�|_tjj|j|�|_||_q|dk�r�|j�qtjjd
|d��q|jj |�|j!�qWWnZtjjk
�rz}z8|jj"�\}}|dk�rTd}tjjd|||f��WYdd}~XnX|j#�r�|jj#�dS)z�Read a DNS master file and build a zone object.

        @raises dns.zone.NoSOA: No SOA RR was found at the zone origin
        @raises dns.zone.NoNS: No NS RRset was found at the zone origin
        TNrr�$z$TTLzbad $TTLz$ORIGINz$INCLUDEzbad origin in $INCLUDE�rz	$GENERATEzUnknown master file directive '�'zsyntax errorz	%s:%d: %s���)$rlr2Zis_eofrqr\rArp�poprmrnrKZis_eolZ
is_commentZget_eolr(�upperryrrzr{rZget_namerorrrrrt�appendrQ�	tokenizer�	Tokenizerr�rxr��whererg)rru�c�filenameZ
new_originZdetailZline_numberr
r
r�reades�

 















"z_MasterReader.readN)r	r
rrrrrvr�r�r�r�r
r
r
rrkJsL)urkTFc
	Cs>|dkrd}tjj||�}t|||||||d�}	|	j�|	jS)arBuild a zone object from a master file format string.

    @param text: the master file format input
    @type text: string.
    @param origin: The origin of the zone; if not specified, the first
    $ORIGIN statement in the master file will determine the origin of the
    zone.
    @type origin: dns.name.Name object or string
    @param rdclass: The zone's rdata class; the default is class IN.
    @type rdclass: int
    @param relativize: should names be relativized?  The default is True
    @type relativize: bool
    @param zone_factory: The zone factory to use
    @type zone_factory: function returning a Zone
    @param filename: The filename to emit when describing where an error
    occurred; the default is '<string>'.
    @type filename: string
    @param allow_include: is $INCLUDE allowed?
    @type allow_include: bool
    @param check_origin: should sanity checks of the origin node be done?
    The default is True.
    @type check_origin: bool
    @raises dns.zone.NoSOA: No SOA RR was found at the zone origin
    @raises dns.zone.NoNS: No NS RRset was found at the zone origin
    @rtype: dns.zone.Zone object
    Nz<string>)rrrg)rr�r�rkr�ro)
�textrrrrsr�rrrgrl�readerr
r
rr�s"rcCslt}d}	t||�r.|dkr|}t||	�}d}
n|dkr:d}d}
zt||||||||�}Wd|
rf|j�X|S)a�Read a master file and build a zone object.

    @param f: file or string.  If I{f} is a string, it is treated
    as the name of a file to open.
    @param origin: The origin of the zone; if not specified, the first
    $ORIGIN statement in the master file will determine the origin of the
    zone.
    @type origin: dns.name.Name object or string
    @param rdclass: The zone's rdata class; the default is class IN.
    @type rdclass: int
    @param relativize: should names be relativized?  The default is True
    @type relativize: bool
    @param zone_factory: The zone factory to use
    @type zone_factory: function returning a Zone
    @param filename: The filename to emit when describing where an error
    occurred; the default is '<file>', or the value of I{f} if I{f} is a
    string.
    @type filename: string
    @param allow_include: is $INCLUDE allowed?
    @type allow_include: bool
    @param check_origin: should sanity checks of the origin node be done?
    The default is True.
    @type check_origin: bool
    @raises dns.zone.NoSOA: No SOA RR was found at the zone origin
    @raises dns.zone.NoNS: No NS RRset was found at the zone origin
    @rtype: dns.zone.Zone object
    ZrUNTz<file>F)rrrQrr\)r]rrrrsr�rrrgZstr_typeZoptsr`�zr
r
r�	from_file�s 


r�cCs�d}x�|D]�}|dkrH|r"|j}n|jdj}|jdj}||||d�}x||jD]r}|jj|j�}	|	sz|j�}	|	|j|j<|	j|j|j|j	d�}
|
j
|j�x$|D]}|j|j|�|
j
|�q�WqPWq
W|r�|j�|S)a�Convert the output of a zone transfer generator into a zone object.

    @param xfr: The xfr generator
    @type xfr: generator of dns.message.Message objects
    @param relativize: should names be relativized?  The default is True.
    It is essential that the relativize setting matches the one specified
    to dns.query.xfr().
    @type relativize: bool
    @param check_origin: should sanity checks of the origin node be done?
    The default is True.
    @type check_origin: bool
    @raises dns.zone.NoSOA: No SOA RR was found at the zone origin
    @raises dns.zone.NoNS: No NS RRset was found at the zone origin
    @rtype: dns.zone.Zone object
    Nr)rT)rZanswerrrrr2r4r;r<r=Z
update_ttlrKr�r�rg)Zxfrrsrrgr�r�rrrCZznodeZzrdsr�r
r
r�from_xfrs,


r�)r)&rZ
__future__rr~r�rS�iorZ
dns.exceptionrZdns.nameZdns.nodeZdns.rdataclassZ
dns.rdatatypeZ	dns.rdataZ	dns.rrsetZ
dns.tokenizerZdns.ttlZ
dns.grangeZ_compatrr�version_infor,rzZDNSExceptionrrrr�objectrrkrirjrr�r�r
r
r
r�<module>sH
o*3