
                            S r SSKJr  SSKJr  SSKrSSKrSSKrSSK	rSSK
rSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJrJr   " S S\R4                  R6                  5      r " S	 S
\R4                  R6                  5      r " S S\R4                  R<                  5      r " S S\R4                  R6                  5      r  " S S\R4                  R6                  5      r! " S S\R4                  R<                  5      r"Sr#Sr$Sr%Sr& " S S\'5      r( " S S\'5      r)    S!S jr* " S S\'5      r+S r,S r-\R\                  R^                  SSSSSS4S jr0  S"S  jr1g)#zDNS Messages    )absolute_import)StringION   )longxrangestring_typesc                       \ rS rSrSrSrg)ShortHeader,   z2The DNS packet passed to from_wire() is too short. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       lib/third_party/dns/message.pyr
   r
   ,   s    <r   r
   c                       \ rS rSrSrSrg)TrailingJunk0   zEThe DNS packet passed to from_wire() has extra junk at the end of it.r   Nr   r   r   r   r   r   0   s    Or   r   c                       \ rS rSrSrSrg)UnknownHeaderField4   zRThe header field name was not recognized when converting from text
into a message.r   Nr   r   r   r   r   r   4   s    r   r   c                       \ rS rSrSrSrg)BadEDNS9   zUAn OPT record occurred somewhere other than the start of
the additional data section.r   Nr   r   r   r   r   r   9       $r   r   c                       \ rS rSrSrSrg)BadTSIG>   zSA TSIG record occurred somewhere other than the end of
the additional data section.r   Nr   r   r   r   r!   r!   >   r   r   r!   c                       \ rS rSrSrSrg)UnknownTSIGKeyC   z(A TSIG with an unknown key was received.r   Nr   r   r   r   r$   r$   C   s    2r   r$         c                   B   \ rS rSrSrSS jrS rS rSS jrS r	S	 r
S
 rS rS r\R                  R                   SSS4S jr\R                  R                   SSS4S jrSS jrSSSSS\R(                  R*                  4S jr  SS jrS S jrS rS rS rS rSrg)!MessageS   zA DNS message.Nc                    Uc$  [         R                  R                  5       U l        OXl        SU l        / U l        / U l        / U l        / U l        SU l	        SU l
        SU l        / U l        SU l        S U l        S U l        [         R                   R"                  U l        SU l        SU l        SU l        SU l        U R                  U l        SU l        SU l        S U l        S U l        SU l        SU l        SU l        0 U l        g )Nr   r   ,  FT) dnsentropy	random_16idflagsquestionanswer	authority
additionaledns	ednsflagspayloadoptionsrequest_payloadkeyringkeynametsigdefault_algorithmkeyalgorithmrequest_mac
other_data
tsig_errorfudgeoriginal_idmacxfrorigintsig_ctxhad_tsigmultifirstindex)selfr1   s     r   __init__Message.__init__V   s    :kk++-DGG
	 HH66
77


r   c                 8    S[        U R                  5      -   S-   $ )Nz<DNS message, ID >)reprr1   rN   s    r   __repr__Message.__repr__v   s    "T$'']2S88r   c                 "    U R                  5       $ N)to_textrT   s    r   __str__Message.__str__y   s    ||~r   c                    [        5       nUR                  SU R                  -  5        UR                  S[        R                  R                  [        R                  R                  U R                  5      5      -  5        [        R                  R                  U R                  U R                  5      nUR                  S[        R                  R                  U5      -  5        UR                  S[        R                  R                  U R                  5      -  5        U R                  S:  a  UR                  SU R                  -  5        U R                  S:w  a;  UR                  S[        R                  R                  U R                  5      -  5        UR                  SU R                  -  5        U R                   H%  nUR                  S	UR                  5       -  5        M'     [        R                  R                  U R                  5      nU(       a  UR                  S
5        OUR                  S5        U R                   H6  nUR                  UR
                  " X40 UD65        UR                  S5        M8     U(       a  UR                  S5        OUR                  S5        U R                    H6  nUR                  UR
                  " X40 UD65        UR                  S5        M8     U(       a  UR                  S5        OUR                  S5        U R"                   H6  nUR                  UR
                  " X40 UD65        UR                  S5        M8     UR                  S5        U R$                   H6  nUR                  UR
                  " X40 UD65        UR                  S5        M8     UR'                  5       SS $ )zConvert the message to text.

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

Returns a ``text``.
zid %d
z
opcode %s
z	rcode %s
z	flags %s
r   zedns %s
z
eflags %s
zpayload %d
z
option %s
z;ZONE
z
;QUESTION

z;PREREQ
z;ANSWER
z;UPDATE
z;AUTHORITY
z;ADDITIONAL
Nr,   )r   writer1   r.   opcoderY   
from_flagsr2   rcoder8   r7   edns_to_textr9   r:   	is_updater3   r4   r5   r6   getvalue)	rN   rH   
relativizekwsrcoptrc   rrsets	            r   rY   Message.to_text|   s    J	
TWW$%	

""3::#8#8#DEF 	GYY!!$**dnn=			 1 1" 556			 1 1$** ==>99>GGL499,-~~"		..t~~>? @GGOdll23<<CGGNS[[]23  JJ((4	GGJGGN#]]EGGEMM&;;<GGEN # GGL!GGL![[EGGEMM&;;<GGEN ! GGL!GGO$^^EGGEMM&;;<GGEN $ 	
 !__EGGEMM&;;<GGEN % zz|CR  r   c                 L   [        U[        5      (       d  gU R                  UR                  :w  a  gU R                  UR                  :w  a  gU R                   H  nX!R                  ;  d  M    g   UR                   H  nX R                  ;  d  M    g   U R
                   H  nX!R
                  ;  d  M    g   UR
                   H  nX R
                  ;  d  M    g   U R                   H  nX!R                  ;  d  M    g   UR                   H  nX R                  ;  d  M    g   g)zTwo messages are equal if they have the same content in the
header, question, answer, and authority sections.

Returns a ``bool``.
FT)
isinstancer)   r1   r2   r3   r4   r5   rN   otherns      r   __eq__Message.__eq__   s     %))77ehh::$A&  A%   A$  A#  A'   A& ! r   c                 .    U R                  U5      (       + $ rX   )rq   )rN   ro   s     r   __ne__Message.__ne__   s    ;;u%%%r   c                    UR                   [        R                   R                  -  S:X  dn  U R                  UR                  :w  dT  [        R                  R                  U R                   5      [        R                  R                  UR                   5      :w  a  g[        R                  R                  UR                   UR                  5      [        R                  R                  :w  a  g[        R                  R                  U R                   5      (       a  gU R                   H  nX!R                  ;  d  M    g   UR                   H  nX R                  ;  d  M    g   g)z<Is this message a response to *other*?

Returns a ``bool``.
r   FT)r2   r.   QRr1   r_   r`   ra   r8   NOERRORrc   r3   rn   s      r   is_responseMessage.is_response   s     ;;%*77ehh::  ,::  -.99U__=		!!"::

++A&  A%   r   c                     XR                   L a  [        $ XR                  L a  [        $ XR                  L a  [
        $ XR                  L a  [        $ [        S5      eaA  Return the "section number" of the specified section for use
in indexing.  The question section is 0, the answer section is 1,
the authority section is 2, and the additional section is 3.

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

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

Returns an ``int``.
zunknown section)	r3   QUESTIONr4   ANSWERr5   	AUTHORITYr6   
ADDITIONAL
ValueError)rN   sections     r   section_numberMessage.section_number   sN     mm#O#M&'.//r   c                     U[         :X  a  U R                  $ U[        :X  a  U R                  $ U[        :X  a  U R
                  $ U[        :X  a  U R                  $ [        S5      er|   )	r}   r3   r~   r4   r   r5   r   r6   r   )rN   numbers     r   section_from_numberMessage.section_from_number  sX     X== v;;y >>!z!??".//r   Fc	                    [        U[        5      (       a  Un	U R                  U	5      nOU R                  U5      n	XX4XV4n
U(       dS  U R                  b!  U R                  R                  U
5      nUb  U$ O%U H  nUR                  X#XEU5      (       d  M  Us  $    U(       d  [        e[        R                  R                  X#XEU5      nUR                  U5        U R                  b  XR                  U
'   U$ )a  Find the RRset with the given attributes in the specified section.

*section*, an ``int`` section number, 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)

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

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

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

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

*deleting*, an ``int`` 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.

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

Returns a ``dns.rrset.RRset object``.
)rm   intr   r   rM   getmatchKeyErrorr.   rj   RRsetappend)rN   r   namerdclassrdtypecoversdeletingcreateforce_uniquer   keyrj   s               r   
find_rrsetMessage.find_rrset  s    L gs##$N..~>G!009NWfGzz%

s+$ L % %E{{4&(KK$ % N		vxHu::!#JJsOr   c	           
      X     U R                  XX4UXgU5      n	U	$ ! [         a    Sn	 U	$ f = f)a  Get the RRset with the given attributes in the specified section.

If the RRset is not found, None is returned.

*section*, an ``int`` section number, 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)

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

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

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

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

*deleting*, an ``int`` 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.

Returns a ``dns.rrset.RRset object`` or ``None``.
N)r   r   )
rN   r   r   r   r   r   r   r   r   rj   s
             r   	get_rrsetMessage.get_rrset\  sD    J	OOG7F$,lDE   	E	s    ))r   c           
         US:X  a  U R                   S:w  a  U R                   nOSnUS:  a  SnOUS:  a  Sn[        R                  R                  U R                  U R
                  X!5      nU R                   H4  nUR                  UR                  UR                  UR                  5        M6     U R                   H/  nUR                  " [        R                  R                  U40 UD6  M1     U R                   H/  nUR                  " [        R                  R                  U40 UD6  M1     U R                   S:  a<  UR#                  U R                   U R$                  U R&                  U R(                  5        U R*                   H/  nUR                  " [        R                  R,                  U40 UD6  M1     UR/                  5         U R0                  b  UR3                  U R0                  U R4                  U R0                     U R6                  U R8                  U R:                  U R<                  U R>                  U R@                  5        URB                  U l!        URE                  5       $ )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.

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

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

Returns a ``binary``.
r   i  i   )#r;   r.   rendererRendererr1   r2   r3   add_questionr   r   r   r4   	add_rrsetr~   r5   r   r7   add_ednsr8   r9   r:   r6   r   write_headerr=   add_tsigr<   rD   rE   rC   rB   rA   r@   rF   get_wire)rN   rH   max_sizerf   rrj   s         r   to_wireMessage.to_wire  s   & q=##q(// c>HHLL!!$''4::xH]]ENN5::u||U]]C #[[EKK++U9b9 !^^EKK..<< $99>JJtyy$..$,,M__EKK//="= %	<<#JJt||T\\$,,%?zz4#3#3T__(8(8((* uuDHzz|r   r-   r   c                 H   Xl         Uc,  [        U R                   R                  5       5      S   U l        O:[	        U[
        5      (       a  [        R                  R                  U5      nX l        Xpl	        X0l
        Uc  U R                  U l        OX@l        XPl        X`l        g)a  When sending, a TSIG signature using the specified keyring
and keyname should be added.

See the documentation of the Message class for a complete
description of the keyring dictionary.

*keyring*, a ``dict``, the TSIG keyring to use.  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.

*keyname*, a ``dns.name.Name`` or ``None``, the name of the TSIG key
to use; defaults to ``None``. The key must be defined in the keyring.

*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 ``binary``, the TSIG other data.

*algorithm*, a ``dns.name.Name``, the TSIG algorithm to use.
Nr   )r<   listkeysr=   rm   r   r.   r   	from_textr@   rD   r1   rE   rC   rB   )rN   r<   r=   rD   rE   rC   rB   	algorithms           r   use_tsigMessage.use_tsig  s    > ? 1 1 34Q7DL'<00((,,W5"L%
#wwD*$$r   c                     Ub  USL a  SnUSL a  SnUc  UnUS:  a	  SnSnSn/ nOU[        S5      -  nX!S-  -  nUc  / nXl        X l        X0l        XPl        X@l        g)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.
NFr,   Tr   l   ~    )r   r7   r8   r9   r:   r;   )rN   r7   r8   r9   r;   r:   s         r   use_ednsMessage.use_edns  s    . <45=D4<D"%O!8IGOG j))I"*%I	".r   c                 ,   U(       aN  U R                   S:  a  U R                  5         U =R                  [        R                  R
                  -  sl        gU R                   S:  a/  U =R                  [        R                  R
                  ) -  sl        gg)zEnable 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.
