HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/dns/__pycache__/zone.cpython-310.pyc
o

!we���@s dZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZm
Z
mZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m!Z!m"Z"m#Z#Gdd�dej$j%�Z&Gdd�de&�Z'Gd	d
�d
e&�Z(Gdd�de&�Z)Gd
d�dej$j%�Z*Gdd�dej$j%�Z+Gdd�dej$j%�Z,Gdd�dej$j%�Z-Gdd�dej.j/�Z0Gdd�dej1j2�Z3ej4j4Gdd�de3��Z5Gdd�d�Z6Gdd�de6�Z7ej4j4Gdd �d e6��Z8Gd!d"�d"ej.j9�Z9dej:j;d#e0dd$d#dd#f	d%e<d&eeej=j>e<fd'ej:j?d(e@d)ed*ee<d+e@d,e@d-eej=jAd.ee@ee<fd/e0fd0d1�ZBdej:j;d#e0dd#d#dd#f	d2ed&eeej=j>e<fd'ej:j?d(e@d)ed*ee<d+e@d,e@d-eej=jAd.ee@ee<fd/e0fd3d4�ZCe0d#d#fd5ed)ed(e@d,e@d/e0f
d6d7�ZDdS)8z
DNS Zones.�N)	�Any�Dict�Iterable�Iterator�List�Optional�Set�Tuple�Union)�DigestHashAlgorithm�DigestScheme�_digest_hashersc@�eZdZdZdS)�BadZonezThe DNS zone is malformed.N��__name__�
__module__�__qualname__�__doc__�rr�A/home/arjun/projects/env/lib/python3.10/site-packages/dns/zone.pyr-�rc@r)�NoSOAz)The DNS zone has no SOA RR at its origin.Nrrrrrr2rrc@r)�NoNSz+The DNS zone has no NS RRset at its origin.Nrrrrrr7rrc@r)�
UnknownOriginz!The DNS zone's origin is unknown.Nrrrrrr<rrc@r)�UnsupportedDigestSchemez(The zone digest's scheme is unsupported.NrrrrrrArrc@r)�UnsupportedDigestHashAlgorithmz(The zone digest's origin is unsupported.NrrrrrrFrrc@r)�NoDigestz/The DNS zone has no ZONEMD RRset at its origin.NrrrrrrKrrc@r)�DigestVerificationFailurez#The ZONEMD digest failed to verify.NrrrrrrPrrc@s�eZdZdZejjZgd�Zej	j
dfdeeej
jefdej	jdefdd�Zd	d
�Zdd�Zd
eej
jefdej
jfdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Z	#dgd
eej
jefd$edejjfd%d&�Z	#dgd
eej
jefd$edeejjfd'd(�Z d
eej
jefdd)fd*d+�Z!ej"j#d#fd
eej
jefd,eej"j$efd-eej"j$efd$edej%j&f
d.d/�Z'ej"j#d#fd
eej
jefd,eej"j$efd-eej"j$efd$edeej%j&f
d0d1�Z(ej"j#fd
eej
jefd,eej"j$efd-eej"j$efdd)fd2d3�Z)d
eej
jefd4ej%j&dd)fd5d6�Z*ej"j#fd
eej
jefd,eej"j$efd-eej"j$efdej+j,fd7d8�Z-ej"j#fd
eej
jefd,eej"j$efd-eej"j$efdeej+j,fd9d:�Z.ej"j/ej"j#fd,eej"j$efd-eej"j$efde0e1ej
jej%j&ffd;d<�Z2ej"j/ej"j#fd,eej"j$efd-eej"j$efde0e1ej
je3ej4j5ffd=d>�Z6			)	#	#dhd?e7d@ededAeedBedCedd)fdDdE�Z8			)	#	#dhd@ededAeedBedCedefdFdG�Z9didHdI�Z:	)djdJeej;j<dej=j/j>j>fdKdL�Z?e@jAfdMeBdNe@deCfdOdP�ZDe@jAfdMeBdNe@dej=j/jEjEfdQdR�ZF	)djdSeej=j/jEjEdd)fdTdU�ZGdkdWdX�ZHdgd4eddVfdYdZ�ZIde1eej
jeeej
jffd[d\�ZJd]d^�ZKd_d`�ZLdadb�ZMdcdd�ZNdedf�ZOd)S)l�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 *name* may be a
    ``dns.name.Name object``, or it may be a string.  In either case,
    if the name is relative it is treated as relative to the origin of
    the zone.
    )�rdclass�origin�nodes�
relativizeTr!r r#cCsb|dur#t|t�rtj�|�}nt|tjj�std��|��s#td��||_||_	i|_
||_dS)a�Initialize a 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``.
        Nz2origin parameter must be convertible to a DNS namez)origin parameter must be an absolute name)�
isinstance�str�dns�name�	from_text�Name�
ValueError�is_absoluter!r r"r#)�selfr!r r#rrr�__init__es

z
Zone.__init__cCs:t|t�sdS|j|jks|j|jks|j|jkrdSdS)zqTwo zones are equal if they have the same origin, class, and
        nodes.

        Returns a ``bool``.
        FT)r$rr r!r"�r,�otherrrr�__eq__�s
zZone.__eq__cCs|�|�S)z>Are two zones not equal?

        Returns a ``bool``.
        )r0r.rrr�__ne__�szZone.__ne__r'�returncCs�t|t�r
tj�|d�}nt|tjj�std��|��r:|jdur%td��|�	|j�s/td��|j
r8|�
|j�}|S|j
sL|jdurFtd��|�|j�}|S)Nz0name parameter must be convertible to a DNS name�no zone origin is definedz5name parameter must be a subdomain of the zone origin)r$r%r&r'r(r)�KeyErrorr+r!�is_subdomainr#�derelativize�r,r'rrr�_validate_name�s"

�
zZone._validate_namecCs|�|�}|j|S�N�r8r"�r,�keyrrr�__getitem__��

zZone.__getitem__cCs|�|�}||j|<dSr9r:)r,r<�valuerrr�__setitem__�s
zZone.__setitem__cCs|�|�}|j|=dSr9r:r;rrr�__delitem__��
zZone.__delitem__cC�
|j��Sr9)r"�__iter__�r,rrrrD��
z
Zone.__iter__cCrCr9�r"�keysrErrrrH�rFz	Zone.keyscCrCr9)r"�valuesrErrrrI�rFzZone.valuescCrCr9�r"�itemsrErrrrK�rFz
Zone.itemscC�|�|�}|j�|�Sr9�r8r"�getr;rrrrN�rBzZone.getcCs|�|�}||jvSr9r:r;rrr�__contains__�r>zZone.__contains__F�createcCs<|�|�}|j�|�}|dur|st�|��}||j|<|S)aNFind a node in the zone, possibly creating it.

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *create*, a ``bool``.  If true, the node will be created if it does
        not exist.

        Raises ``KeyError`` if the name is not known and create was
        not specified, or if the name was not a subdomain of the origin.

        Returns a ``dns.node.Node``.
        N)r8r"rNr4�node_factory�r,r'rP�noderrr�	find_node�s

zZone.find_nodecCs,z	|�||�}W|Styd}Y|Sw)aGet a node in the zone, possibly creating it.

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

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *create*, a ``bool``.  If true, the node will be created if it does
        not exist.

        Raises ``KeyError`` if the name is not known and create was
        not specified, or if the name was not a subdomain of the origin.

        Returns a ``dns.node.Node`` or ``None``.
        N)rTr4rRrrr�get_node�s��z
Zone.get_nodeNcCs$|�|�}||jvr|j|=dSdS)akDelete the specified node if it exists.

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        It is not an error if the node does not exist.
        Nr:r7rrr�delete_nodes

�zZone.delete_node�rdtype�coverscCsD|�|�}tjj�|�}tjj�|�}|�||�}|�|j|||�S)a�Look for an rdataset with the specified name and type in the zone,
        and return an rdataset encapsulating it.

        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.

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdatatype.RdataType`` or ``str`` the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.

        *create*, a ``bool``.  If true, the node will be created if it does
        not exist.

        Raises ``KeyError`` if the name is not known and create was
        not specified, or if the name was not a subdomain of the origin.

        Returns a ``dns.rdataset.Rdataset``.
        )r8r&�	rdatatype�	RdataType�makerT�
find_rdatasetr )r,r'rWrXrPrSrrrr\s

)zZone.find_rdatasetcCs0z|�||||�}W|Styd}Y|Sw)a%Look for an rdataset with the specified name and type in the zone.

        This method is like ``find_rdataset()``, except it returns None instead
        of raising an exception if the rdataset does not exist and creation
        has not been requested.

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

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdatatype.RdataType`` or ``str``, the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.

        *create*, a ``bool``.  If true, the node will be created if it does
        not exist.

        Raises ``KeyError`` if the name is not known and create was
        not specified, or if the name was not a subdomain of the origin.

        Returns a ``dns.rdataset.Rdataset`` or ``None``.
        N)r\r4)r,r'rWrXrP�rdatasetrrr�get_rdatasetIs*��zZone.get_rdatasetcCsj|�|�}tjj�|�}tjj�|�}|�|�}|dur1|�|j||�t|�dkr3|�	|�dSdSdS)a�Delete the rdataset matching *rdtype* and *covers*, if it
        exists at the node specified by *name*.

        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.

        *name*: the name of the node to find. The value may be a ``dns.name.Name`` or a
        ``str``.  If absolute, the name must be a subdomain of the zone's origin.  If
        ``zone.relativize`` is ``True``, then the name will be relativized.

        *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdatatype.RdataType`` or ``str`` or ``None``, the covered
        type. Usually this value is ``dns.rdatatype.NONE``, but if the rdtype is
        ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``, then the covers value will be
        the rdata type the SIG/RRSIG covers.  The library treats the SIG and RRSIG types
        as if they were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA). This
        makes RRSIGs much easier to work with than if RRSIGs covering different rdata
        types were aggregated into a single RRSIG rdataset.
        Nr)
r8r&rYrZr[rU�delete_rdatasetr �lenrV�r,r'rWrXrSrrrr_ys

�zZone.delete_rdataset�replacementcCs.|j|jkr
td��|�|d�}|�|�dS)a�Replace an rdataset at name.

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

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

        If the node does not exist, it is created.

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *replacement*, a ``dns.rdataset.Rdataset``, the replacement rdataset.
        z#replacement.rdclass != zone.rdclassTN)r r*rT�replace_rdataset)r,r'rbrSrrrrc�szZone.replace_rdatasetcCs^|�|�}tjj�|�}tjj�|�}|j|�|j||�}tj�	||j||�}|�
|�|S)a�Look for an rdataset with the specified name and type in the zone,
        and return an RRset encapsulating it.

        This method is less efficient than the similar
        ``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 rdataset.

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

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdatatype.RdataType`` or ``str``, the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.

        *create*, a ``bool``.  If true, the node will be created if it does
        not exist.

        Raises ``KeyError`` if the name is not known and create was
        not specified, or if the name was not a subdomain of the origin.

        Returns a ``dns.rrset.RRset`` or ``None``.
        )r8r&rYrZr[r"r\r �rrset�RRset�update)r,r'rWrX�vnamer]rdrrr�
find_rrset�s
,
zZone.find_rrsetcCs.z
|�|||�}W|Styd}Y|Sw)a�Look for an rdataset with the specified name and type in the zone,
        and return an RRset encapsulating it.

        This method is less efficient than the similar ``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 rdataset.

        This method may not be used to create new nodes or rdatasets;
        use ``get_rdataset()`` instead.

        *name*: the name of the node to find.
        The value may be a ``dns.name.Name`` or a ``str``.  If absolute, the
        name must be a subdomain of the zone's origin.  If ``zone.relativize``
        is ``True``, then the name will be relativized.

        *rdtype*, a ``dns.rdataset.Rdataset`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdataset.Rdataset`` or ``str``, the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.

        *create*, a ``bool``.  If true, the node will be created if it does
        not exist.

        Raises ``KeyError`` if the name is not known and create was
        not specified, or if the name was not a subdomain of the origin.

        Returns a ``dns.rrset.RRset`` or ``None``.
        N)rhr4)r,r'rWrXrdrrr�	get_rrset�s+��zZone.get_rrsetccsh�tjj�|�}tjj�|�}|��D]\}}|D]}|tjjks+|j|kr0|j|kr0||fVqqdS)a�Return a generator which yields (name, rdataset) tuples for
        all rdatasets in the zone which have the specified *rdtype*
        and *covers*.  If *rdtype* is ``dns.rdatatype.ANY``, the default,
        then all rdatasets will be matched.

        *rdtype*, a ``dns.rdataset.Rdataset`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdataset.Rdataset`` or ``str``, the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.
        N)r&rYrZr[rK�ANYrWrX)r,rWrXr'rS�rdsrrr�iterate_rdatasetss�
���zZone.iterate_rdatasetsccsv�tjj�|�}tjj�|�}|��D]%\}}|D]}|tjjks+|j|kr7|j|kr7|D]	}||j|fVq-qqdS)a�Return a generator which yields (name, ttl, rdata) tuples for
        all rdatas in the zone which have the specified *rdtype*
        and *covers*.  If *rdtype* is ``dns.rdatatype.ANY``, the default,
        then all rdatas will be matched.

        *rdtype*, a ``dns.rdataset.Rdataset`` or ``str``, the rdata type desired.

        *covers*, a ``dns.rdataset.Rdataset`` or ``str``, the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.
        N)	r&rYrZr[rKrjrWrX�ttl)r,rWrXr'rSrk�rdatarrr�iterate_rdatas>s����zZone.iterate_rdatas�f�sorted�nl�
want_comments�want_originc
Cs�t|t�rt|d�}nt�|�}|��}t|dd�}|durd}|dur,tj�|�}	d}nt|t�r7|�|�}	n|}	|�	�}|rr|j
dusFJ�d|j
��}
|
�|�}z|�|�|�|	�Wnt
yq|�|
�|�|�Ynw|rt|���}|��n|��}|D]2}
||
j|
|j
||d�}
|
�|�}z|�|�|�|	�Wq�t
y�|�|
�|�|�Yq�wWd�dS1s�wYdS)a=Write a zone to a file.

        *f*, a file or `str`.  If *f* is a string, it is treated
        as the name of a file to open.

        *sorted*, a ``bool``.  If True, the default, then 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.

        *relativize*, a ``bool``.  If True, the default, then domain
        names in the output will be relativized to the zone's origin
        if possible.

        *nl*, a ``str`` or None.  The end of line string.  If not
        ``None``, the output will use the platform's native
        end-of-line marker (i.e. LF on POSIX, CRLF on Windows).

        *want_comments*, a ``bool``.  If ``True``, emit end-of-line comments
        as part of writing the file.  If ``False``, the default, do not
        emit them.

        *want_origin*, a ``bool``.  If ``True``, emit a $ORIGIN line at
        the start of the file.  If ``False``, the default, do not emit
        one.
        �wb�encodingNzutf-8�
z$ORIGIN )r!r#rs)r$r%�open�
contextlib�nullcontext�getattr�os�linesep�encode�decoder!�to_text�write�	TypeError�listrH�sort)r,rprqr#rrrsrt�cm�file_enc�nl_b�l�l_b�names�nrrr�to_file_s\
$




�
�


��"�zZone.to_filecCs0t��}|�||||||�|��}|��|S)aReturn a zone's text as though it were written to a file.

        *sorted*, a ``bool``.  If True, the default, then 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.

        *relativize*, a ``bool``.  If True, the default, then domain
        names in the output will be relativized to the zone's origin
        if possible.

        *nl*, a ``str`` or None.  The end of line string.  If not
        ``None``, the output will use the platform's native
        end-of-line marker (i.e. LF on POSIX, CRLF on Windows).

        *want_comments*, a ``bool``.  If ``True``, emit end-of-line comments
        as part of writing the file.  If ``False``, the default, do not
        emit them.

        *want_origin*, a ``bool``.  If ``True``, emit a $ORIGIN line at
        the start of the output.  If ``False``, the default, do not emit
        one.

        Returns a ``str``.
        )�io�StringIOr��getvalue�close)r,rqr#rrrsrt�temp_buffer�return_valuerrrr��s
!zZone.to_textcCsX|jrtjj}n
|jdusJ�|j}|�|tjj�durt�|�|tjj	�dur*t
�dS)z�Do some simple checking of the zone's origin.

        Raises ``dns.zone.NoSOA`` if there is no SOA RRset.

        Raises ``dns.zone.NoNS`` if there is no NS RRset.

        Raises ``KeyError`` if there is no origin node.
        N)r#r&r'�emptyr!r^rY�SOAr�NSrr7rrr�check_origin�s	
�zZone.check_origin�txncCs^|jrtjj}n
|jdurt�|j}|r|�|tjj�}n|�	|tjj�}|dur+t�|dS)z�Get the zone SOA rdata.

        Raises ``dns.zone.NoSOA`` if there is no SOA RRset.

        Returns a ``dns.rdtypes.ANY.SOA.SOA`` Rdata.
        Nr)
r#r&r'r�r!rrNrYr�r^)r,r��origin_name�soarrr�get_soa�s	

zZone.get_soa�hash_algorithm�schemecst�|�}|s	t�|tjkrt��jrtjj	}n
�j
dusJ��j
}|�}t����D]R\}}|�
�j
�}t|dd�d�D]?}	||krNtjj|	j|	jfvrNq=t�d|	j|	j|	j�}
�fdd�|	D�}t|�D]}t�dt|��}
|�||
|
|�qfq=q+|��S)NcSs|j|jfSr9)rWrX)rkrrr�<lambda>sz&Zone._compute_digest.<locals>.<lambda>)r<z!HHIcsg|]}|��j��qSr)�
to_digestabler!)�.0rnrErr�
<listcomp>(�z(Zone._compute_digest.<locals>.<listcomp>z!H)r
rNrr�SIMPLErr#r&r'r�r!rqrKr�rY�ZONEMDrWrX�struct�packr rmr`rf�digest)r,r�r��hashinfor��hasherr'rS�	rrnamebufr]�rrfixed�rdatasrn�rrlenrrEr�_compute_digests8


