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__/message.cpython-310.pyc
o

!we���@sjdZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
ddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZGdd�dejj�Z Gdd�dejj�Z!Gdd	�d	ejj"�Z#Gd
d�dejj�Z$Gdd
�d
ejj�Z%Gdd�dejj"�Z&Gdd�dejj"�Z'Gdd�dejj"�Z(Gdd�dejj"�Z)Gdd�dejj"�Z*Gdd�dejj+�Z,Gdd�dej-j.�Z/Gdd�d�Z0dZ1dZ2e	e3ej4j5ej6j7ej8j9eej8j9eej6j7fZ:ee:ej;j<fZ=e
e3e>eej;j<fZ?Gd d!�d!�Z@Gd"d#�d#�ZAGd$d%�d%e@�ZBd&d'�ZCd(d)�ZDGd*d+�d+�ZE		,	-			-	-	-	-	-	-d`d.eFd/eed0eeFd1eGd2eej4j5d3ee
ejHjIejHjJfd4eGd5eGd6eGd7eGd8eGd9eGd:e@fd;d<�ZKGd=d>�d>�ZL		-		?	dad@e>dAeej4jMd6eGd2eej4j5dBeGdCeej4j5d:e@fdDdE�ZN		-dbdFedAeej4jMd6eGd:e@fdGdH�ZOej6jPdd-ddddddejQjRdfdIe
ej4j5e>fdJe
ej8j9e>fdKe
ej6j7e>fdLee
e3eGfdMeGdNee3dOee3dPee3dQeeejSjTdAeej4jMdRee3dSe3dTe3d:eBfdUdV�ZU	-	W	X	dcdYe@dZeGd[e3d\e3d]e3d:e@fd^d_�ZVe/jWZWe/jXZXe/jYZYe/jZZZdS)dzDNS Messages�N)�Any�Dict�List�Optional�Tuple�Unionc@�eZdZdZdS)�ShortHeaderz2The DNS packet passed to from_wire() is too short.N��__name__�
__module__�__qualname__�__doc__�rr�D/home/arjun/projects/env/lib/python3.10/site-packages/dns/message.pyr	-�r	c@r)�TrailingJunkzEThe DNS packet passed to from_wire() has extra junk at the end of it.Nr
rrrrr1rrc@r)�UnknownHeaderFieldzVThe header field name was not recognized when converting from text
    into a message.Nr
rrrrr5rrc@r)�BadEDNSzLAn OPT record occurred somewhere other than
    the additional data section.Nr
rrrrr:rrc@r)�BadTSIGzWA TSIG record occurred somewhere other than the end of
    the additional data section.Nr
rrrrr?rrc@r)�UnknownTSIGKeyz(A TSIG with an unknown key was received.Nr
rrrrrDrrcs.eZdZdZdhZ�fdd�Zdd�Z�ZS)�	TruncatedzThe truncated flag is set.�messagecst�j|i|��dS�N)�super�__init__)�self�args�kwargs��	__class__rrrOszTruncated.__init__cC�
|jdS)zbAs much of the message as could be processed.

        Returns a ``dns.message.Message``.
        r)r�rrrrrRs