r   N)r7   r   r8   r.   r2   DO)rN   wanteds     r   want_dnssecMessage.want_dnssec  sY     yy1}NNciill*NYY!^NNsyy||m+N r   c                 j    [         R                  R                  U R                  U R                  5      $ )z'Return the rcode.

Returns an ``int``.
)r.   ra   r`   r2   r8   rT   s    r   ra   Message.rcode%  s#    
 yy##DJJ??r   c                 R   [         R                  R                  U5      u  p#U =R                  S-  sl        U =R                  U-  sl        U =R                  [        S5      -  sl        U =R                  U-  sl        U R                  S:w  a  U R                  S:  a  SU l        ggg)z:Set the rcode.

*rcode*, an ``int``, is the rcode to set.
i  i r   N)r.   ra   to_flagsr2   r8   r   r7   )rN   ra   valueevalues       r   	set_rcodeMessage.set_rcode,  s|    
 )),,U3

f


e
$z**& >>Q499q=DI $1r   c                 T    [         R                  R                  U R                  5      $ )z(Return the opcode.

Returns an ``int``.
)r.   r_   r`   r2   rT   s    r   r_   Message.opcode9  s    
 zz$$TZZ00r   c                     U =R                   S-  sl         U =R                   [        R                  R                  U5      -  sl         g)z=Set the opcode.