����
zZone._compute_digestcCs6|��j}|�||�}tjjj�|jtjj||||�Sr9)	r��serialr�r&�rdtypesrjr�r rY)r,r�r�r�r�rrr�compute_digest.s


�zZone.compute_digest�zonemdc	Cs�|r|g}n|jdus
J�|�|jtjj�}|durt�|}|D]}z|�|j|j�}||j	kr4WdSWq t
y>Yq wt�r9)r!r^r&rYr�rr�r�r�r��	Exceptionr)r,r��digestsrkr��computedrrr�
verify_digest9s"
��zZone.verify_digest�TransactioncCst|dt|d|j|j��S)NF�)r��Versionr"r!rErrr�readerPszZone.readercCst||�}|��|Sr9)r��_setup_version)r,rbr�rrr�writerSs
zZone.writercCs$|jrtjj}n|j}|j|j|fSr9)r#r&r'r�r!)r,�	effectiverrr�origin_informationXs
zZone.origin_informationcC�|jSr9)r rErrr�	get_classbszZone.get_classcC�dSr9r�r,r�rrr�	_end_readg�zZone._end_readcCr�r9rr�rrr�
_end_writejr�zZone._end_writecCs |j|_|jdur||_dSdSr9)r"r!)r,�_�versionr!rrr�_commit_versionms