zTruncated.message)rrr
r�supp_kwargsrr�
__classcell__rrrrrHs
rc@r)�NotQueryResponsez%Message is not a response to a query.Nr
rrrrr%Zrr%c@r)�ChainTooLongzThe CNAME chain is too long.Nr
rrrrr&^rr&c@r)�AnswerForNXDOMAINz.The rcode is NXDOMAIN but an answer was found.Nr
rrrrr'brr'c@r)�NoPreviousNamezNo previous name was known.Nr
rrrrr(frr(c@s,eZdZdZdZdZdZdZedd��Z	dS)	�MessageSectionzMessage sectionsr���cCsdS�Nr,r)�clsrrr�_maximumr�zMessageSection._maximumN)
rrr
r�QUESTION�ANSWER�	AUTHORITY�
ADDITIONAL�classmethodr/rrrrr)jsr)c@seZdZdedefdd�ZdS)�MessageError�	exception�offsetcCs||_||_dSr)r7r8)rr7r8rrrrxs
zMessageError.__init__N)rrr
�	Exception�intrrrrrr6wsr6i��c@s�eZdZdZeZd~deefdd�Ze	de
ejj
fdd��Zejd	d��Ze	de
ejj
fd
d��Zejdd��Ze	de
ejj
fd
d��Zejdd��Ze	de
ejj
fdd��Zejdd��Zdd�Zdd�Z		ddeejjdedeeefdefdd�Zdd�Zdd �Zd!ddefd"d#�Zd$e
ejj
defd%d&�Zd'ede
ejj
fd(d)�Z ej!j"dd*d*dfd$e#d+ejjd,ej$j%d-ej!j&d.ej!j&d/eej$j%d0ed1ed2eejj'dejj
fd3d4�Z(ej!j"dd*d*dfd$e#d+ejjd,ej$j%d-ej!j&d.ej!j&d/eej$j%d0ed1ed2eejj'deejj
fd5d6�Z)defd7d8�Z*defd9d:�Z+		;	*	d�deejjd<ed=ed>eedeeefde,fd?d@�Z-e.dAdB��Z/ddCdd;dDej0j1fdEedFee2ejjefdGedHeedIedJe,dKe2ejjefddfdLdM�Z3e	deejjfdNdO��Z4e	deejjfdPdQ��Z5e	dee,fdRdS��Z6e	deefdTdU��Z7e	defdVdW��Z8e.d;e9dfdXdY��Z:d;d;e9ddd;fdZee2eefd[ed\ed]eed^ee
ej;j<d_eddfd`da�Z=e	defdbdc��Z;e	defddde��Z>e>jdfde��Z>e	defdgdh��Z?e	de@fdidj��ZAd�dkeddfdldm�ZBdejCjDfdndo�ZCdpejCjDddfdqdr�ZEdejFjGfdsdt�ZFduejFjGddfdvdw�ZHdxdy�ZIdzd{�ZJd|d}�ZKdS)��MessagezA DNS message.N�idcCs||durtj��|_n||_d|_ggggg|_d|_d|_d|_d|_	d|_
d|_d|_d|_
d|_i|_g|_d|_dS)Nr�Fg)�dns�entropy�	random_16r=�flags�sections�opt�request_payload�pad�keyring�tsig�request_mac�xfr�origin�tsig_ctx�index�errors�time)rr=rrrr�s"
zMessage.__init__�returncCr!)zThe question section.r�rCr"rrr�question��
zMessage.questioncC�||jd<dS�NrrQ�r�vrrrrR��cCr!)zThe answer section.r*rQr"rrr�answer�rSzMessage.answercCrT)Nr*rQrVrrrrY�rXcCr!)zThe authority section.r+rQr"rrr�	authority�rSzMessage.authoritycCrT)Nr+rQrVrrrrZ�rXcCr!)zThe additional data section.r,rQr"rrr�
additional�rSzMessage.additionalcCrTr-rQrVrrrr[�rXcCsdt|j�dS)Nz<DNS message, ID �>)�reprr=r"rrr�__repr__�szMessage.__repr__cCs|��Sr)�to_textr"rrr�__str__�szMessage.__str__TrK�
relativize�kwc	Ks:t��}|�d|j�|�dtj�|����|�dtj�|����|�dtj�|j��|j	dkrX|�d|j	�|j
dkrP|�dtj�|j
��|�d|j�|j
D]}|�d	|���q[|jj��D]'\}}|�d
|�d��|�|�D]}|�|j||fi|���|�d�qqm|��dd
�S)z�Convert the message to text.

        The *origin*, *relativize*, and any other keyword
        arguments are passed to the RRset ``to_wire()`` method.

        Returns a ``str``.
        zid %d
z
opcode %s
z	rcode %s
z	flags %s
rzedns %s
z
eflags %s
zpayload %d
z
option %s
�;�
N���)�io�StringIO�writer=r?�opcoder_�rcoderB�edns�	ednsflags�edns_to_text�payload�options�
_section_enum�__members__�items�section_from_number�getvalue)	rrKrarb�srD�name�which�rrsetrrrr_�s&


�zMessage.to_textcCs�t|t�sdS|j|jkrdS|j|jkrdSt|j�D]#\}}|j|}|D]
}||vr1dSq'|D]
}||vr>dSq4qdS)z�Two messages are equal if they have the same content in the
        header, question, answer, and authority sections.

        Returns a ``bool``.
        FT)�
isinstancer<r=rB�	enumeraterC)r�other�i�section�
other_section�nrrr�__eq__�s$

���zMessage.__eq__cCs|�|�Sr)r�)rr{rrr�__ne__�zMessage.__ne__r{cCs�|jtjj@dks|j|jkstj�|j�tj�|j�krdS|��tjjtjjtjj	tjj
hvr:t|j�dkr:dStj�
|j�rCdS|jD]
}||jvrPdSqF|jD]
}||jvr^dSqTdS)zuIs *other*, also a ``dns.message.Message``, a response to this
        message?

        Returns a ``bool``.
        rFT)rBr?�QRr=ri�
from_flagsrj�FORMERR�SERVFAIL�NOTIMP�REFUSED�lenrR�	is_update)rr{rrrr�is_responses.�	

�

�zMessage.is_responser}cCs2t|j�D]\}}||ur|�|�Sqtd��)z�Return the "section number" of the specified section for use
        in indexing.

        *section* is one of the section attributes of this message.

        Raises ``ValueError`` if the section isn't known.

        Returns an ``int``.
        zunknown section)rzrCrp�
ValueError)rr}r|�our_sectionrrr�section_number5s
�zMessage.section_number�numbercCs|j�|�}|j|S)aReturn the section list associated with the specified section
        number.

        *number* is a section number `int` or the text form of a section
        name.

        Raises ``ValueError`` if the section isn't known.

        Returns a ``list``.
        )rp�makerC)rr�r}rrrrsEs
zMessage.section_from_numberFrv�rdclass�rdtype�covers�deleting�create�force_unique�
idna_codecc

Cs8t|t�r
|}
|�|
�}nt|t�rt�|�}
|�|
�}n|�|�}
t|t�r/tjj||	d�}tj	j
�|�}tjj
�|�}tj	j
�|�}|durOtjj
�|�}|
|||||f}|s}|jdurk|j�|�}|durj|Sn|D]}|�|||||�r||Sqm|s�t�tj�|||||�}|�|�|jdur�||j|<|S)a�Find the RRset with the given attributes in the specified section.

        *section*, an ``int`` section number, a ``str`` section name, or one of
        the section attributes of this message.  This specifies the
        the section of the message to search.  For example::

            my_message.find_rrset(my_message.answer, name, rdclass, rdtype)
            my_message.find_rrset(dns.message.ANSWER, name, rdclass, rdtype)
            my_message.find_rrset("ANSWER", name, rdclass, rdtype)

        *name*, a ``dns.name.Name`` or ``str``, the name of the RRset.

        *rdclass*, an ``int`` or ``str``, the class of the RRset.

        *rdtype*, an ``int`` or ``str``, the type of the RRset.

        *covers*, an ``int`` or ``str``, the covers value of the RRset.
        The default is ``dns.rdatatype.NONE``.

        *deleting*, an ``int``, ``str``, or ``None``, the deleting value of the
        RRset.  The default is ``None``.

        *create*, a ``bool``.  If ``True``, create the RRset if it is not found.
        The created RRset is appended to *section*.

        *force_unique*, a ``bool``.  If ``True`` and *create* is also ``True``,
        create a new RRset regardless of whether a matching RRset exists
        already.  The default is ``False``.  This is useful when creating
        DDNS Update messages, as order matters for them.

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

        Raises ``KeyError`` if the RRset was not found and create was
        ``False``.

        Returns a ``dns.rrset.RRset object``.
        �r�N)ryr:rs�strr)�	from_textr�r?rv�	rdatatype�	RdataTyper��
rdataclass�
RdataClassrM�get�
full_match�KeyErrorrx�RRset�append)
rr}rvr�r�r�r�r�r�r�r��keyrxrrr�
find_rrsetTs@
4




��


zMessage.find_rrsetc
Cs:z|�|||||||||	�	}
W|
Styd}
Y|
Sw)ajGet the RRset with the given attributes in the specified section.

        If the RRset is not found, None is returned.

        *section*, an ``int`` section number, a ``str`` section name, or one of
        the section attributes of this message.  This specifies the
        the section of the message to search.  For example::

            my_message.get_rrset(my_message.answer, name, rdclass, rdtype)
            my_message.get_rrset(dns.message.ANSWER, name, rdclass, rdtype)
            my_message.get_rrset("ANSWER", name, rdclass, rdtype)

        *name*, a ``dns.name.Name`` or ``str``, the name of the RRset.

        *rdclass*, an ``int`` or ``str``, the class of the RRset.

        *rdtype*, an ``int`` or ``str``, the type of the RRset.

        *covers*, an ``int`` or ``str``, the covers value of the RRset.
        The default is ``dns.rdatatype.NONE``.

        *deleting*, an ``int``, ``str``, or ``None``, the deleting value of the
        RRset.  The default is ``None``.

        *create*, a ``bool``.  If ``True``, create the RRset if it is not found.
        The created RRset is appended to *section*.

        *force_unique*, a ``bool``.  If ``True`` and *create* is also ``True``,
        create a new RRset regardless of whether a matching RRset exists
        already.  The default is ``False``.  This is useful when creating
        DDNS Update messages, as order matters for them.

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

        Returns a ``dns.rrset.RRset object`` or ``None``.
        N)r�r�)rr}rvr�r�r�r�r�r�r�rxrrr�	get_rrset�s"3�
��zMessage.get_rrsetcCsJ|jsdSd}|jdjD]}|��}|t|�d7}q
|jr#|d7}|S)z:Compute the size required for the OPT RR, padding excludedr��)rDro�to_wirer�rF)r�size�option�wirerrr�_compute_opt_reserve�szMessage._compute_opt_reservecCs*|jsdSt��}|j�|�t|���S)z)Compute the size required for the TSIG RRr)rHrf�BytesIOr�r�rt)r�frrr�_compute_tsig_reserve�s
zMessage._compute_tsig_reserver�max_size�multirLc	Ks�|dur|jdur|j}|dkr|jdkr|j}nd}|dkr"d}n|dkr(d}tj�|j|j||�}|��}|�|�|�	�}|�|�|j
D]}	|�|	j|	j
|	j�qH|jD]}	|jtjj|	fi|��qX|jD]}	|jtjj|	fi|��qj|jD]}	|jtjj|	fi|��q||��|jdur�|�|j|j||�|��|jdur�tj�|��|j|jdtt � ��|j!||�\}
}|j�"�|j�#|
�|�tjj|j�|��|r�||_$|��S)a�Return a string containing the message in DNS compressed wire
        format.

        Additional keyword arguments are passed to the RRset ``to_wire()``
        method.

        *origin*, a ``dns.name.Name`` or ``None``, the origin to be appended
        to any relative names.  If ``None``, and the message has an origin
        attribute that is not ``None``, then it will be used.

        *max_size*, an ``int``, the maximum size of the wire format
        output; default is 0, which means "the message's request
        payload, if nonzero, or 65535".

        *multi*, a ``bool``, should be set to ``True`` if this message is
        part of a multiple message sequence.

        *tsig_ctx*, a ``dns.tsig.HMACTSig`` or ``dns.tsig.GSSTSig`` object, the
        ongoing TSIG context, used when signing zone transfers.

        Raises ``dns.exception.TooBig`` if *max_size* was exceeded.

        Returns a ``bytes``.
        Nri��i)%rKrEr?�renderer�Rendererr=rBr��reserver�rR�add_questionrvr�r�rY�	add_rrsetr2rZr3r[r4�release_reservedrD�add_optrF�write_headerrH�sign�get_wirerGr:rOrI�clear�addrL)rrKr�r�rLrb�r�opt_reserve�tsig_reserverx�new_tsig�ctxrrrr�sX!









�
	zMessage.to_wirec	Cs8tjjj�tjjtjj|||||||�	}tj�|d|�SrU)r?�rdtypes�ANY�TSIGr�r�rx�
from_rdata)	�keyname�	algorithm�time_signed�fudge�mac�original_id�errorr{rHrrr�
_make_tsig[s
�zMessage._make_tsig�,r>rGr�r�r��
tsig_error�
other_datar�c	
Cs�t|tjj�r
|}|j}n0t|�r|||�}n&t|t�r"tj�|�}|dur,tt	|��}||}t|t
�r=tj�|||�}||_|durG|j}|�
||jjd|dtjj|jj|||�|_dS)a�When sending, a TSIG signature using the specified key
        should be added.

        *key*, a ``dns.tsig.Key`` is the key to use.  If a key is specified,
        the *keyring* and *algorithm* fields are not used.

        *keyring*, a ``dict``, ``callable`` or ``dns.tsig.Key``, is either
        the TSIG keyring or key to use.

        The format of a keyring dict is a mapping from TSIG key name, as
        ``dns.name.Name`` to ``dns.tsig.Key`` or a TSIG secret, a ``bytes``.
        If a ``dict`` *keyring* is specified but a *keyname* is not, 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 ``dict`` keyring is used, unless they know the keyring
        contains only one key.  If a ``callable`` keyring is specified, the
        callable will be called with the message and the keyname, and is
        expected to return a key.

        *keyname*, a ``dns.name.Name``, ``str`` or ``None``, the name of
        this TSIG key to use; defaults to ``None``.  If *keyring* is a
        ``dict``, the key must be defined in it.  If *keyring* is a
        ``dns.tsig.Key``, this is ignored.

        *fudge*, an ``int``, the TSIG time fudge.

        *original_id*, an ``int``, the TSIG original id.  If ``None``,
        the message's id is used.

        *tsig_error*, an ``int``, the TSIG error code.

        *other_data*, a ``bytes``, the TSIG other data.

        *algorithm*, a ``dns.name.Name`` or ``str``, the TSIG algorithm to use.  This is
        only used if *keyring* is a ``dict``, and the key entry is a ``bytes``.
        Nr�)ryr?rH�Keyrv�callabler�r��next�iter�bytesrGr=r�r��	mac_sizes)	rrGr�r�r�r�r�r�r�rrr�use_tsigls2/


�zMessage.use_tsigcCs|jr|jjSdSr)rHrvr"rrrr���zMessage.keynamecC�|jr	|jdjSdSrU)rHr�r"rrr�keyalgorithm��zMessage.keyalgorithmcCr�rU)rHr�r"rrrr��r�zMessage.maccCr�rU)rHr�r"rrrr��r�zMessage.tsig_errorcCs
t|j�Sr)�boolrHr"rrr�had_tsig�s
zMessage.had_tsigcCs4tjjj�|tjj|pd�}tj�tjjt	|�|�S)Nr)
r?r�r��OPTr�rxr�rv�rootr:)rBrnrorDrrr�	_make_opt�szMessage._make_optrkrlrnrErorFcCs�|dus|durd}n|durd}|dkrd|_d|_dS|dM}||d>O}|dur-g}|�|||�|_|dur;|}||_||_dS)a'Configure EDNS behavior.

        *edns*, an ``int``, is the EDNS level to use.  Specifying ``None``, ``False``,
        or ``-1`` means "do not use EDNS", and in this case the other parameters are
        ignored.  Specifying ``True`` is equivalent to specifying 0, i.e. "use EDNS0".

        *ednsflags*, an ``int``, the EDNS flag values.

        *payload*, an ``int``, is the EDNS sender's payload field, which is the maximum
        size of UDP datagram the sender can handle.  I.e. how big a response to this
        message can be.

        *request_payload*, an ``int``, is the EDNS payload size to use when sending this
        message.  If not specified, defaults to the value of *payload*.

        *options*, a list of ``dns.edns.Option`` objects or ``None``, the EDNS options.

        *pad*, a non-negative ``int``.  If 0, the default, do not pad; otherwise add
        padding bytes to make the message size a multiple of *pad*.  Note that if
        padding is non-zero, an EDNS PADDING option will always be added to the
        message.
        NFreTrl�~r;)rDrEr�rF)rrkrlrnrErorFrrr�use_edns�s  

zMessage.use_ednscCs|jr
|jd@d?SdS)Ni�r;re)rDrlr"rrrrkszMessage.ednscCs|jr|jjSdSrU)rD�ttlr"rrrrlr�zMessage.ednsflagscCs*|jr	||j_dS|r|�|�|_dSdSr)rDr�r�rVrrrrls
�cCs|jr	|jdjSdSrU)rDrnr"rrrrn#r�zMessage.payloadcCs|jr	|jdjSdS)Nrr)rDror"rrrro*r�zMessage.options�wantedcCs<|r
|jtjjO_dS|jr|jtjjM_dSdS)a!Enable or disable 'DNSSEC desired' flag in requests.

        *wanted*, a ``bool``.  If ``True``, then DNSSEC data is
        desired in the response, EDNS is enabled if required, and then
        the DO bit is set.  If ``False``, the DO bit is cleared if
        EDNS is enabled.
        N)rlr?rB�DOrD)rr�rrr�want_dnssec1s
	�zMessage.want_dnsseccCstj�t|j�t|j��S)zBReturn the rcode.

        Returns a ``dns.rcode.Rcode``.
        )r?rjr�r:rBrlr"rrrrj?sz
Message.rcoderjcCsLtj�|�\}}|jdM_|j|O_|jdM_|j|O_dS)zUSet the rcode.

        *rcode*, a ``dns.rcode.Rcode``, is the rcode to set.
        i�i���N)r?rj�to_flagsrBrl)rrj�value�evaluerrr�	set_rcodeFs
zMessage.set_rcodecCstj�t|j��S)zEReturn the opcode.

        Returns a ``dns.opcode.Opcode``.
        )r?rir�r:rBr"rrrriQszMessage.opcodericCs(|jdM_|jtj�|�O_dS)zZSet the opcode.

        *opcode*, a ``dns.opcode.Opcode``, is the opcode to set.
        i��N)rBr?rir�)rrirrr�
set_opcodeXszMessage.set_opcodecCs|Srr)rr�rrr�_get_one_rr_per_rrset`r0zMessage._get_one_rr_per_rrsetcCs||ddfS�NFr)rr}rvr�r�rrr�_parse_rr_headerfr�zMessage._parse_rr_headercCsl|tjjkr|tjks|js|tjjkrt�n|tjj	kr0|tjks.|tjj
ks.||dkr0t�||ddfS)Nr*F)r?r�r�r)r4rDrvr�rr�r�r)rr}�count�positionrvr�r�rrr�_parse_special_rr_headerks
��
z Message._parse_special_rr_headerr)NT)NrFN)T)Lrrr
rr)rprr:r�propertyrr?rxr�rR�setterrYrZr[r^r`rv�Namer�rr�rr_r�r�r�r�rsr��NONE�SectionTyper�r�r��	IDNACodecr�r�r�r�r�r��staticmethodr�rH�default_algorithmrr�r�r�r�r�r��DEFAULT_EDNS_PAYLOADr�rk�Optionr�rlrnrror�rj�Rcoder�ri�Opcoder�r�r�r�rrrrr<�sr



�
��
�
�&&������
��	�

�
�[������
��	�

�

�C�
����
�
�O
��������	
�J�������
�3
r<c	@s>eZdZdZdejjdeejj	de
deejj	fdd�ZdS)	�ChainingResulta�The result of a call to dns.message.QueryMessage.resolve_chaining().

    The ``answer`` attribute is the answer RRSet, or ``None`` if it doesn't
    exist.

    The ``canonical_name`` attribute is the canonical name after all
    chaining has been applied (this is the same name as ``rrset.name`` in cases
    where rrset is not ``None``).

    The ``minimum_ttl`` attribute is the minimum TTL, i.e. the TTL to
    use if caching the data.  It is the smallest of all the CNAME TTLs
    and either the answer TTL if it exists or the SOA TTL and SOA
    minimum values for negative answers.

    The ``cnames`` attribute is a list of all the CNAME RRSets followed to
    get to the canonical name.
    �canonical_namerY�minimum_ttl�cnamescCs||_||_||_||_dSr)rrYrr)rrrYrrrrrr�s
zChainingResult.__init__N)
rrr
rr?rvr�rrxr�r:rrrrrrr}s�
��
�rc@s,eZdZdefdd�Zdejjfdd�ZdS)�QueryMessagerPcCs�|jtjj@dkrt�t|j�dkrtjj�|jd}|j}tj	j
}d}d}g}|tkr�z|�|j
||j|j�}t||j	�}WnAty�|jtjjkr~z&|�|j
||jtjj�}|�|�t||j	�}|D]}|j}|d7}WYq(ty}YYnwYnw|tkr�t�|��tjjkr�|dur�t�|dur�|}		z|�|j|	|jtjj�}
t||
j	|
dj�}Wnty�z|	��}	Wntjjy�YYnwYnwq�t||||�S)a�Follow the CNAME chain in the response to determine the answer
        RRset.

        Raises ``dns.message.NotQueryResponse`` if the message is not
        a response.

        Raises ``dns.message.ChainTooLong`` if the CNAME chain is too long.

        Raises ``dns.message.AnswerForNXDOMAIN`` if the rcode is NXDOMAIN
        but an answer was found.

        Raises ``dns.exception.FormError`` if the question count is not 1.

        Returns a ChainingResult object.
        rr*N) rBr?r�r%r�rRr7�	FormErrorrvr��MAX_TTL�	MAX_CHAINr�rYr�r��minr�r��CNAMEr��targetr&rj�NXDOMAINr'rZ�SOA�minimum�parent�NoParentr)rrR�qname�min_ttlrYr�r�crrset�rd�auname�srrsetrrr�resolve_chaining�st
��
�������zQueryMessage.resolve_chainingcCs
|��jS)a�Return the canonical name of the first name in the question
        section.

        Raises ``dns.message.NotQueryResponse`` if the message is not
        a response.

        Raises ``dns.message.ChainTooLong`` if the CNAME chain is too long.

        Raises ``dns.message.AnswerForNXDOMAIN`` if the rcode is NXDOMAIN
        but an answer was found.

        Raises ``dns.exception.FormError`` if the question count is not 1.
        )rrr"rrrr�s
zQueryMessage.canonical_nameN)	rrr
rrr?rvr�rrrrrr�sKrcCsddl}dSrU)�
dns.update)r?rrr�_maybe_import_update�srcCs.|tjjkrtS|tjjkrt�tjjStSr)	r?ri�QUERYr�UPDATEr�update�
UpdateMessager<)rirrr�_message_factory_from_opcodesrc@sFeZdZdZ						ddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�_WireReaderaiWire format reader.

    parser: the binary parser
    message: The message object being built
    initialize_message: Callback to set message parsing options
    question_only: Are we only reading the question?
    one_rr_per_rrset: Put each RR into its own RRset?
    keyring: TSIG keyring
    ignore_trailing: Ignore trailing junk at end of request?
    multi: Is this message part of a multi-message sequence?
    DNS dynamic updates.
    continue_on_error: try to extract as much information as possible from
    the message, accumulating MessageErrors in the *errors* attribute instead of
    raising them.
    FNc		CsHtj�|�|_d|_||_||_||_||_||_	||_
||_g|_dSr)
r?r��Parser�parserr�initialize_message�
question_only�one_rr_per_rrset�ignore_trailingrGr��continue_on_errorrN)	rr�r!r"r#r$rGr�r%rrrrs
z_WireReader.__init__c	Cs~|jdusJ�|jj|}t|�D]+}|j�|jj�}|j�d�\}}|j�||||�\}}}}|jj||||ddd�qdS)zhRead the next *qcount* records from the wire data and add them to
        the question section.
        Nz!HHT�r�r�)	rrC�ranger �get_namerK�
get_structr�r�)rr��qcountr}�_rr�r�rrr�
_get_question5s���z_WireReader._get_questioncCs|j�t||jj��dSr)rNr�r6r �current)r�errr�
_add_errorEsz_WireReader._add_errorcCs�|jdusJ�|jj|}|j}t|�D�]Z}|jj}|j��}|jjdur.|�|jj�}n|}|j�	d�\}	}
}}|	t
jjt
jj
fvrT|j�|||||
|	�\}
}	}
}n
|j�|||
|	�\}
}	}
}|jj}z�|rw|dkrpt
jj�d}t
jj}n&|j�|��t
j�|
|	|j|jj�}Wd�n1s�wY|��}|jjr�|	t
jjkr�d}|	t
jjkr�t
j�|||�|j_n�|	t
jj
k�r)|jdur�td��t|jt�r�|j� |�}t|t!�r�t
j"�#|||j$�}nt%|j�r�|�|j|�}n|j}|dur�td|��||j_t
j"�&|jj'|||t(t)�)��|jj*||jj+|j,�	|j_+t
j�|d|�|j_"n|j�-|||
|	||
d|�}|du�rH|dk�rBd}|�.||�Wqt/�yo}z|j0�rd|�1|�|j�2||�n�WYd}~qd}~wwdS)z�Read the next I{count} records from the wire data and add them to
        the specified section.

        section_number: the section of the message to which to add records
        count: the number of records to read
        Nz!HHIHrTz"got signed message without keyringzkey '%s' unknowni���)3rrCr#r'r r-r(rKrar)r?r�r�r�r�r�r7rr��restrict_to�rdata�from_wire_parserr�rJrrxr�rDrGrry�dictr�r�rHr�r�r��validater�r:rOrIrLr�r�r�r9r%r/�seek)rr�r�r}r�r|�rr_start�
absolute_namervr�r�r��rdlenr��empty�rdata_startrr�r�rxr.rrr�_get_sectionHs�
���
��

�

��


�
����z_WireReader._get_sectionc	
CsV|j��dkr	t�|j�d�\}}}}}}ttj�|��}||d�|_tj	�
|�|j_	|�|j�|j�|j
�|_
zS|�tj|�|jrH|jWS|�tj|�|�tj|�|�tj|�|jsi|j��dkrit�|jr�|jjr�|jjs�|jj�|jj�W|jSW|jSW|jSW|jSty�}z|jr�|�|�n�WYd}~|jSd}~ww)zNRead a wire format DNS message and build a dns.message.Message
        object.�z!HHHHHH�r=rN) r �	remainingr	r)rr?rir�rrB�Flagr!r�r#r,r)r1r"r;r2r3r4r$rr�rLr�rr�r9r%r/)	rr=rBr*�ancount�aucount�adcount�factoryr.rrr�read�sL������
���z_WireReader.read)FFFNFF)	rrr
rrr,r/r;rDrrrrr
s
�`rr>Fr�rGrIrJrKrLr�r"r#r$�raise_on_truncationr%rPc	s��durd�����fdd�}t|||||	|||�}
z|
��}Wntjjy=|
jr<|
jjtjj@r<|
r<t|
jd���w|jtjj@rL|
rLt|d��|rR|
j	|_	|S)a�Convert a DNS wire format message into a message object.

    *keyring*, a ``dns.tsig.Key`` or ``dict``, the key or keyring to use if the message
    is signed.

    *request_mac*, a ``bytes`` or ``None``.  If the message is a response to a
    TSIG-signed request, *request_mac* should be set to the MAC of that request.

    *xfr*, a ``bool``, should be set to ``True`` if this message is part of a zone
    transfer.

    *origin*, a ``dns.name.Name`` or ``None``.  If the message is part of a zone
    transfer, *origin* should be the origin name of the zone.  If not ``None``, names
    will be relativized to the origin.

    *tsig_ctx*, a ``dns.tsig.HMACTSig`` or ``dns.tsig.GSSTSig`` object, the ongoing TSIG
    context, used when validating zone transfers.

    *multi*, a ``bool``, should be set to ``True`` if this message is part of a multiple
    message sequence.

    *question_only*, a ``bool``.  If ``True``, read only up to the end of the question
    section.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing junk at end of the
    message.

    *raise_on_truncation*, a ``bool``.  If ``True``, raise an exception if the TC bit is
    set.

    *continue_on_error*, a ``bool``.  If ``True``, try to continue parsing even if
    errors occur.  Erroneous rdata will be ignored.  Errors will be accumulated as a
    list of MessageError objects in the message's ``errors`` attribute.  This option is
    recommended only for DNS analysis tools, or for use in a server as part of an error
    handling path.  The default is ``False``.

    Raises ``dns.message.ShortHeader`` if the message is less than 12 octets long.

    Raises ``dns.message.TrailingJunk`` if there were octets in the message past the end
    of the proper DNS message, and *ignore_trailing* is ``False``.

    Raises ``dns.message.BadEDNS`` if an OPT record was in the wrong section, or
    occurred more than once.

    Raises ``dns.message.BadTSIG`` if a TSIG record was not the last record of the
    additional data section.

    Raises ``dns.message.Truncated`` if the TC flag is set and *raise_on_truncation* is
    ``True``.

    Returns a ``dns.message.Message``.
    Nr>cs�|_�|_�|_�|_dSr)rIrJrKrL�r�rKrIrLrJrrr!s