*opcode*, an ``int``, is the opcode to set.
i  N)r2   r.   r_   r   )rN   r_   s     r   
set_opcodeMessage.set_opcode@  s/    
 	

f


cjj))&11
r   )r6   r4   r5   r7   r8   rL   r2   rD   rJ   r1   rM   r@   r=   r<   rF   rK   r:   rH   rE   rB   r9   r3   rA   r;   rI   rC   rG   rX   )NT)Nr   )r   r   i   NN)T)r   r   r   r   r   rO   rU   rZ   rY   rq   rt   ry   r   r   r.   	rdatatypeNONEr   r   r   r>   r?   r   r   r   ra   r   r_   r   r   r   r   r   r)   r)   S   s    @97!rB&00.00 --,,tE %;| ++d5$*X.` )-C!aC8855-%^ KO,/\, @12r   r)   c                   8    \ rS rSrSr  S	S jrS rS rS rSr	g)
_WireReaderiI  a  Wire format reader.

wire: a binary, is the wire-format message.
message: The message object being built
current: When building a message object from wire format, this
variable contains the offset from the beginning of wire of the next octet
to be read.
updating: Is the message a dynamic update?
one_rr_per_rrset: Put each RR into its own RRset?
ignore_trailing: Ignore trailing junk at end of request?
zone_rdclass: The class of the zone in messages which are
DNS dynamic updates.
c                     [         R                  R                  U5      U l        X l        SU l        SU l        [         R                  R                  U l	        X0l
        X@l        XPl        g )Nr   F)r.   wiredata
maybe_wrapwiremessagecurrentupdating
rdataclassINzone_rdclassquestion_onlyone_rr_per_rrsetignore_trailing)rN   r   r   r   r   r   s         r   rO   _WireReader.__init__Y  sO    LL++D1	NN--* 0.r   c           
         U R                   (       a   US:  a  [        R                  R                  e[	        SU5       GH&  n[        R
                  R                  U R                  U R                  5      u  p4U R                  R                  b%  UR                  U R                  R                  5      nU R                  U-   U l        [        R                  " SU R                  U R                  U R                  S-    5      u  pVU R                  S-   U l        U R                  R                  U R                  R                  UXeSSS9  U R                   (       d  GM   X`l        GM)     g)zXRead the next *qcount* records from the wire data and add them to