�zZone._commit_versioncC�dS)Nr�rrErrr�_get_next_version_idrszZone._get_next_version_id�F)TTNFF)r2Nr9)r2r�)Prrrrr&rS�NoderQ�	__slots__�
rdataclass�INrr
r'r)r%�
RdataClass�boolr-r0r1r8r=r@rArDrHrIrKrNrOrTrUrVrY�NONErZr]�Rdatasetr\r^r_rcrdrerhrirjrr	rl�intrn�Rdatarorr�r�r��transactionr�r�r�r�rr�r�bytesr�r�r�r�r�r�r�r�r�r�r�r�rrrrrUs�
���
�"���
����

������
�3�����

�4����
�&��
�����
�8����

�3���
�"���
�$�������
�[������
�
'�
�

����
�%���

���
�

�
rcs"eZdZdgZ�fdd�Z�ZS)�
VersionedNode�idcst���d|_dS�Nr)�superr-r�rE��	__class__rrr-�s

zVersionedNode.__init__)rrrr�r-�
__classcell__rrr�rr�sr�cs�eZdZ�fdd�Zejjdfdejjdejj	dejj	de
dejjf
�fd	d
�
Z
ejjdfdejjdejj	dejj	de
deejjf
�fdd�
Zejjfdejjdejj	dejj	dd
fdd�Zdejjdd
fdd�Zde
fdd�Z�ZS)�ImmutableVersionedNodecs,t���|j|_tdd�|jD��|_dS)NcSsg|]}tj�|��qSr)r&r]�ImmutableRdataset)r�rkrrrr��r�z3ImmutableVersionedNode.__init__.<locals>.<listcomp>)r�r-r��tuple�	rdatasets)r,rSr�rrr-�s