z%from_wire.<locals>.initialize_messagerF)
rrDr?r7rrrB�TCrrN)r�rGrIrJrKrLr�r"r#r$rEr%r!�reader�mrrGr�	from_wire�s<F�
����
rKc@sJeZdZdZ				ddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�_TextReaderatText format reader.

    tok: the tokenizer.
    message: The message object being built.
    DNS dynamic updates.
    last_name: The most recently read name when building a message object.
    one_rr_per_rrset: Put each RR into its own RRset?
    origin: The origin for relative names
    relativize: relativize names?
    relativize_to: the origin to relativize to.
    FNTcCshd|_tjj||d�|_d|_||_||_||_||_	d|_
d|_d|_t
|_d|_tjj|_d|_dS)Nr�rer)rr?�	tokenizer�	Tokenizer�tok�	last_namer#rKra�
relativize_tor=rkrlr�rnrjrirrB)r�textr�r#rKrarQrrrrGs	

z_TextReader.__init__cCsx|j��}|j}|dkr|j��|_n�|dkr5	|j��}|��s(|j�|�n|jtj�	|j�B|_qn�|dkrI|j��|_
|j|j
d>B|_nl|dkrs|j
dkrUd|_
	|j��}|��sf|j�|�n|jtj�|j�B|_qVnB|dkr�|j��|_