the question section.
r   r   N!HH   Tr   r   )r   r.   	exception	FormErrorr   r   	from_wirer   r   r   rH   re   structunpackr   r3   r   )rN   qcountiqnameusedr   r   s          r   _get_question_WireReader._get_questiond  s   
 ==VaZ--)))6"AHH..tyy$,,GMU||"".(()<)<=<<$.DLe"iiT\\A5EFH V  <<!+DLLL##DLL$9$95$+D15 $ 7 }}}$+! #r   c                    U R                   (       d  U R                  (       a  SnOSnSn[        SU5       GH  nU R                  n[        R
                  R                  U R                  U R                  5      u  pxUn	U R                  R                  b%  UR                  U R                  R                  5      nU R                  U-   U l        [        R                  " SU R                  U R                  U R                  S-    5      u  ppU R                  S-   U l        U
[        R                  R                  :X  Ga  XR                  R                  Ld  U(       a  [         eXR                  l        XR                  l        US-  S-	  U R                  l        / U R                  l        U R                  nUnUS:  a  [        R                  " S	U R                  XS
-    5      u  nnUS
-   n[        R&                  R+                  UU R                  UU5      nU R                  R(                  R-                  U5        UU-   nUS
-
  U-
  nUS:  a  M  SnGOpU
[        R                  R.                  :X  Ga  XR                  R                  L a  XRS-
  :X  d  [0        eU R                  R2                  c  [5        S5      eU R                  R2                  R7                  U	5      nUc  [5        SU-  5      eXR                  l        [        R:                  R=                  U R                  U R                  U5      u  U R                  l        U R                  l         [        R:                  RC                  U R                  U	U[E        [F        RF                  " 5       5      U R                  RH                  UU R                  UU R                  RJ                  U R                  RL                  U R                  RN                  5      U R                  l%        SU R                  l(        GOUS:  a  SnU R                   (       aK  U[        RR                  RT                  :X  d  U[        RR                  RV                  :X  a  UnU RX                  nOSnU[        RR                  RT                  :X  d6  U[        RR                  RV                  :X  a5  XR                  RZ                  L a  [        R                  RV                  nSnO[[        R\                  R                  XU R                  U R                  UU R                  R                  5      nUR_                  5       nU R                  R`                  (       a   U
[        R                  Rb                  :X  a  SnU R                  Re                  XXUUSU5      nUb  URg                  UU5        U R                  U-   U l        GM     g)zRead the next I{count} records from the wire data and add them to
the specified section.

section: the section of the message to which to add records
count: the number of records to read
TFr   Nz!HHIH
   i   r   r   r   r   z"got signed message without keyringzkey '%s' unknown)4r   r   r   r   r.   r   r   r   r   rH   re   r   r   r   OPTr6   r   r9   r8   r7   r:   option_from_wirer   TSIGr!   r<   r$   r   r=   r>   get_algorithm_and_macr@   rF   validater   timerA   rI   rK   rL   rJ   r   ANYr   r   r4   rdatar   rG   SOAr   add)rN   r   countr   seen_optr   rr_startr   r   absolute_namer   r   ttlrdlenr   optslenotypeolenri   secretr   r   rdrj   s                           r   _get_section_WireReader._get_section{  sl    ==D11L L5!A||H88--diiFLT M||"".t||':':;<<$.DLg"iiT\\B5FGI *Vc  <<",DL***,,"9"99X!M'.$),&%(8^$:!')$,,ke&*ii!&DF "UD &kG((33tyy'49CLL((//4%nG%kD0G k  3==---<<#:#::ai(!M<<''/()MNN--11-@>();d)BCC'4$HH22499dll38: >*DLL,< HH%%dii&3&,&)$))+&6&*ll&>&>&.&*ll&+&*ll&;&;&*ll&8&8&*ll&8&8
: % )-%7C==s~~1113>>#6#66&H"//G#Hs~~111 3 33<<#6#66 ]]//FB,,Wdii-1\\5-1\\-@-@BB  YY[F<<###--2C2C(C#'L//0708$N >IIb#&<<%/DLi "r   c                    [        U R                  5      nUS:  a  [        e[        R                  " SU R                  SS 5      u  U R
                  l        U R
                  l        p#pESU l        [        R                  R                  U R
                  R                  5      (       a  SU l        U R                  U5        U R                  (       a  gU R                  U R
                  R                   U5        U R                  U R
                  R"                  U5        U R                  U R
                  R$                  U5        U R&                  (       d  U R                  U:w  a  [(        eU R
                  R*                  (       ah  U R
                  R,                  (       aL  U R
                  R.                  (       d0  U R
                  R,                  R1                  U R                  5        gggg)zFRead a wire format DNS message and build a dns.message.Message
object.   z!HHHHHHNT)lenr   r
   r   r   r   r1   r2   r   r.   r_   rc   r   r   r   r   r4   r5   r6   r   r   rK   rI   rJ   update)rN   lr   ancountaucountadcounts         r   read_WireReader.read  sO    		Nr6#]]9diinE	$,,,f	:: 2 233 DM6"$,,--w7$,,00':$,,117;##(9<<$,,"7"7LL))LL!!((3 * #8r   )r   r   r   r   r   r   r   r   N)FFF)
r   r   r   r   r   rO   r   r   r	  r   r   r   r   r   r   I  s%     5:9>	/,.a0F4r   r   Fc                     [        SS9nXl        X+l        X;l        XKl        X[l        Xkl        X{l        [        XXU
5      nUR                  5         U$ )a  Convert a DNS wire format message into a message
object.

*keyring*, a ``dict``, the keyring to use if the message is signed.

*request_mac*, a ``binary``.  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.

*tsig_ctx*, a ``hmac.HMAC`` objext, the ongoing TSIG context, used
when validating zone transfers.

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

*first*, a ``bool``, should be set to ``True`` if this message is
stand-alone, or the first message in a multi-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.

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

Raises ``dns.messaage.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.

Returns a ``dns.message.Message``.
r   )r1   )
r)   r<   rA   rG   rH   rI   rK   rL   r   r	  )r   r<   rA   rG   rH   rI   rK   rL   r   r   r   mreaders                r   r   r     sP    j 	1AIMEHJGG-(*F
KKMHr   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
_TextReaderi<  a  Text format reader.

tok: the tokenizer.
message: The message object being built.
updating: Is the message a dynamic update?
zone_rdclass: The class of the zone in messages which are
DNS dynamic updates.
last_name: The most recently read name when building a message object.
c                     X l         [        R                  R                  U5      U l        S U l        [        R                  R                  U l        SU l	        g )NF)
r   r.   	tokenizer	Tokenizertok	last_namer   r   r   r   )rN   textr   s      r   rO   _TextReader.__init__H  s=    ==**40NN--r   c                    U R                   R                  5       nUR                  nUS:X  a+  U R                   R                  5       U R                  l        GO`US:X  a   U R                   R                  5       nUR                  5       (       d  U R                   R                  U5        OQU R                  R                  [        R                  R                  UR                  5      -  U R                  l        M  [        R                  R                  U R                  R                  5      (       a  SU l        GO|US:X  aj  U R                   R                  5       U R                  l        U R                  R                  U R                  R                  S-  -  U R                  l        GOUS:X  a  U R                  R                  S:  a  SU R                  l         U R                   R                  5       nUR                  5       (       d  U R                   R                  U5        GOU R                  R                  [        R                  R!                  UR                  5      -  U R                  l        M  US:X  aU  U R                   R                  5       U R                  l        U R                  R                  S:  a  SU R                  l        OUS	:X  a}  U R                   R%                  5       nU R                  R                  [        R                  R'                  [        R                  R                  U5      5      -  U R                  l        O_US
:X  aS  U R                   R%                  5       nU R                  R)                  [        R*                  R                  U5      5        O[,        eU R                   R/                  5         g)z5Process one line from the text format header section.r1   r2   Tr7   r   eflagsr   r9   r_   ra   N)r  r   r   get_intr   r1   is_identifierungetr2   r.   r   r_   rc   r   r7   r8   edns_from_textr9   
get_stringr   r   ra   r   get_eol)rN   r   tokenwhatr  s        r   _header_line_TextReader._header_lineO  s    {{4<"hh..0DLLOW_**,,HHNN5)%)\\%7%7II''4&5"  zz##DLL$6$677 $V^ $ 0 0 2DLL%)\\%;%;""b(&*DLL"X||  1$$%!**,,HHNN5))-)?)?II,,U[[9*:&  Y#'88#3#3#5DLL ||  1$$%!X88&&(D!%!3!3

##CJJ$8$8$>?"@DLLW_88&&(DLL""399#6#6t#<=$$r   c           	      (   U R                   R                  SS9nUR                  5       (       d/  [        R                  R                  UR                  S5      U l        U R                  nU R                   R                  5       nUR                  5       (       d  [        R                  R                  e [        R                  R                  UR                  5      nU R                   R                  5       nUR                  5       (       d  [        R                  R                  e [        R                  R                  UR                  5      nU R                  R!                  U R                  R"                  UXESSS9  U R$                  (       a  X@l        U R                   R)                  5         g! [        R                  R                   a    [        R                  R                  e[         a    [        R                  R                  n Nf = f)z7Process one line from the text format question section.Twant_leadingNr   )r  r   is_whitespacer.   r   r   r   r  r  r   SyntaxErrorr   	Exceptionr   r   r   r   r3   r   r   r  )rN   r   r  r   r   r   s         r   _question_line_TextReader._question_line}  sr    $/""$$ XX//TBDN~~""$$--+++	(nn..u{{;GHHLLNE&&((mm/// ) ((5 5 5t '-1 	  	3 == ' }}(( 	,--+++ 	(nn''G	(s   4A2F3 3AHHc           
         SnU R                   R                  SS9nUR                  5       (       d/  [        R                  R                  UR                  S5      U l        U R                  nU R                   R                  5       nUR                  5       (       d  [        R                  R                  e [        UR                  S5      nU R                   R                  5       nUR                  5       (       d  [        R                  R                  e  [        R                  R                  UR                  5      nU R                   R                  5       nUR                  5       (       d  [        R                  R                  eU[        R                  R                  :X  d  U[        R                  R                  :X  a  UnU R                   n[        R$                  R                  UR                  5      nU R                   R                  5       nUR'                  5       (       dW  U R                   R)                  U5        [        R*                  R                  XgU R                   S5      nUR-                  5       n	OSn[        R$                  R                  n	U R.                  R1                  XXgU	USU R2                  5      n
Ub  U
R5                  X5        gg! [        R                  R                   a    [        R                  R                  e[         a    Sn GNf = f! [        R                  R                   a    [        R                  R                  e[         a    [        R                  R"                  n GNf = f)zVProcess one line from the text format answer, authority, or
additional data sections.
NTr$  r   )r  r   r&  r.   r   r   r   r  r  r   r'  r   r(  r   r   r   r   r   r   is_eol_or_eofr  r   r   r   r   r   r   )rN   r   r   r  r   r   r   r   r   r   rj   s              r   _rr_line_TextReader._rr_line  s   
 $/""$$ XX//TBDN~~""$$--+++	ekk1%CHHLLNE&&((mm/// )	(nn..u{{;GHHLLNE&&((mm///#..,,,3>>;N;N0N"++ ((5""$$HHNN5!$$WdhhEBYY[FB]]''F''(/(0$G >IIb = }}(( 	,--+++ 	C	 }}(( 	,--+++ 	(nn''G	(s(   6AK B<L( AL%$L%(ANNc                    U R                   nSn U R                  R                  SS5      nUR                  5       (       a  gUR	                  5       (       a  UR
                  R                  5       nUS:X  a  U R                   nOUS:X  d  US:X  a#  U R                  nU R                  R                  nOUS:X  d  US:X  a#  U R                  nU R                  R                  nOWUS:X  d  US	:X  a#  U R                  nU R                  R                  nO(US
:X  a"  U R                  nU R                  R                  nU R                  R                  5         GMG  U R                  R                  U5        U" U5        GMl  )zFRead a text format DNS message and build a dns.message.Message
object.NTHEADERr}   ZONEr~   PREREQr   UPDATEr   )r!  r  r   r,  
is_commentr   upperr)  r   r3   r-  r4   r5   r6   r  r  )rN   line_methodr   r  us        r   r	  _TextReader.read  s2    ''HHLLt,E""$$!!KK%%'="&"3"3K*_V"&"5"5K"ll33G(]a8m"&--K"ll11G+%h"&--K"ll44G,&"&--K"ll55G  "HHNN5! / r   )r  r   r  r   r   N)r   r   r   r   r   rO   r!  r)  r-  r	  r   r   r   r   r  r  <  s"    ,\:3j!r   r  c                 P    [        5       n[        X5      nUR                  5         U$ )a  Convert the text format message into a message object.

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

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``
)r)   r  r	  )r  r  r  s      r   r   r     s#      		A!F
KKMHr   c                     [         nSn[        X5      (       a  [        X5      n SnOSn [        U 5      nU(       a  U R	                  5         U$ ! U(       a  U R	                  5         f f = f)aK  Read the next text format message from the specified file.

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

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``
rUTF)r   rm   openr   close)fstr_typeopts
want_closer  s        r   	from_filerB    s`     HD!M

aLGGIH GGI s   A A(c	           	         [        U [        5      (       a  [        R                  R	                  U 5      n [        U[        5      (       a  [        R
                  R	                  U5      n[        U[        5      (       a  [        R                  R	                  U5      n[        5       n	U	=R                  [        R                  R                  -  sl        U	R                  U	R                  XUSSS9  0 n
Ub	  XZS'   Uc  SnUb	  XjS'   Uc  SnUb	  XzS'   Uc  SnUb	  XS'   Uc  SnX:S'   U	R                  " S	0 U
D6  U	R                  U5        U	$ )
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 ``text``, the query name.

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

*rdclass*, an ``int`` or ``text``,  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 (no EDNS).
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.

Returns a ``dns.message.Message``
Tr   r8   r   r9   r;   r:   r7   r   )rm   r   r.   r   r   r   r   r)   r2   RDr   r3   r   r   )r   r   r   r   r   r8   r9   r;   r:   r  kwargss              r   
make_queryrF  %  s8   R %&&""5)&,''((0'<((..**73	AGGsyy||GLLUVD"  $
 F'{H#yH"$3 !H#yH6NJJMM+Hr   c           	      ^   U R                   [        R                   R                  -  (       a  [        R                  R	                  S5      e[        R
                  R                  U R                  5      n[        R                   R                  U R                   [        R                   R                  -  -  Ul         U(       a-  U=R                   [        R                   R                  -  sl         UR                  U R                  5       5        [        U R                  5      Ul        U R                  S:  a  UR                  SSX R                   5        U R"                  (       aF  UR%                  U R&                  U R(                  USSSU R*                  5        U R,                  Ul        U$ )as  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.

Returns a ``dns.message.Message`` object.
z&specified query message is not a queryr   Nr   )r2   r.   rw   r   r   r   r)   r1   rD  RAr   r_   r   r3   r7   r   r9   rJ   r   r<   r=   r@   rF   rA   )queryrecursion_availableour_payloadrD   responses        r   make_responserM  r  s   . {{SYY\\!mm%%&NOO{{""588,HYY\\U[[399<<%?@HN#)),,&'U^^,HzzQ!Q]];~~%--tQ,,	.$yyOr   )
Nr   FNNFTFFF)Fi    r-   )2r   
__future__r   ior   r   r   dns.ednsr.   dns.exception	dns.flagsdns.name
dns.opcodedns.entropy	dns.rcode	dns.rdatadns.rdataclassdns.rdatatype	dns.rrsetdns.rendererdns.tsigdns.wiredata_compatr   r   r   r   r   r
   r   DNSExceptionr   r   r!   r$   r}   r~   r   r   objectr)   r   r   r  r   rB  r   r   rF  rM  r   r   r   <module>ra     si  $  &                  / /=#--)) =P3==** P33 
$cmm%% $
$cmm%% $
3S]]// 3
  
 	 
s2f s2lk4& k4\ FJ0449#BJp!& p!f0< '*nn&7&7$ D$#TJZ AE%r   