�zImmutableVersionedNode.__init__Fr rWrXrPr2c�|rtd��t��|||d�S�N�	immutableF)r�r�r\�r,r rWrXrPr�rrr\��z$ImmutableVersionedNode.find_rdatasetcr�r�)r�r�r^r�r�rrr^�r�z#ImmutableVersionedNode.get_rdatasetNcC�td���Nr��r�)r,r rWrXrrrr_�sz&ImmutableVersionedNode.delete_rdatasetrbcCr�r�r�)r,rbrrrrc�sz'ImmutableVersionedNode.replace_rdatasetcCr��NTrrErrr�is_immutable�r�z#ImmutableVersionedNode.is_immutable)rrrr-r&rYr�r�r�rZr�r]r�r\rr^r_rcr�r�rrr�rr��sP�����������
�����
�r�c
@s�eZdZ		ddededeeejj	ej
jfdeejj	fdd�Zdejj	d	ejj	fd
d�Z
dejj	d	eej
jfdd
�Zdejj	dejjdejjd	eejjfdd�Zdd�Zdd�ZdS)r�N�zoner�r"r!cCs,||_||_|dur||_ni|_||_dSr9)r�r�r"r!)r,r�r�r"r!rrrr-�s
zVersion.__init__r'r2cCsp|��r#|jdur
td��|�|j�std��|jjr!|�|j�}|S|jjs6|jdur0td��|�|j�}|S)Nr3z*name is not a subdomain of the zone origin)r+r!r4r5r�r#r6r7rrrr8�s
�
zVersion._validate_namecCrLr9rMr7rrrrU�rBzVersion.get_noderWrXcCs(|�|�}|durdS|�|jj||�Sr9)rUr^r�r rarrrr^�s
zVersion.get_rdatasetcCrCr9rGrErrrrH�rFzVersion.keyscCrCr9rJrErrrrK�rFz
Version.items)NN)rrrrr�rrr&r'r)rSr�r-r8rUrYrZr]r�r^rHrKrrrrr��s2����

����

�r�cs�eZdZddedef�fdd�
Zdejjdej	j
fdd	�Zdejjdd
fdd�Zdejjd
ej
jdd
fdd�Zdejjdejjdejjdd
fdd�Z�ZS)�WritableVersionFr�rbcs<|��}t��||�|s|j�|j�|j|_t�|_dSr9)r�r�r-r"rfr!�set�changed)r,r�rbr�r�rrr-�szWritableVersion.__init__r'r2cCsx|�|�}|j�|�}|dus||jvr:|j��}t|d�r"|j|_|dur-|j�	|j�||j|<|j�
|�|S|S)Nr�)r8r"rNr�r�rQ�hasattrr�r��extend�add)r,r'rS�new_noderrr�
_maybe_cow�s



zWritableVersion._maybe_cowNcCs0|�|�}||jvr|j|=|j�|�dSdSr9)r8r"r�r�r7rrrrVs


�zWritableVersion.delete_noder]cCs|�|�}|�|�dSr9)r�rc)r,r'r]rSrrr�put_rdatasets
zWritableVersion.put_rdatasetrWrXcCs8|�|�}|�|jj||�t|�dkr|j|=dSdSr�)r�r_r�r r`r"rarrrr_!s

�zWritableVersion.delete_rdatasetr�)rrrrr�r-r&r'r)rSr�r�rVr]r�r�rYrZr_r�rrr�rr��s(��
�����r�cs"eZdZdef�fdd�Z�ZS)�ImmutableVersionr�cs`t��|jd�|j|_|j|_|jD]}|j�|�}|r$t|�|j|<qt	j
�|jd�|_dSr�)r�r-r�r�r!r�r"rNr�r&r�r)r,r�r'rSr�rrr-/s
�zImmutableVersion.__init__)rrrr�r-r�rrr�rr�-sr�cs�eZdZd!�fdd�	Zedd��Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Z�ZS)"r�NFcs(|du}t��|||�||_||_dSr9)r�r-r��make_immutable)r,r�rbr�r��	read_onlyr�rrr-Ds
zTransaction.__init__cCr�r9)�managerrErrrr�JszTransaction.zonecCs"|jdusJ�t|j|j�|_dSr9)r�r�r�rbrErrrr�NszTransaction._setup_versioncCs|j�|||�Sr9)r�r^�r,r'rWrXrrr�
_get_rdatasetR�zTransaction._get_rdatasetcCs|jrJ�|j�||�dSr9)r�r�r�)r,r'r]rrr�
_put_rdatasetUs
zTransaction._put_rdatasetcCs|jrJ�|j�|�dSr9)r�r�rVr7rrr�_delete_nameYs
zTransaction._delete_namecCs|jrJ�|j�|||�dSr9)r�r�r_r�rrr�_delete_rdataset]s
zTransaction._delete_rdatasetcCs|j�|�duSr9�r�rUr7rrr�_name_existsar�zTransaction._name_existscCs|jrdSt|jj�dkS)NFr)r�r`r�r�rErrr�_changeddszTransaction._changedcCsj|jr|j�|�dS|r-t|jj�dkr-|jrt|j�}n|j}|j�|||jj	�dS|j�
|�dSr�)r�r�r�r`r�r�r�r�r�r!r�)r,�commitr�rrr�_end_transactionjszTransaction._end_transactioncCs|jjdur||j_dSdSr9)r�r!)r,r!rrr�_set_originws�zTransaction._set_originccs.�|j��D]\}}|D]}||fVqqdSr9)r�rK)r,r'rSr]rrr�_iterate_rdatasets{s���zTransaction._iterate_rdatasetscCrCr9)r�rHrErrr�_iterate_names�rFzTransaction._iterate_namescCs|j�|�Sr9rr7rrr�	_get_node�szTransaction._get_nodecCsH|j��\}}}|dur|jjdur|jj}|rtjj}n|}|||fSr9)r�r�r�r!r&r'r�)r,�absoluter#r�rrr�_origin_information�s