|j
dkr�d|_
n/|d	kr�|j��}tj�	|�|_|jtj�|j�B|_n|d
kr�|j��}tj�	|�|_nt�|j��dS)z5Process one line from the text format header section.r=rBTrkr;�eflagsrrnrirjN)rOr�r��get_intr=�
is_identifier�ungetrBr?r�rkrl�edns_from_textrn�
get_stringrir�rjr�get_eol)rr+�token�whatrRrrr�_header_line_sR

�

�
�

z_TextReader._header_linecCs|jj|}|jjdd�}|��s|j�||jj|j|j�|_	|j	}|dur(t
�|j��}|��s5tj
j�ztj�|j�}|j��}|��sJtj
j�Wntj
jyXtj
j�tydtjj}Ynwtj�|j�}|j�||||�\}}}}|jj||||ddd�|j��dS)z7Process one line from the text format question section.T��want_leadingNr&)rrCrOr��
is_whitespace�as_namerKrarQrPr(rUr?r7�SyntaxErrorr�r�r�r9�INr�r�r�rY)rr�r}rZrvr�r�r+rrr�_question_line�s>�

����z_TextReader._question_linec

Cs|jj|}|jjdd�}|��s|j�||jj|j|j�|_	|j	}|dur(t
�|j��}|��s5tj
j�zt|jd�}|j��}|��sItj
j�Wntj
jyWtj
j�tyad}Ynwztj�|j�}|j��}|��swtj
j�Wntj
jy�tj
j�ty�tjj}Ynwtj�|j�}|j�||||�\}}}}	|j��}|	r�|��s�tj
j�|	s�|��r�tj
j�|��s�|j�|�tj�|||j|jj|j|j�}
|
��}nd}
tjj}|j�||||||d|j�}|
dur�|�|
|�dSdS)zfProcess one line from the text format answer, authority, or
        additional data sections.
        Tr]Nr) rrCrOr�r_r`rKrarQrPr(rUr?r7rar:r�r9r�r�rbr�r��
is_eol_or_eof�
UnexpectedEndrVr1r�r�r�r#r�)
rr�r}rZrvr�r�r�r�r9rr�rxrrr�_rr_line�s��

��
���
�
�
�z_TextReader._rr_linecCs`t|j�}||jd�}|j|_|jdkr|�|j|j|j�|jr'|�	|j�|j
r.|j
|_
|S)Nr=r)rrir=rBrkr�rlrnrjr�rK)rrCrrrr�
_make_message�s