zTransaction._origin_information)NF)rrrr-�propertyr�r�r�r�r�r�rrrrrrrr
r�rrr�rr�Cs"

r�TF�textr!r r#�zone_factory�filename�
allow_includer��
idna_codec�allow_directivesr2c
	Cs�|durd}||||d�}
|
�d��0}tjj|||d�}tjj|||||	d�}
z|
��Wn
tjjy:tjj�wWd�n1sEwY|rP|
�	�|
S)aBuild a zone object from a zone file format string.

    *text*, a ``str``, the zone file format input.

    *origin*, a ``dns.name.Name``, a ``str``, or ``None``.  The origin
    of the zone; if not specified, the first ``$ORIGIN`` statement in the
    zone file will determine the origin of the zone.

    *rdclass*, a ``dns.rdataclass.RdataClass``, 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``.

    *zone_factory*, the zone factory to use or ``None``.  If ``None``, then
    ``dns.zone.Zone`` will be used.  The value may be any class or callable
    that returns a subclass of ``dns.zone.Zone``.

    *filename*, a ``str`` or ``None``, the filename to emit when
    describing where an error occurred; the default is ``'<string>'``.

    *allow_include*, a ``bool``.  If ``True``, the default, then ``$INCLUDE``
    directives are permitted.  If ``False``, then encoutering a ``$INCLUDE``
    will raise a ``SyntaxError`` exception.

    *check_origin*, a ``bool``.  If ``True``, the default, then sanity
    checks of the origin node will be made by calling the zone's
    ``check_origin()`` method.

    *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
    encoder/decoder.  If ``None``, the default IDNA 2003 encoder/decoder
    is used.

    *allow_directives*, a ``bool`` or an iterable of `str`.  If ``True``, the default,
    then directives are permitted, and the *allow_include* parameter controls whether
    ``$INCLUDE`` is permitted.  If ``False`` or an empty iterable, then no directive
    processing is done and any directive-like text will be treated as a regular owner
    name.  If a non-empty iterable, then only the listed directives (including the
    ``$``) are allowed.

    Raises ``dns.zone.NoSOA`` if there is no SOA RRset.

    Raises ``dns.zone.NoNS`` if there is no NS RRset.

    Raises ``KeyError`` if there is no origin node.

    Returns a subclass of ``dns.zone.Zone``.
    Nz<string>�r#T)r)rr)
r�r&�	tokenizer�	Tokenizer�zonefile�Reader�readrr�r�)rr!r r#r
rrr�rrr�r��tokr�rrrr(�s,A����r(rpc
Cslt|t�r|dur|}t|�}
nt�|�}
|
�}t||||||||||	�
Wd�S1s/wYJ�)aRead a zone file and build a zone object.

    *f*, a file or ``str``.  If *f* is a string, it is treated
    as the name of a file to open.

    *origin*, a ``dns.name.Name``, a ``str``, or ``None``.  The origin
    of the zone; if not specified, the first ``$ORIGIN`` statement in the
    zone file will determine the origin of the zone.

    *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``.

    *zone_factory*, the zone factory to use or ``None``.  If ``None``, then
    ``dns.zone.Zone`` will be used.  The value may be any class or callable
    that returns a subclass of ``dns.zone.Zone``.

    *filename*, a ``str`` or ``None``, the filename to emit when
    describing where an error occurred; the default is ``'<string>'``.

    *allow_include*, a ``bool``.  If ``True``, the default, then ``$INCLUDE``
    directives are permitted.  If ``False``, then encoutering a ``$INCLUDE``
    will raise a ``SyntaxError`` exception.

    *check_origin*, a ``bool``.  If ``True``, the default, then sanity
    checks of the origin node will be made by calling the zone's
    ``check_origin()`` method.

    *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
    encoder/decoder.  If ``None``, the default IDNA 2003 encoder/decoder
    is used.

    *allow_directives*, a ``bool`` or an iterable of `str`.  If ``True``, the default,
    then directives are permitted, and the *allow_include* parameter controls whether
    ``$INCLUDE`` is permitted.  If ``False`` or an empty iterable, then no directive
    processing is done and any directive-like text will be treated as a regular owner
    name.  If a non-empty iterable, then only the listed directives (including the
    ``$``) are allowed.

    Raises ``dns.zone.NoSOA`` if there is no SOA RRset.

    Raises ``dns.zone.NoNS`` if there is no NS RRset.

    Raises ``KeyError`` if there is no origin node.

    Returns a subclass of ``dns.zone.Zone``.
    N)r$r%rxryrzr()rpr!r r#r