z_TextReader._make_messagecCs�|j}d}	|j�dd�}|��rnW|��r^|j��}|dkr"|j}|jr)|j}n|��}z!|j	�
|�}|jsA||_|�|j�|_|t
jkrJ|j}n|j}Wn	tyWYnw|j��q|j�|�||�q|jsq|��|_|jS)zNRead a text format DNS message and build a dns.message.Message
        object.Nr*T�HEADER)r\rOr�rd�
is_commentr��upperrrgrpr�r�r#r)r1rcrfr9rYrV)r�line_methodr�rZ�urrrrrDsF
�
��
�#
z_TextReader.read)FNTN)
rrr
rrr\rcrfrgrDrrrrrL9s
�)#KrLTrRr�rarQcCst||||||�}|��S)aConvert the text format message into a message object.

    The reader stops after reading the first blank line in the input to
    facilitate reading multiple messages from a single file with
    ``dns.message.from_file()``.

    *text*, a ``str``, the text format message.

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

    *one_rr_per_rrset*, a ``bool``.  If ``True``, then each RR is put
    into its own rrset.  The default is ``False``.

    *origin*, a ``dns.name.Name`` (or ``None``), the
    origin to use for relative names.

    *relativize*, a ``bool``.  If true, name will be relativized.

    *relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use
    when relativizing names.  If not set, the *origin* value will be used.

    Raises ``dns.message.UnknownHeaderField`` if a header is unknown.

    Raises ``dns.exception.SyntaxError`` if the text is badly formed.

    Returns a ``dns.message.Message object``
    )rLrD)rRr�r#rKrarQrIrrrr�0s*�r�r�cCsRt|t�r
t|�}nt�|�}|�}t|||�Wd�S1s"wYJ�)a�Read the next text format message from the specified file.

    Message blocks are separated by a single blank line.

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

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

    *one_rr_per_rrset*, a ``bool``.  If ``True``, then each RR is put
    into its own rrset.  The default is ``False``.

    Raises ``dns.message.UnknownHeaderField`` if a header is unknown.

    Raises ``dns.exception.SyntaxError`` if the text is badly formed.

    Returns a ``dns.message.Message object``
    N)ryr��open�
contextlib�nullcontextr�)r�r�r#�cmrrr�	from_file`s



 �rqrr�r�r�r�rlrnrEror=rBrFc
Cs�t|t�r
tjj||	d�}tjj�|�}tjj	�|�}t
|
d�}
tj�|�|
_|
j
|
j|||ddd�i}|dur=||d<|durE||d<|durM||d<|durU||d	<|r]|dur]d
}||d<||d<|
jd
i|��|
�|�|
S)a�Make a query message.

    The query name, type, and class may all be specified either
    as objects of the appropriate type, or as strings.

    The query will have a randomly chosen query id, and its DNS flags
    will be set to dns.flags.RD.

    qname, a ``dns.name.Name`` or ``str``, the query name.

    *rdtype*, an ``int`` or ``str``, the desired rdata type.

    *rdclass*, an ``int`` or ``str``,  the desired rdata class; the default
    is class IN.

    *use_edns*, an ``int``, ``bool`` or ``None``.  The EDNS level to use; the
    default is ``None``.  If ``None``, EDNS will be enabled only if other
    parameters (*ednsflags*, *payload*, *request_payload*, or *options*) are
    set.
    See the description of dns.message.Message.use_edns() for the possible
    values for use_edns and their meanings.

    *want_dnssec*, a ``bool``.  If ``True``, DNSSEC data is desired.

    *ednsflags*, an ``int``, the EDNS flag values.

    *payload*, an ``int``, is the EDNS sender's payload field, which is the
    maximum size of UDP datagram the sender can handle.  I.e. how big
    a response to this message can be.

    *request_payload*, an ``int``, is the EDNS payload size to use when
    sending this message.  If not specified, defaults to the value of
    *payload*.

    *options*, a list of ``dns.edns.Option`` objects or ``None``, the EDNS
    options.

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

    *id*, an ``int`` or ``None``, the desired query id.  The default is
    ``None``, which generates a random query id.

    *flags*, an ``int``, the desired query flags.  The default is
    ``dns.flags.RD``.

    *pad*, a non-negative ``int``.  If 0, the default, do not pad; otherwise add
    padding bytes to make the message size a multiple of *pad*.  Note that if
    padding is non-zero, an EDNS PADDING option will always be added to the
    message.

    Returns a ``dns.message.QueryMessage``
    r�r=Tr&NrlrnrErorrkrFr)ryr�r?rvr�r�r�r�r�r�rrBr?r�rRr�r�)rr�r�r�r�rlrnrEror�r=rBrFrJrrrr�
make_query�s.
F

rr� r��query�recursion_available�our_payloadr�r�c	Cs�|jtjj@r
tj�d��t|���}||jd�}tjj|jtjj@B|_|r0|jtjj	O_|�
|���t|j�|_|j
dkrK|�dd||j�|jr`|�|j|j|d|d|j�|j|_|S)a`Make a message which is a response for the specified query.
    The message returned is really a response skeleton; it has all
    of the infrastructure required of a response, but none of the
    content.

    The response's question section is a shallow copy of the query's
    question section, so the query's question RRsets should not be
    changed.

    *query*, a ``dns.message.Message``, the query to respond to.

    *recursion_available*, a ``bool``, should RA be set in the response?

    *our_payload*, an ``int``, the payload size to advertise in EDNS
    responses.

    *fudge*, an ``int``, the TSIG time fudge.

    *tsig_error*, an ``int``, the TSIG error.

    Returns a ``dns.message.Message`` object whose specific class is
    appropriate for the query.  For example, if query is a
    ``dns.update.UpdateMessage``, response will be too.
    z&specified query message is not a queryr=rNr>)rBr?r�r7rrrir=�RD�RAr��listrRrkr�rnr�r�rGr�r�r�rI)rtrurvr�r�rC�responserrr�
make_response�s. 
�	r{)Nr>FNNFFFFFF)NFNTNr�)Frsr�r)[rrnrfrO�typingrrrrrr�dns.ednsr?�dns.entropy�dns.enum�
dns.exception�	dns.flags�dns.name�
dns.opcode�	dns.rcode�	dns.rdata�dns.rdataclass�
dns.rdatatype�dns.rdtypes.ANY.OPT�dns.rdtypes.ANY.TSIG�dns.renderer�	dns.rrset�dns.tsig�dns.ttl�dns.wirer7rr	r�DNSExceptionrrrrrr%r&r'rar(�enum�IntEnumr)r6r�rr:rvr�r�r�r�r��IndexKeyTyperxr��	IndexTyper�r�r<rrrrrr�r�rH�HMACTSig�GSSTSigrKrLr�r�rqrbrBrwrkr�rrr{r1r2r3r4rrrr�<module>s� 


��v ]	
A�����
����	�
���
�nz��
��
��
�
�2��
��
�&���������	�

���
�
�d������
�;