rrr�rrr�rrr�	from_file�s(
=

� �
r�xfrcCs�d}|D]S}|dur#|r|j}n|jdj}|jdj}||||d�}|jD]0}|j�|j�}	|	s;|��}	|	|j|j<|	�|j|j|j	d�}
|
�
|j�|D]}|
�|�qNq&q|dur`t
d��|rf|��|S)aNConvert the output of a zone transfer generator into a zone object.

    *xfr*, a generator of ``dns.message.Message`` objects, typically
    ``dns.query.xfr()``.

    *relativize*, a ``bool``, determine's whether domain names are
    relativized to the zone's origin.  The default is ``True``.
    It is essential that the relativize setting matches the one specified
    to the generator.

    *check_origin*, a ``bool``.  If ``True``, the default, then sanity
    checks of the origin node will be made by calling the zone's
    ``check_origin()`` method.

    Raises ``dns.zone.NoSOA`` if there is no SOA RRset.

    Raises ``dns.zone.NoNS`` if there is no NS RRset.

    Raises ``KeyError`` if there is no origin node.

    Raises ``ValueError`` if no messages are yielded by the generator.

    Returns a subclass of ``dns.zone.Zone``.
    NrrTzempty transfer)r!�answerr'r r"rNrQr\rWrX�
update_ttlrmr�r*r�)rr
r#r��z�rr!r rd�znode�zrds�rdrrr�from_xfr>s0
��	r")Erryr�r|r��typingrrrrrrrr	r
�
dns.exceptionr&�
dns.grange�
dns.immutable�dns.name�dns.node�	dns.rdata�dns.rdataclass�dns.rdataset�
dns.rdatatype�dns.rdtypes.ANY.SOA�dns.rdtypes.ANY.ZONEMD�	dns.rrset�
dns.tokenizer�dns.transaction�dns.ttl�dns.zonefile�
dns.zonetypesrrr
�	exception�DNSExceptionrrrrrrrrr��TransactionManagerrrSr�r�r�r�r�r�r�r�r�r�r%r'r)r�r��	IDNACodecr(rr"rrrr�<module>s�,0	-8?R���������
	�
�
�Z���������
	�
�
�U������