
    h                      S 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Jr  SSK	J
r
  SSKJrJrJrJrJr  SSKJrJrJr  SSKJrJr  SS	KJr  SS
KJrJrJrJr  SSK J!r!J"r"J#r#  / SQr$\RJ                  r%S r&S r'S r(S r)Sr*\+" SS5      u  r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=Sr>Sr?Sr@SrASrBSrCSrDSrESrFSrG0 \,S_\-S_\.S _\/S!_\0S"_\1S#_\2S$_\3S%_\4S&_\5S'_\6S(_\7S)_\8S*_\9S+_\:S,_\;S-_\<S._\=S/\>S0\?S1\@S2\AS3\BS4\CS5\DS6\ES7\FS8\GS90ErH\+" S:S;5      u  rIrJrKrLrM\IS<\JS=\KS>\LS?\MS@0rN\
" \HR                  5       \NR                  5       5       V Vs0 s H  u  pX_M	     snn rP\+" SSA5      u  rQrRrSrTSBrU\QSC\RSD\SSE\TSF\USG0rV\VR                  5        V Vs0 s H  u  pX_M	     snn rW\+" SH5      u  rXrYrZSIr[SAr\\+" SJ5      u  r]r^r_r`rarbSKrc\+" SKS5      u  rdrerf " SL SM\5      rgSSNKhJiriJjrjJkrk  SO rlSSP jrmSQ rnSSR jro\SSS j5       rp\SST j5       rpSSU jrpSV rq " SW SX\5      rr " SY SZ\r\g5      rs\" \r5       " S[ S\5      5       rt\" \r5       " S] S^5      5       ru\"\" \r5       " S_ S`5      5       5       rv\" \r5       " Sa Sb\R                  \R                  5      5       ry\" \r5       " Sc Sd\R                  \R                  5      5       rz\" \r5       " Se Sf\R                  5      5       r{\" \s5       " Sg Sh\R                  \R                  5      5       r| " Si Sj\|5      r} " Sk Sl\|5      r~ " Sm Sn\|5      r " So Sp\|5      r " Sq Sr\|5      r " Ss St\|5      r " Su Sv\|5      r " Sw Sx\|5      r " Sy Sz\|5      r\" \s5       " S{ S|\R                  5      5       r\" \s5       " S} S~\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r\" \s5       " S S\R                  \R                  5      5       r " S S\5      r\" \s5       " S S\R                  \R                  5      5       rS rS r    S           SS jjr " S S\R                  5      r " S S\R                  5      r " S S5      r " S S\\GR<                  5      r " S S\\GR@                  5      rgs  snn f s  snn f )zU
DNS protocol implementation.

Future Plans:
    - Get rid of some toplevels, maybe.
    )annotationsN)BytesIO)chain)OptionalSequenceSupportsIntUnionoverload)	Attribute	Interfaceimplementer)deferprotocol)CannotListenError)failurelog	randbytesutil)cmp
comparablenativeString)d
IEncodableIRecordIEncodableRecordAA6AAAAAFSDBCNAMEDNAMEHINFOMAILAMAILBMBMDMFMGMINFOMRMXNAPTRNSNULLOPTPTRRPSOASPFSRVTXTSSHFPTSIGWKSANYCHCSHSINALL_RECORDSAXFRIXFREFORMATENAMEENOTIMPEREFUSEDESERVEREBADVERSIONEBADSIGEBADKEYEBADTIMERecord_A	Record_A6Record_AAAARecord_AFSDBRecord_CNAMERecord_DNAMERecord_HINFO	Record_MB	Record_MD	Record_MF	Record_MGRecord_MINFO	Record_MR	Record_MXRecord_NAPTR	Record_NSRecord_NULL
Record_PTR	Record_RP
Record_SOA
Record_SPF
Record_SRVRecord_SSHFPRecord_TSIG
Record_TXT
Record_WKSUnknownRecordQUERY_CLASSESQUERY_TYPESREV_CLASSES	REV_TYPESEXT_QUERIESCharstrMessageNameQueryRRHeaderSimpleRecordDNSDatagramProtocolDNSMixinDNSProtocolOK
OP_INVERSE	OP_NOTIFYOP_QUERY	OP_STATUS	OP_UPDATEPORTAuthoritativeDomainErrorDNSQueryTimeoutErrorDomainErrorc                    [        U /5      $ )z{
Construct a bytes object representing a single byte with the given
ordinal value.

@type ordinal: L{int}
@rtype: L{bytes}
bytes)ordinals    X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/names/dns.py
_ord2bytesr      s     '    c                    [        U 5      SS $ )z
Represent a mostly textful bytes object in a way suitable for
presentation to an end user.

@param bytes: The bytes to represent.
@rtype: L{str}
   N)reprr}   s    r   
_nicebytesr      s     ;qr?r   c           
         SR                  SR                  U  Vs/ s H  n[        U5      PM     sn5      5      $ s  snf )z
Represent a list of mostly textful bytes objects in a way suitable for
presentation to an end user.

@param list: The list of bytes to represent.
@rtype: L{str}
z[{}], )formatjoinr   )listbs     r   _nicebyteslistr      s2     ==4#@4aJqM4#@ABB#@s   ;c                 \    [         R                  " S[        R                  " SSS95      S   $ )zs
Wrapper around L{twisted.python.randbytes.RandomFactory.secureRandom} to
return 2 random bytes.

@rtype: L{bytes}
H   T)fallbackr   )structunpackr   secureRandom r   r   randomSourcer      s'     ==i44QFGJJr   5   r         !   #   &   '   )   ,   c         r   r,   r%   r&   r   r1   r$   r'   r)   r-   r7   r/   r!   r(   r*   r4   r0   r   r   r3   r+   r   r    r.   r5   r2   TKEYr6         r?   r>   r#   r"   r=         r<   r:   r9   r;   r8               c                  (    \ rS rSrSr\" S5      rSrg)r   i  z(
A single entry in a zone of authority.
z,An indicator of what kind of record this is.r   N)__name__
__module____qualname____firstlineno____doc__r   TYPE__static_attributes__r   r   r   r   r     s     CDDr   r   )ry   rz   r{   c                n    U S;   a  S/$ U R                  S5      nUS   S:w  a  UR                  S5        U$ )a  
Split a domain name into its constituent labels.

@type name: L{bytes}
@param name: A fully qualified domain name (with or without a
    trailing dot).

@return: A L{list} of labels ending with an empty label
    representing the DNS root zone.
@rtype: L{list} of L{bytes}
)r      .r   r   )splitappend)namelabelss     r   _nameToLabelsr   +  s>     {uZZFbzScMr   c           
         [        U [        5      (       a  U R                  S5      n [        U [        5      (       dB  [	        SR                  [        R                  [        R                  U [        U 5      5      5      eU $ )a  
Coerce a domain name string to bytes.

L{twisted.names} represents domain names as L{bytes}, but many interfaces
accept L{bytes} or a text string (L{unicode} on Python 2, L{str} on Python
3). This function coerces text strings using IDNA encoding --- see
L{encodings.idna}.

Note that DNS is I{case insensitive} but I{case preserving}. This function
doesn't normalize case, so you'll still need to do that whenever comparing
the strings it returns.

@param domain: A domain name.  If passed as a text string it will be
    C{idna} encoded.
@type domain: L{bytes} or L{str}

@returns: L{bytes} suitable for network transmission.
@rtype: L{bytes}

@since: Twisted 20.3.0
idnaz+Expected {} or {} but found {!r} of type {})
isinstancestrencoder~   	TypeErrorr   r   type)domains    r   domainStringr   ?  sc    , &#v&fe$$9@@fd6l
 	

 Mr   c                    [        U R                  5       5      n[        UR                  5       5      nU[        U5      * S U:H  $ )a  
Test whether C{descendantName} is equal to or is a I{subdomain} of
C{ancestorName}.

The names are compared case-insensitively.

The names are treated as byte strings containing one or more
DNS labels separated by B{.}.

C{descendantName} is considered equal if its sequence of labels
exactly matches the labels of C{ancestorName}.

C{descendantName} is considered a I{subdomain} if its sequence of
labels ends with the labels of C{ancestorName}.

@type descendantName: L{bytes}
@param descendantName: The DNS subdomain name.

@type ancestorName: L{bytes}
@param ancestorName: The DNS parent or ancestor domain name.

@return: C{True} if C{descendantName} is equal to or if it is a
    subdomain of C{ancestorName}. Otherwise returns C{False}.
N)r   lowerlen)descendantNameancestorNamedescendantLabelsancestorLabelss       r   _isSubdomainOfr   `  sF    2 %^%9%9%;<"<#5#5#78NS0023~EEr   c                   SnU R                  5       R                  5       n U H7  u  p#U R                  U5      (       d  M  [        [	        U SS 5      U-  5      s  $     [        U 5      $ ! [
         a    [        SU -   5      ef = f)ze
mypy doesn't like type-punning str | bytes | int | None into a str so we have this helper function.
))Sr   )M<   )r   i  )DiQ )Wi:	 )Yi3Nr   z!Invalid time interval specifier: )upperstripendswithintfloat
ValueError)ssuffixessuffmults       r   	_str2timer   ~  s    H 	
	A
::duQsV}t+,, B1v B<q@AABs   
A* *Bc                    g Nr   r   s    r   str2timer         r   c                    g r   r   r   s    r   r   r     r   r   c                    [        U [        5      (       a  [        U R                  S5      5      $ [        U [        5      (       a  [        U 5      $ U $ )a  
Parse a string description of an interval into an integer number of seconds.

@param s: An interval definition constructed as an interval duration
    followed by an interval unit.  An interval duration is a base ten
    representation of an integer.  An interval unit is one of the following
    letters: S (seconds), M (minutes), H (hours), D (days), W (weeks), or Y
    (years).  For example: C{"3S"} indicates an interval of three seconds;
    C{"5D"} indicates an interval of five days.  Alternatively, C{s} may be
    any non-string and it will be returned unmodified.
@type s: text string (L{bytes} or L{str}) for parsing; anything else
    for passthrough.

@return: an L{int} giving the interval represented by the string C{s}, or
    whatever C{s} is if it is not a string.
ascii)r   r~   r   decoder   r   s    r   r   r     sA    " !U'*++!S|Hr   c                R    U R                  U5      n[        U5      U:  a  [        eU$ r   )readr   EOFError)filelbuffs      r   readPreciselyr     s$    99Q<D
4y1}Kr   c                  ,    \ rS rSrSrSS jrSS jrSrg)r   i  z
Interface for something which can be encoded to and decoded
to the DNS wire format.

A binary-mode file object (such as L{io.BytesIO}) is used as a buffer when
encoding or decoding.
Nc                    g)a  
Write a representation of this object to the given
file object.

@type strio: File-like object
@param strio: The buffer to write to. It must have a C{tell()} method.

@type compDict: L{dict} of L{bytes} to L{int} r L{None}
@param compDict: A mapping of names to byte offsets that have already
been written to the buffer, which may be used for compression (see RFC
1035 section 4.1.4). When L{None}, encode without compression.
Nr   )striocompDicts     r   r   IEncodable.encode      r   c                    g)a  
Reconstruct an object from data read from the given
file object.

@type strio: File-like object
@param strio: A seekable buffer from which bytes may be read.

@type length: L{int} or L{None}
@param length: The number of bytes in this RDATA field.  Most
implementations can ignore this value.  Only in the case of
records similar to TXT where the total length is in no way
encoded in the data is it necessary.
Nr   )r   lengths     r   r   IEncodable.decode  r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r     s    r   r   c                      \ rS rSrSrSrg)r   i  zT
Interface for DNS records that can be encoded and decoded.

@since: Twisted 21.2.0
r   N)r   r   r   r   r   r   r   r   r   r   r     s    r   r   c                  P    \ rS rSrS
SS jjrSS jrSS jrSS jrS rSS jr	S	r
g)ri   i  c                X    [        U[        5      (       d  [        U< S35      eXl        g )Nz is not a byte string)r   r~   r   string)selfr   s     r   __init__Charstr.__init__  s'    &%((z)>?@@r   Nc                    U R                   n[        U5      nUR                  [        U5      5        UR                  U5        g)z
Encode this Character string into the appropriate byte format.

@type strio: file
@param strio: The byte representation of this Charstr will be written
    to this file.
N)r   r   writer   )r   r   r   r   inds        r   r   Charstr.encode  s2     &kJsO$Fr   c                \    SU l         [        [        US5      5      n[        X5      U l         g)z
Decode a byte string into this Charstr.

@type strio: file
@param strio: Bytes will be read from this file until the full string
    is decoded.

@raise EOFError: Raised when there are not enough bytes available from
    C{strio}.
r   r   N)r   ordr   )r   r   r   r   s       r   r   Charstr.decode  s(     eQ'(#E-r   c                j    [        U[        5      (       a  U R                  UR                  :H  $ [        $ r   )r   ri   r   NotImplementedr   others     r   __eq__Charstr.__eq__  s(    eW%%;;%,,..r   c                ,    [        U R                  5      $ r   )hashr   r   s    r   __hash__Charstr.__hash__  s    DKK  r   c                ,    [        U R                  5      $ )z9
Represent this L{Charstr} instance by its string value.
)r   r   r  s    r   __str__Charstr.__str__  s     DKK((r   )r   r   )r   r~   r   r	  objectreturnboolr  r   )r   r   r   r   r   r   r   r
  r  r  r   r   r   r   ri   ri     s     
.
!)r   ri   c                  T    \ rS rSrSrSSS jjrSS jrSS jrSS jrS r	SS	 jr
S
rg)rk   i   z
A name in the domain name system, made up of multiple labels.  For example,
I{twistedmatrix.com}.

@ivar name: A byte string giving the name.
@type name: L{bytes}
c                $    [        U5      U l        g)z5
@param name: A name.
@type name: L{bytes} or L{str}
N)r   r   )r   r   s     r   r   Name.__init__*  s    
 !&	r   Nc                   U R                   nU(       a  UbT  X2;   a,  UR                  [        R                  " SSX#   -  5      5        gUR	                  5       [
        R                  -   X#'   UR                  S5      nUS:  a  USU X4S-   S p5OUnSn[        U5      nUR                  [        U5      5        UR                  U5        U(       a  M  UR                  S5        g)aY  
Encode this Name into the appropriate byte format.

@type strio: file
@param strio: The byte representation of this Name will be written to
this file.

@type compDict: dict
@param compDict: dictionary of Names that have already been encoded
and whose addresses may be backreferenced by this Name (for the purpose
of reducing the message size).
N!Hi   r   r   r       )
r   r   r   packtellrj   
headerSizefindr   r   )r   r   r   r   r  labels         r   r   Name.encode1  s     yy##KKD&8>2I JK%*ZZ\G4F4F%FHN))D/CQw"4Cj$Qwy/t %jKK
3(KK! d" 	Gr   c                   [        5       nSU l        Sn [        [        US5      5      nUS:X  a  US:  a  UR	                  U5        gUS-	  S:X  ah  US-  S-  [        [        US5      5      -  nXc;   a  [        S	5      eUR                  U5        US:X  a  UR                  5       nUR	                  U5        M  [        X5      nU R                  S:X  a  Xpl        OU R                  S
-   U-   U l        M  )aE  
Decode a byte string into this Name.

@type strio: file
@param strio: Bytes will be read from this file until the full Name
is decoded.

@raise EOFError: Raised when there are not enough bytes available
from C{strio}.

@raise ValueError: Raised when the name cannot be decoded (for example,
    because it contains a loop).
r   r   r   Nr   r   ?      z Compression loop in encoded namer   )setr   r  r   seekr   addr!  )r   r   r   visitedoffr   new_offr$  s           r   r   Name.decodeR  s     %	M%+,AAv7JJsOQ1}r6a-#mE1.E*FF%$%GHHG$!8**,C

7#!%+EyyC!	 II,u4	' r   c                    [        U[        5      (       a5  U R                  R                  5       UR                  R                  5       :H  $ [        $ r   )r   rk   r   r   r  r  s     r   r
  Name.__eq__x  s8    eT""99??$

(8(8(:::r   c                ,    [        U R                  5      $ r   r  r   r  s    r   r  Name.__hash__}      DIIr   c                ,    [        U R                  5      $ )z5
Represent this L{Name} instance by its string name.
r   r   r  s    r   r  Name.__str__  s     DII&&r   )r   r  )r   bytes | strr   r  r  )r   r   r   r   r   r   r   r   r
  r  r  r   r   r   r   rk   rk      s'    'B$5L
'r   rk   c                  `    \ rS rSrSrS\\4SS jjrSS jrSS jr	S r
S	 rSS
 jrSS jrSrg)rl   i  z
Represent a single DNS query.

@ivar name: The name about which this query is requesting information.
@type name: L{Name}

@ivar type: The query type.
@type type: L{int}

@ivar cls: The query class.
@type cls: L{int}
r   c                <    [        U5      U l        X l        X0l        g)z
@type name: L{bytes} or L{str}
@param name: See L{Query.name}

@type type: L{int}
@param type: The query type.

@type cls: L{int}
@param cls: The query class.
N)rk   r   r   clsr   r   r   r<  s       r   r   Query.__init__  s     J		r   Nc                    U R                   R                  X5        UR                  [        R                  " SU R
                  U R                  5      5        g N!HH)r   r   r   r   r   r   r<  r   r   r   s      r   r   Query.encode  s5    		)FKKtyy$((;<r   c                    U R                   R                  U5        [        US5      n[        R                  " SU5      u  U l        U l        g )Nr   rA  )r   r   r   r   r   r   r<  )r   r   r   r   s       r   r   Query.decode  s9    		UA&$mmE48	48r   c                    [        U R                  R                  R                  5       U R                  U R                  45      $ r   )r  r   r   r   r<  r  s    r   r  Query.__hash__  s-    TYY^^))+TYYABBr   c                4   [        U[        5      (       a~  [        U R                  R                  R	                  5       U R
                  U R                  4UR                  R                  R	                  5       UR
                  UR                  45      $ [        $ r   )r   rl   r   r   r   r   r<  r  r  s     r   __cmp__Query.__cmp__  sj    eU##%%'DHH=&&(%**eii@  r   c                   [         R                  U R                  [        R                  U R                  SU R                  -  5      5      n[        R                  U R
                  SU R
                  -  5      nSU R                   SU SU S3$ )NUNKNOWN (%d)z<Query  >)re   getr   rh   rd   r<  r   r   tcs      r   r  Query.__str__  sq    OOII{tyy.4992LM
 dhh(AB1QCq1--r   c                p    SU R                   R                   < SU R                  < SU R                  < S3$ )NzQuery(r   ))r   r   r<  r  s    r   __repr__Query.__repr__  s.    		)DII=488,aHHr   )r<  r   r   )r   Union[bytes, str]r   r   r<  r   r   r  )r   r   r   r   r   r   r<   r   r   r   r  rI  r  rV  r   r   r   r   rl   rl     s6     25!PR =9
C.Ir   rl   c                      \ rS rSrSrSS 4SSSSS	S
4rSr     SS jr\S 5       r	\S 5       r
SS jrSS jr\S 5       rSrg)
_OPTHeaderi  a&  
An OPT record header.

@ivar name: The DNS name associated with this record. Since this
    is a pseudo record, the name is always an L{Name} instance
    with value b'', which represents the DNS root zone. This
    attribute is a readonly property.

@ivar type: The DNS record type. This is a fixed value of 41
    C{dns.OPT} for OPT Record. This attribute is a readonly
    property.

@see: L{_OPTHeader.__init__} for documentation of other public
    instance attributes.

@see: U{https://tools.ietf.org/html/rfc6891#section-6.1.2}

@since: 13.2
r   c                ,    [        U R                  5      $ r   r7  )ns    r   <lambda>_OPTHeader.<lambda>  s    </r   r   udpPayloadSizeextendedRCODEversiondnssecOKoptions)r   r   r_  r`  ra  rb  rc  Nc                J    Xl         X l        X0l        X@l        Uc  / nXPl        g)a  
@type udpPayloadSize: L{int}
@param udpPayloadSize: The number of octets of the largest UDP
    payload that can be reassembled and delivered in the
    requestor's network stack.

@type extendedRCODE: L{int}
@param extendedRCODE: Forms the upper 8 bits of extended
    12-bit RCODE (together with the 4 bits defined in
    [RFC1035].  Note that EXTENDED-RCODE value 0 indicates
    that an unextended RCODE is in use (values 0 through 15).

@type version: L{int}
@param version: Indicates the implementation level of the
    setter.  Full conformance with this specification is
    indicated by version C{0}.

@type dnssecOK: L{bool}
@param dnssecOK: DNSSEC OK bit as defined by [RFC3225].

@type options: L{list}
@param options: A L{list} of 0 or more L{_OPTVariableOption}
    instances.
Nr_  r`  ra  rb  rc  )r   r_  r`  ra  rb  rc  s         r   r   _OPTHeader.__init__  s*    @ -* ?Gr   c                    [        S5      $ )z
A readonly property for accessing the C{name} attribute of
this record.

@return: The DNS name associated with this record. Since this
    is a pseudo record, the name is always an L{Name} instance
    with value b'', which represents the DNS root zone.
r   )rk   r  s    r   r   _OPTHeader.name  s     Cyr   c                    [         $ )z
A readonly property for accessing the C{type} attribute of
this record.

@return: The DNS record type. This is a fixed value of 41
    (C{dns.OPT} for OPT Record.
)r.   r  s    r   r   _OPTHeader.type$  s	     
r   c           	     t   [        5       nU R                   H  nUR                  U5        M     UR                  5       n[	        U R
                  R
                  U R                  U R                  U R                  S-  U R                  S-  -  U R                  S-  -  [        U5      S9R                  X5        g)aa  
Encode this L{_OPTHeader} instance to bytes.

@type strio: file
@param strio: the byte representation of this L{_OPTHeader}
    will be written to this file.

@type compDict: L{dict} or L{None}
@param compDict: A dictionary of backreference addresses that
    have already been written to this stream and that may
    be used for DNS name compression.
   r      )r   r   r<  ttlpayloadN)r   rc  r   getvaluerm   r   r   r_  r`  ra  rb  rc   )r   r   r   r   ooptionBytess         r   r   _OPTHeader.encode/  s     IAHHQK jjl####r)DLLB,>>RTATT!+.	
 &
!r   c           	        [        5       nUR                  X5        [        [        XR                  5      5      Ul        U R                  U5      nU R                   H   nUS;  d  M  [        X[        XE5      5        M"     g)z
Decode bytes into an L{_OPTHeader} instance.

@type strio: file
@param strio: Bytes will be read from this file until the full
    L{_OPTHeader} is decoded.

@type length: L{int} or L{None}
@param length: Not used.
)r   r   N)
rm   r   rc   r   rdlengthro  fromRRHeadercompareAttributessetattrgetattr)r   r   r   hnewOptHeaderattrNames         r   r   _OPTHeader.decodeI  sd     J	!-zz"BC	((+..H//(GH /r   c                   SnUR                   b  / n[        UR                   R                  5      n[        UR                   R                  5      nUR	                  5       U:  aB  [        5       nUR                  U5        UR                  U5        UR	                  5       U:  a  MB  U " UR                  UR                  S-	  UR                  S-	  S-  UR                  S-  S-	  US9$ )a)  
A classmethod for constructing a new L{_OPTHeader} from the
attributes and payload of an existing L{RRHeader} instance.

@type rrHeader: L{RRHeader}
@param rrHeader: An L{RRHeader} instance containing an
    L{UnknownRecord} payload.

@return: An instance of L{_OPTHeader}.
@rtype: L{_OPTHeader}
Nrl  r   r   i  rm  re  )
ro  r   datar   r!  _OPTVariableOptionr   r   r<  rn  )r<  rrHeaderrc  optionsBytesoptionsBytesLengthrq  s         r   rv  _OPTHeader.fromRRHeader_  s     'G"8#3#3#8#89L!$X%5%5%:%:!;##%(::&(&q! ##%(:: #<<",,",LLB&-llV+2
 	
r   )rb  r`  rc  r_  ra  )i   r   r   FNr   )r   r   r   r   r   showAttributesrw  r   propertyr   r   r   r   classmethodrv  r   r   r   r   rZ  rZ    s    * 
/0N 'R 	 	  "4I, 
 
r   rZ  c                  J    \ rS rSrSrSS\44rSrSrSS jr	SS	 jr
SS
 jrSrg)r  i  z
A class to represent OPT record variable options.

@see: L{_OPTVariableOption.__init__} for documentation of public
    instance attributes.

@see: U{https://tools.ietf.org/html/rfc6891#section-6.1.2}

@since: 13.2
coder  r  r  rA  c                    Xl         X l        g)zd
@type code: L{int}
@param code: The option code

@type data: L{bytes}
@param data: The option data
Nr  )r   r  r  s      r   r   _OPTVariableOption.__init__  s     		r   Nc           	         UR                  [        R                  " U R                  U R                  [        U R                  5      5      U R                  -   5        g)ah  
Encode this L{_OPTVariableOption} to bytes.

@type strio: file
@param strio: the byte representation of this
    L{_OPTVariableOption} will be written to this file.

@type compDict: L{dict} or L{None}
@param compDict: A dictionary of backreference addresses that
    have already been written to this stream and that may
    be used for DNS name compression.
N)r   r   r   _fmtr  r   r  rB  s      r   r   _OPTVariableOption.encode  s6     	FKK		499c$))nE		QRr   c                    [         R                  " U R                  5      n[        X5      n[         R                  " U R                  U5      u  U l        n[        X5      U l        g)z
Decode bytes into an L{_OPTVariableOption} instance.

@type strio: file
@param strio: Bytes will be read from this file until the full
    L{_OPTVariableOption} is decoded.

@type length: L{int} or L{None}
@param length: Not used.
N)r   calcsizer  r   r   r  r  )r   r   r   r   r   s        r   r   _OPTVariableOption.decode  sG     OODII&U&"MM$))T:	6!%0	r   )r   r   r   )r   r   r   r   r   r   r  rw  r  r   r   r   r   r   r   r   r  r    s3    	 v|45N(D	S1r   r  c                      \ rS rSrSrSrSrSrSrS\	\
SSS4           SS	 jjrSS
 jrSS jrS rSS jr\rSrg)rm   i  a3  
A resource record header.

@cvar fmt: L{str} specifying the byte format of an RR.

@ivar name: The name about which this reply contains information.
@type name: L{Name}

@ivar type: The query type of the original request.
@type type: L{int}

@ivar cls: The query class of the original request.

@ivar ttl: The time-to-live for this record.
@type ttl: L{int}

@ivar payload: The record described by this header.
@type payload: L{IEncodableRecord} or L{None}

@ivar auth: A L{bool} indicating whether this C{RRHeader} was parsed from
    an authoritative message.
)r   r   r<  rn  ro  authz!HHIHNr   r   Fc           	     >   Uc  SOUR                   nUb?  Xr:w  a:  [        S[        R                  Xw5      < S[        R                  X"5      < S35      e[	        U5      nUS:  a  [        S5      e[        U5      U l        X l        X0l        Xl	        XPl
        X`l        g)aE  
@type name: L{bytes} or L{str}
@param name: See L{RRHeader.name}

@type type: L{int}
@param type: The query type.

@type cls: L{int}
@param cls: The query class.

@type ttl: L{int}
@param ttl: Time to live for this record.  This will be
    converted to an L{int}.

@type payload: L{IEncodableRecord} or L{None}
@param payload: An optional Query Type specific data object.

@raises TypeError: if the ttl cannot be converted to an L{int}.
@raises ValueError: if the ttl is negative.
@raises ValueError: if the payload type is not equal to the C{type}
                    argument.
NzPayload type (z) does not match given type (rU  r   zTTL cannot be negative)r   r   re   rO  r   rk   r   r   r<  rn  ro  r  )	r   r   r   r<  rn  ro  r  payloadTypeintegralTTLs	            r   r   RRHeader.__init__  s    > &od7<<"{':  OOK=OOD/  #h?566J			r   c           	        U R                   R                  X5        UR                  [        R                  " U R
                  U R                  U R                  U R                  S5      5        U R                  (       a  UR                  5       nU R                  R                  X5        UR                  5       nUR                  US-
  S5        UR                  [        R                  " SXC-
  5      5        UR                  US5        g g )Nr   r   r  )r   r   r   r   r   fmtr   r<  rn  ro  r!  r*  )r   r   r   prefixafts        r   r   RRHeader.encode  s    		)FKK$))TXXtxxKL<<ZZ\FLL0**,CJJvz1%KKD#,78JJsA r   c                   U R                   R                  U5        [        R                  " U R                  5      n[        X5      n[        R                  " U R                  U5      nUu  U l        U l        U l	        U l
        g r   )r   r   r   r  r  r   r   r   r<  rn  ru  )r   r   r   r   r   rs         r   r   RRHeader.decode  sZ    		OODHH%U&MM$((D)784	48TXt}r   c                    U R                   $ r   r  r  s    r   isAuthoritativeRRHeader.isAuthoritative%  s    yyr   c                f   [         R                  U R                  [        R                  U R                  SU R                  -  5      5      n[        R                  U R
                  SU R
                  -  5      nSU R                  UUU R                  U R                  =(       a    S=(       d    S4-  $ )NrL  z-<RR name=%s type=%s class=%s ttl=%ds auth=%s>TrueFalse)	re   rO  r   rh   rd   r<  r   rn  r  rP  s      r   r  RRHeader.__str__(  s    OOII{tyy.4992LM
 dhh(AB>IIHHII &+GB
 
 	
r   )r  r<  r   ro  ru  rn  r   )r   rX  r   r   r<  r   rn  r   ro  zOptional[IEncodableRecord]r  r  r   r  )r   r   r   r   r   rw  r  ru  cachedResponser   r<   r   r   r   r  r  rV  r   r   r   r   rm   rm     s    . J
CHN #&.233 3 	3
 3 ,3 3j	9
 Hr   rm   c                  X    \ rS rSr% SrSrSrSrS\S'   Sr	SS jr
SS	 jrSS
 jrS rSrg)rn   i8  z
A Resource Record which consists of a single RFC 1035 domain-name.

@type name: L{Name}
@ivar name: The name associated with this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
)r   r   %srn  )r   rn  NzOptional[int]r   c                D    [        U5      U l        [        U5      U l        g)zF
@param name: See L{SimpleRecord.name}
@type name: L{bytes} or L{str}
N)rk   r   r   rn  )r   r   rn  s      r   r   SimpleRecord.__init__K  s    
 J	C=r   c                :    U R                   R                  X5        g r   )r   r   rB  s      r   r   SimpleRecord.encodeS  s    		)r   c                X    [        5       U l        U R                  R                  U5        g r   )rk   r   r   r   r   r   s      r   r   SimpleRecord.decodeV  s    F			r   c                ,    [        U R                  5      $ r   r3  r  s    r   r  SimpleRecord.__hash__Z  r5  r   r   Nr   )r   r   r   r   r   r  rw  r   __annotations__r   r   r   r   r  r   r   r   r   rn   rn   8  s7    	 5N'D-D!* r   rn   c                       \ rS rSrSr\rSrSrg)rX   i_  z
An authoritative nameserver.
r,   r   N)	r   r   r   r   r   r,   r   fancybasenamer   r   r   r   rX   rX   _  s     DMr   rX   c                       \ rS rSrSr\rSrSrg)rQ   ih  zH
A mail destination.

This record type is obsolete.

@see: L{Record_MX}
r%   r   N)	r   r   r   r   r   r%   r   r  r   r   r   r   rQ   rQ   h       DMr   rQ   c                       \ rS rSrSr\rSrSrg)rR   iu  zF
A mail forwarder.

This record type is obsolete.

@see: L{Record_MX}
r&   r   N)	r   r   r   r   r   r&   r   r  r   r   r   r   rR   rR   u  r  r   rR   c                       \ rS rSrSr\rSrSrg)rM   i  z"
The canonical name for an alias.
r   r   N)	r   r   r   r   r   r   r   r  r   r   r   r   rM   rM     s     DMr   rM   c                       \ rS rSrSr\rSrSrg)rP   i  z>
A mailbox domain name.

This is an experimental record type.
r$   r   N)	r   r   r   r   r   r$   r   r  r   r   r   r   rP   rP          DMr   rP   c                       \ rS rSrSr\rSrSrg)rS   i  z<
A mail group member.

This is an experimental record type.
r'   r   N)	r   r   r   r   r   r'   r   r  r   r   r   r   rS   rS     r  r   rS   c                       \ rS rSrSr\rSrSrg)rU   i  zB
A mail rename domain name.

This is an experimental record type.
r)   r   N)	r   r   r   r   r   r)   r   r  r   r   r   r   rU   rU     r  r   rU   c                       \ rS rSrSr\rSrSrg)rZ   i  z
A domain name pointer.
r/   r   N)	r   r   r   r   r   r/   r   r  r   r   r   r   rZ   rZ     s     DMr   rZ   c                       \ rS rSrSr\rSrSrg)rN   i  a?  
A non-terminal DNS name redirection.

This record type provides the capability to map an entire subtree of the
DNS name space to another domain.  It differs from the CNAME record which
maps a single node of the name space.

@see: U{http://www.faqs.org/rfcs/rfc2672.html}
@see: U{http://www.faqs.org/rfcs/rfc3363.html}
r    r   N)	r   r   r   r   r   r    r   r  r   r   r   r   rN   rN     s    	 DMr   rN   c                  \    \ rS rSrSrSr\rSrSS jr	SS jr
SS jrS rSS	 jr\rS
 rSrg)rI   i  a   
An IPv4 host address.

@type address: L{bytes}
@ivar address: The packed network-order representation of the IPv4 address
    associated with this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
addressrn  Nc                    [        U[        5      (       a  UR                  S5      n[        R                  " U5      nXl        [        U5      U l        g)~
@type address: L{bytes} or L{str}
@param address: The IPv4 address associated with this record, in
    quad-dotted notation.
r   N)r   r~   r   socket	inet_atonr  r   rn  r   r  rn  s      r   r   Record_A.__init__  s?     gu%%nnW-G""7+C=r   c                :    UR                  U R                  5        g r   r   r  rB  s      r   r   Record_A.encode      DLL!r   c                &    [        US5      U l        g )Nr   r   r  r  s      r   r   Record_A.decode  s    $UA.r   c                ,    [        U R                  5      $ r   r  r  r  s    r   r  Record_A.__hash__      DLL!!r   c                D    SU R                  5        SU R                   S3$ )Nz<A address=z ttl=rN  )
dottedQuadrn  r  s    r   r  Record_A.__str__  s#    T__./uTXXJa@@r   c                B    [         R                  " U R                  5      $ r   r  	inet_ntoar  r  s    r   r  Record_A.dottedQuad  s    --r   )0.0.0.0Nr   r  )r   r   r   r   r   rw  r   r   r  r   r   r   r  r  rV  r  r   r   r   r   rI   rI     s?    
 +DG!"/"A H.r   rI   c                  \    \ rS rSrSrSrSrSr\r	        SS jr
SS jrSS	 jrS
 rSrg)r\   i  a  
Marks the start of a zone of authority.

This record describes parameters which are shared by all records within a
particular zone.

@type mname: L{Name}
@ivar mname: The domain-name of the name server that was the original or
    primary source of data for this zone.

@type rname: L{Name}
@ivar rname: A domain-name which specifies the mailbox of the person
    responsible for this zone.

@type serial: L{int}
@ivar serial: The unsigned 32 bit version number of the original copy of
    the zone.  Zone transfers preserve this value.  This value wraps and
    should be compared using sequence space arithmetic.

@type refresh: L{int}
@ivar refresh: A 32 bit time interval before the zone should be refreshed.

@type minimum: L{int}
@ivar minimum: The unsigned 32 bit minimum TTL field that should be
    exported with any RR from this zone.

@type expire: L{int}
@ivar expire: A 32 bit time value that specifies the upper limit on the
    time interval that can elapse before the zone is no longer
    authoritative.

@type retry: L{int}
@ivar retry: A 32 bit time interval that should elapse before a failed
    refresh should be retried.

@type ttl: L{int}
@ivar ttl: The default TTL to use for records served from this zone.
r1   )serialmnamernamerefreshexpireretryminimumrn  ))r  r  r  )r  r  r  r  r  r  r  r  rn  Nc	                
   [        U5      [        U5      sU l        U l        [        U5      [        U5      sU l        U l        [        U5      [        U5      sU l        U l        [        U5      U l        [        U5      U l	        g)z
@param mname: See L{Record_SOA.mname}
@type mname: L{bytes} or L{str}

@param rname: See L{Record_SOA.rname}
@type rname: L{bytes} or L{str}
N)
rk   r  r  r   r  r  r  r  r  rn  )	r   r  r  r  r  r  r  r  rn  s	            r   r   Record_SOA.__init__8  sf    $ "&ed5k
DJ$,V$4hw6G!T\$,W$5x7G!dke_
C=r   c           
     (   U R                   R                  X5        U R                  R                  X5        UR                  [        R
                  " SU R                  U R                  U R                  U R                  U R                  5      5        g )N!LlllL)r  r   r  r   r   r   r  r  r  r  r  rB  s      r   r   Record_SOA.encodeP  sd    

%*

%*KK

		
r   c                2   [        5       [        5       sU l        U l        U R                  R                  U5        U R                  R                  U5        [        R
                  " S[        US5      5      nUu  U l        U l        U l	        U l
        U l        g )Nr     )rk   r  r  r   r   r   r   r  r  r  r  r  r   r   r   r  s       r   r   Record_SOA.decode^  sk    !%
DJ

% 

% MM(M%$<=KLHT\4:t{DLr   c                    [        U R                  U R                  U R                  U R                  U R
                  U R                  45      $ r   )r  r  r  r  r  r  r  r  s    r   r  Record_SOA.__hash__e  s7    [[$**djj$,,TZZX
 	
r   )r  r  r  r  r  r  r  rn  )r   r   r   r   r   r   r   Nr   )r   r   r   r   r   r  rw  r  r1   r   r   r   r   r  r   r   r   r   r\   r\     sT    %N M		N D !0
M
r   r\   c                  T    \ rS rSrSrSrS\4S4rSr\	r
SS jrSS	 jrSS
 jrS rSrg)rY   ik  z
A null record.

This is an experimental record type.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
r-   ro  rn  )ro  rn  Nc                0    Xl         [        U5      U l        g r   )ro  r   rn  )r   ro  rn  s      r   r   Record_NULL.__init__}  s    C=r   c                :    UR                  U R                  5        g r   )r   ro  rB  s      r   r   Record_NULL.encode  r  r   c                $    [        X5      U l        g r   )r   ro  r  s      r   r   Record_NULL.decode  s    $U3r   c                ,    [        U R                  5      $ r   )r  ro  r  s    r   r  Record_NULL.__hash__  r  r   )NNr   )r   r   r   r   r   r  r   r  rw  r-   r   r   r   r   r  r   r   r   r   rY   rY   k  s<     M *-u5N*D!"4"r   rY   c                  `    \ rS rSrSrSrSr/ SQr\r	\
S 5       rSS jrSS	 jrSS
 jrS rSrg)rb   i  a  
A well known service description.

This record type is obsolete.  See L{Record_SRV}.

@type address: L{bytes}
@ivar address: The packed network-order representation of the IPv4 address
    associated with this record.

@type protocol: L{int}
@ivar protocol: The 8 bit IP protocol number for which this service map is
    relevant.

@type map: L{bytes}
@ivar map: A bitvector indicating the services available at the specified
    address.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
r7   )r  r   maprn  )_addressr  r  r   rn  c                B    [         R                  " U R                  5      $ r   r  r  s    r   r  Record_WKS._address  s    --r   Nc                    [        U[        5      (       a  UR                  S5      n[        R                  " U5      U l        X#sU l        U l        [        U5      U l	        g)r  r   N)
r   r~   r   r  r  r  r   r  r   rn  )r   r  r   r  rn  s        r   r   Record_WKS.__init__  sJ     gu%%nnV,G''0"*txC=r   c                    UR                  U R                  5        UR                  [        R                  " SU R                  5      5        UR                  U R
                  5        g N!B)r   r  r   r   r   r  rB  s      r   r   Record_WKS.encode  s=    DLL!FKKdmm45DHHr   c                    [        US5      U l        [        R                  " S[        US5      5      S   U l        [        XS-
  5      U l        g )Nr   r  r   r   r   )r   r  r   r   r   r  r  s      r   r   Record_WKS.decode  s>    $UA.dM%,CDQG 
3r   c                Z    [        U R                  U R                  U R                  45      $ r   )r  r  r   r  r  s    r   r  Record_WKS.__hash__  s     T\\4==$((;<<r   )r  r  r   rn  )r  r   r   Nr   )r   r   r   r   r   r  rw  r  r7   r   r  r  r   r   r   r  r   r   r   r   rb   rb     sD    , M=GND. .!
4
=r   rb   c                  \    \ rS rSrSr\rSrSrSr	\
S 5       rSS jrSS	 jrSS
 jrS rSrg)rK   i  a0  
An IPv6 host address.

@type address: L{bytes}
@ivar address: The packed network-order representation of the IPv6 address
    associated with this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.

@see: U{http://www.faqs.org/rfcs/rfc1886.html}
r   )r  rn  r  c                L    [         R                  " [        U R                  5      $ r   )r  	inet_ntopAF_INET6r  r  s    r   r  Record_AAAA._address  s    $,,77r   Nc                    [        U[        5      (       a  UR                  S5      n[        R                  " [
        U5      U l        [        U5      U l        g)zg
@type address: L{bytes} or L{str}
@param address: The IPv6 address for this host, in RFC 2373 format.
r   N)	r   r~   r   r  	inet_ptonr  r  r   rn  r  s      r   r   Record_AAAA.__init__  s>    
 gu%%nnV,G''':C=r   c                :    UR                  U R                  5        g r   r  rB  s      r   r   Record_AAAA.encode  r  r   c                &    [        US5      U l        g )Nr   r  r  s      r   r   Record_AAAA.decode  s    $UB/r   c                ,    [        U R                  5      $ r   r  r  s    r   r  Record_AAAA.__hash__  r  r   )::Nr   )r   r   r   r   r   r   r   r  r  rw  r  r  r   r   r   r  r   r   r   r   rK   rK     sD     DM;N*8 8	!"0"r   rK   c                      \ rS rSrSr\rSrSrSr	\
S 5       r    S       SS jjrSS	 jrSS
 jrSS jrS rSS jrSrg)rJ   i  al  
An IPv6 address.

This is an experimental record type.

@type prefixLen: L{int}
@ivar prefixLen: The length of the suffix.

@type suffix: L{bytes}
@ivar suffix: An IPv6 address suffix in network order.

@type prefix: L{Name}
@ivar prefix: If specified, a name which will be used as a prefix for other
    A6 records.

@type bytes: L{int}
@ivar bytes: The length of the prefix.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.

@see: U{http://www.faqs.org/rfcs/rfc2874.html}
@see: U{http://www.faqs.org/rfcs/rfc3363.html}
@see: U{http://www.faqs.org/rfcs/rfc3364.html}
r   ))_suffixsuffixr  )r  r  r  rn  )	prefixLenr  r  rn  c                L    [         R                  " [        U R                  5      $ r   )r  r  r  r  r  s    r   r  Record_A6._suffix  s    $++66r   Nc                   [        U[        5      (       a  UR                  S5      nXl        [        R
                  " [        U5      U l        [        U5      U l	        [        SU R                  -
  S-  5      U l        [        U5      U l        g)z
@param suffix: An IPv6 address suffix in in RFC 2373 format.
@type suffix: L{bytes} or L{str}

@param prefix: An IPv6 address prefix for other A6 records.
@type prefix: L{bytes} or L{str}
r             @N)r   r~   r   r  r  r  r  r  rk   r  r   r   rn  )r   r  r  r  rn  s        r   r   Record_A6.__init__  sh     fe$$]]6*F"&&x86l#.#56
C=r   c                4   UR                  [        R                  " SU R                  5      5        U R                  (       a)  UR                  U R
                  U R                  * S  5        U R                  (       a  U R                  R                  US 5        g g r  )r   r   r   r  r~   r  r  r   rB  s      r   r   Record_A6.encode5  sa    FKKdnn56::KKTZZKM23>>KKud+ r   c                l   [         R                  " S[        US5      5      S   U l        [	        SU R                  -
  S-  5      U l        U R
                  (       a-  SSU R
                  -
  -  [        XR
                  5      -   U l        U R                  (       a  U R                  R                  U5        g g )Nr  r   r   r"  r#  r  r   )	r   r   r   r  r   r~   r  r  r   r  s      r   r   Record_A6.decode=  s    t]5!-DEaH#.#56
::!R$**_5eZZ8XXDK>>KKu% r   c                b   [        U[        5      (       a  U R                  UR                  :H  =(       au    U R                  U R                  * S  UR                  U R                  * S  :H  =(       a9    U R
                  UR
                  :H  =(       a    U R                  UR                  :H  $ [        $ r   )r   rJ   r  r  r~   r  rn  r  r  s     r   r
  Record_A6.__eq__E  s    eY''%//1 *KK.%,,

{}2MM*KK5<</* HH		)	 r   c                v    [        U R                  U R                  U R                  * S  U R                  45      $ r   )r  r  r  r~   r  r  s    r   r  Record_A6.__hash__O  s-    T^^T[[$**%?MNNr   c                    SU R                   [        R                  " [        U R                  5      U R
                  U R                  4-  $ )Nz<A6 %s %s (%d) ttl=%s>)r  r  r  r  r  r  rn  r  s    r   r  Record_A6.__str__R  s=    'KKXt{{3NNHH	+
 
 	
r   )r~   r  r  r  rn  )r   r  r   N)r  r   r  r9  r  r9  rn  Union[str, bytes, int, None]r   r  r  )r   r   r   r   r   r   r   r  r  rw  r  r  r   r   r   r
  r  r  r   r   r   r   rJ   rJ     s    6 DMUN@7 7
 "!,0!! ! 	!
 *!.,&O
r   rJ   c                  L    \ rS rSrSr\rSrSrSr	SS jr
SS jrSS	 jrS
 rSrg)r^   i[  a  
The location of the server(s) for a specific protocol and domain.

This is an experimental record type.

@type priority: L{int}
@ivar priority: The priority of this target host.  A client MUST attempt to
    contact the target host with the lowest-numbered priority it can reach;
    target hosts with the same priority SHOULD be tried in an order defined
    by the weight field.

@type weight: L{int}
@ivar weight: Specifies a relative weight for entries with the same
    priority. Larger weights SHOULD be given a proportionately higher
    probability of being selected.

@type port: L{int}
@ivar port: The port on this target host of this service.

@type target: L{Name}
@ivar target: The domain name of the target host.  There MUST be one or
    more address records for this name, the name MUST NOT be an alias (in
    the sense of RFC 1034 or RFC 2181).  Implementors are urged, but not
    required, to return the address record(s) in the Additional Data
    section.  Unless and until permitted by future standards action, name
    compression is not to be used for this field.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.

@see: U{http://www.faqs.org/rfcs/rfc2782.html}
r3   )priorityweighttargetportrn  )r1  r2  )r3  r3  r  r4  rn  Nc                    [        U5      U l        [        U5      U l        [        U5      U l        [	        U5      U l        [        U5      U l        g)zJ
@param target: See L{Record_SRV.target}
@type target: L{bytes} or L{str}
N)r   r1  r2  r4  rk   r3  r   rn  )r   r1  r2  r4  r3  rn  s         r   r   Record_SRV.__init__  s;    
 H&kI	6lC=r   c                    UR                  [        R                  " SU R                  U R                  U R
                  5      5        U R                  R                  US 5        g N!HHH)r   r   r   r1  r2  r4  r3  r   rB  s      r   r   Record_SRV.encode  s=    FKKt{{DIINO5$'r   c           	         [         R                  " S[        U[         R                  " S5      5      5      nUu  U l        U l        U l        [        5       U l        U R                  R                  U5        g r8  )
r   r   r   r  r1  r2  r4  rk   r3  r   r  s       r   r   Record_SRV.decode  sO    MM&-vv7N"OP01-t{DIf5!r   c                p    [        U R                  U R                  U R                  U R                  45      $ r   )r  r1  r2  r4  r3  r  s    r   r  Record_SRV.__hash__  s&    T]]DKKDKKHIIr   )r4  r1  r3  rn  r2  )r   r   r   r   Nr   )r   r   r   r   r   r3   r   r  rw  r  r   r   r   r  r   r   r   r   r^   r^   [  s4     D DMGVN	!(
"Jr   r^   c                  Z    \ rS rSrSr\rSrSrSr	       SS jr
SS jrSS	 jrS
 rSrg)rW   i  a  
The location of the server(s) for a specific protocol and domain.

@type order: L{int}
@ivar order: An integer specifying the order in which the NAPTR records
    MUST be processed to ensure the correct ordering of rules.  Low numbers
    are processed before high numbers.

@type preference: L{int}
@ivar preference: An integer that specifies the order in which NAPTR
    records with equal "order" values SHOULD be processed, low numbers
    being processed before high numbers.

@type flag: L{Charstr}
@ivar flag: A <character-string> containing flags to control aspects of the
    rewriting and interpretation of the fields in the record.  Flags
    are single characters from the set [A-Z0-9].  The case of the alphabetic
    characters is not significant.

    At this time only four flags, "S", "A", "U", and "P", are defined.

@type service: L{Charstr}
@ivar service: Specifies the service(s) available down this rewrite path.
    It may also specify the particular protocol that is used to talk with a
    service.  A protocol MUST be specified if the flags field states that
    the NAPTR is terminal.

@type regexp: L{Charstr}
@ivar regexp: A STRING containing a substitution expression that is applied
    to the original string held by the client in order to construct the
    next domain name to lookup.

@type replacement: L{Name}
@ivar replacement: The next NAME to query for NAPTR, SRV, or address
    records depending on the value of the flags field.  This MUST be a
    fully qualified domain-name.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.

@see: U{http://www.faqs.org/rfcs/rfc2915.html}
)order
preferenceflagsserviceregexpreplacementr+   )r@  rA  )rB  rB  r  )rC  rC  r  )rD  rD  r  )rE  rE  r  rn  Nc                    [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l
        g)z[
@param replacement: See L{Record_NAPTR.replacement}
@type replacement: L{bytes} or L{str}
N)r   r@  rA  ri   rB  rC  rD  rk   rE  r   rn  )r   r@  rA  rB  rC  rD  rE  rn  s           r   r   Record_NAPTR.__init__  sT     Z
j/U^
w'fo,C=r   c                Z   UR                  [        R                  " SU R                  U R                  5      5        U R
                  R                  US 5        U R                  R                  US 5        U R                  R                  US 5        U R                  R                  US 5        g r@  )
r   r   r   r@  rA  rB  r   rC  rD  rE  rB  s      r   r   Record_NAPTR.encode  su    FKKtzz4??CD

%&E4(5$'t,r   c           	        [         R                  " S[        U[         R                  " S5      5      5      nUu  U l        U l        [        5       U l        [        5       U l        [        5       U l	        [        5       U l        U R                  R                  U5        U R                  R                  U5        U R                  R                  U5        U R                  R                  U5        g r@  )r   r   r   r  r@  rA  ri   rB  rC  rD  rk   rE  r   r  s       r   r   Record_NAPTR.decode  s    MM%ufooe6L!MN&'#
DOY
yi6

% E"5!&r   c                    [        U R                  U R                  U R                  U R                  U R
                  U R                  45      $ r   )r  r@  rA  rB  rC  rD  rE  r  s    r   r  Record_NAPTR.__hash__  s@    



  	
 		
r   )rB  r@  rA  rD  rE  rC  rn  )r   r   r   r   r   r   Nr   )r   r   r   r   r   r+   r   rw  r  r  r   r   r   r  r   r   r   r   rW   rW     sP    *X D MN !,-
'

r   rW   c                  L    \ rS rSrSr\rSrSrSr	SS jr
SS jrSS	 jrS
 rSrg)rL   i  au  
Map from a domain name to the name of an AFS cell database server.

@type subtype: L{int}
@ivar subtype: In the case of subtype 1, the host has an AFS version 3.0
    Volume Location Server for the named AFS cell.  In the case of subtype
    2, the host has an authenticated name server holding the cell-root
    directory node for the named DCE/NCA cell.

@type hostname: L{Name}
@ivar hostname: The domain name of a host that has a server for the cell
    named by this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.

@see: U{http://www.faqs.org/rfcs/rfc1183.html}
r   )subtypehostnamern  )rO  )rP  rP  r  rn  Nc                d    [        U5      U l        [        U5      U l        [	        U5      U l        g)zR
@param hostname: See L{Record_AFSDB.hostname}
@type hostname: L{bytes} or L{str}
N)r   rO  rk   rP  r   rn  )r   rO  rP  rn  s       r   r   Record_AFSDB.__init__6  s%    
 7|XC=r   c                    UR                  [        R                  " SU R                  5      5        U R                  R                  X5        g Nr  )r   r   r   rO  rP  r   rB  s      r   r   Record_AFSDB.encode?  s/    FKKdll34U-r   c           	         [         R                  " S[        U[         R                  " S5      5      5      nUu  U l        U R
                  R                  U5        g rT  )r   r   r   r  rO  rP  r   r  s       r   r   Record_AFSDB.decodeC  s=    MM$eV__T5J KLU#r   c                D    [        U R                  U R                  45      $ r   )r  rO  rP  r  s    r   r  Record_AFSDB.__hash__H  s    T\\4==122r   )rP  rO  rn  r   r   Nr   )r   r   r   r   r   r   r   r  rw  r  r   r   r   r  r   r   r   r   rL   rL     s2    ( DM6GN!.$
3r   rL   c                  L    \ rS rSrSr\rSrSrSr	SS jr
SS jrSS	 jrS
 rSrg)r[   iL  a  
The responsible person for a domain.

@type mbox: L{Name}
@ivar mbox: A domain name that specifies the mailbox for the responsible
    person.

@type txt: L{Name}
@ivar txt: A domain name for which TXT RR's exist (indirection through
    which allows information sharing about the contents of this RP record).

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.

@see: U{http://www.faqs.org/rfcs/rfc1183.html}
r0   )mboxtxtrn  ))r\  r\  r  )r]  r]  r  rn  Nc                d    [        U5      U l        [        U5      U l        [        U5      U l        g)z
@param mbox: See L{Record_RP.mbox}.
@type mbox: L{bytes} or L{str}

@param txt: See L{Record_RP.txt}
@type txt: L{bytes} or L{str}
N)rk   r\  r]  r   rn  )r   r\  r]  rn  s       r   r   Record_RP.__init__f  s%     J	9C=r   c                p    U R                   R                  X5        U R                  R                  X5        g r   )r\  r   r]  rB  s      r   r   Record_RP.encoder  s$    		)(r   c                    [        5       U l        [        5       U l        U R                  R                  U5        U R                  R                  U5        g r   )rk   r\  r]  r   r  s      r   r   Record_RP.decodev  s6    F	6		r   c                D    [        U R                  U R                  45      $ r   )r  r\  r]  r  s    r   r  Record_RP.__hash__|      TYY)**r   )r\  rn  r]  r   r   Nr   )r   r   r   r   r   r0   r   r  rw  r  r   r   r   r  r   r   r   r   r[   r[   L  s2    $ DM.JN
!)+r   r[   c                  x    \ rS rSrSr\rSrS\4S\4S4r	Sr
   S     SS	 jjrSS
 jrSS jrSS jrS rSrg)rO   i  z
Host information.

@type cpu: L{bytes}
@ivar cpu: Specifies the CPU type.

@type os: L{bytes}
@ivar os: Specifies the OS.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
r!   cpuosrn  )ri  rj  rn  Nc                @    XsU l         U l        [        U5      U l        g r   )ri  rj  r   rn  )r   ri  rj  rn  s       r   r   Record_HINFO.__init__  s      $'C=r   c                   UR                  [        R                  " S[        U R                  5      5      U R                  -   5        UR                  [        R                  " S[        U R
                  5      5      U R
                  -   5        g r  )r   r   r   r   ri  rj  rB  s      r   r   Record_HINFO.encode  sR    FKKc$((m4txx?@FKKc$''l3dgg=>r   c                    [         R                  " S[        US5      5      S   n[        X5      U l        [         R                  " S[        US5      5      S   n[        X5      U l        g )Nr  r   r   )r   r   r   ri  rj  )r   r   r   ri  rj  s        r   r   Record_HINFO.decode  sR    mmD-q"9:1= ,]]4ua!89!<*r   c                Z   [        U[        5      (       a  U R                  R                  5       UR                  R                  5       :H  =(       aU    U R                  R                  5       UR                  R                  5       :H  =(       a    U R
                  UR
                  :H  $ [        $ r   )r   rO   rj  r   ri  rn  r  r  s     r   r
  Record_HINFO.__eq__  sq    e\**588>>#33 *HHNN$		(99*HH		)
 r   c                |    [        U R                  R                  5       U R                  R                  5       45      $ r   )r  rj  r   ri  r  s    r   r  Record_HINFO.__hash__  s'    TWW]]_dhhnn&6788r   rg  )ri  r~   rj  r~   rn  r/  r   r  )r   r   r   r   r   r!   r   r  r   r  rw  r   r   r   r
  r  r   r   r   r   rO   rO     so     DMj)D*+=uEN, ,0	!! ! *	!?+9r   rO   c                  T    \ rS rSrSr\rSrSrSr	Sr
SrSS jrSS jrSS	 jrS
 rSrg)rT   i  a  
Mailbox or mail list information.

This is an experimental record type.

@type rmailbx: L{Name}
@ivar rmailbx: A domain-name which specifies a mailbox which is responsible
    for the mailing list or mailbox.  If this domain name names the root,
    the owner of the MINFO RR is responsible for itself.

@type emailbx: L{Name}
@ivar emailbx: A domain-name which specifies a mailbox which is to receive
    error messages related to the mailing list or mailbox specified by the
    owner of the MINFO record.  If this domain name names the root, errors
    should be returned to the sender of the message.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
Nr(   )rmailbxemailbxrn  ))rv  responsibilityr  )rw  errorsr  rn  c                f    [        U5      [        U5      sU l        U l        [        U5      U l        g)z
@param rmailbx: See L{Record_MINFO.rmailbx}.
@type rmailbx: L{bytes} or L{str}

@param emailbx: See L{Record_MINFO.rmailbx}.
@type emailbx: L{bytes} or L{str}
N)rk   rv  rw  r   rn  )r   rv  rw  rn  s       r   r   Record_MINFO.__init__  s'     &*']DM"dlC=r   c                p    U R                   R                  X5        U R                  R                  X5        g r   )rv  r   rw  rB  s      r   r   Record_MINFO.encode  s&    E,E,r   c                    [        5       [        5       sU l        U l        U R                  R                  U5        U R                  R                  U5        g r   )rk   rv  rw  r   r  s      r   r   Record_MINFO.decode  s:    %)VTV"dlE"E"r   c                D    [        U R                  U R                  45      $ r   )r  rv  rw  r  s    r   r  Record_MINFO.__hash__  s    T\\4<<011r   )rw  rv  rn  rg  r   )r   r   r   r   r   r(   r   rv  rw  r  rw  r  r   r   r   r  r   r   r   r   rT   rT     s>    * DGGM5N	!-#
2r   rT   c                  L    \ rS rSrSr\rSrSrSr	SS jr
SS jrSS	 jrS
 rSrg)rV   i  ax  
Mail exchange.

@type preference: L{int}
@ivar preference: Specifies the preference given to this RR among others at
    the same owner.  Lower values are preferred.

@type name: L{Name}
@ivar name: A domain-name which specifies a host willing to act as a mail
    exchange.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be
    cached.
r*   )rA  r   rn  )rA  r  rn  Nc                    [        U5      U l        [        UR                  SU5      5      U l        [        U5      U l        g)zD
@param name: See L{Record_MX.name}.
@type name: L{bytes} or L{str}
exchangeN)r   rA  rk   rO  r   r   rn  )r   rA  r   rn  kwargss        r   r   Record_MX.__init__
  s1    
 j/J56	C=r   c                    UR                  [        R                  " SU R                  5      5        U R                  R                  X5        g rT  )r   r   r   rA  r   r   rB  s      r   r   Record_MX.encode  s/    FKKdoo67		)r   c                    [         R                  " S[        US5      5      S   U l        [	        5       U l        U R
                  R                  U5        g )Nr  r   r   )r   r   r   rA  rk   r   r   r  s      r   r   Record_MX.decode  s;     --mE1.EFqIF			r   c                D    [        U R                  U R                  45      $ r   )r  rA  r   r  s    r   r  Record_MX.__hash__  s    T__dii011r   )r   rA  rn  rZ  r   )r   r   r   r   r   r*   r   r  rw  r  r   r   r   r  r   r   r   r   rV   rV     s2      DM5BN!* 
2r   rV   c                  d    \ rS rSrSrSrSrSr\r	Sr
SrSrS	rSrSrSS
 jrSS jrSS jrS rSrg)r_   i   a  
A record containing the fingerprint of an SSH key.

@type algorithm: L{int}
@ivar algorithm: The SSH key's algorithm, such as L{ALGORITHM_RSA}.
    Note that the numbering used for SSH key algorithms is specific
    to the SSHFP record, and is not the same as the numbering
    used for KEY or SIG records.

@type fingerprintType: L{int}
@ivar fingerprintType: The fingerprint type,
    such as L{FINGERPRINT_TYPE_SHA256}.

@type fingerprint: L{bytes}
@ivar fingerprint: The key's fingerprint, e.g. a 32-byte SHA-256 digest.

@cvar ALGORITHM_RSA: The algorithm value for C{ssh-rsa} keys.
@cvar ALGORITHM_DSS: The algorithm value for C{ssh-dss} keys.
@cvar ALGORITHM_ECDSA: The algorithm value for C{ecdsa-sha2-*} keys.
@cvar ALGORITHM_Ed25519: The algorithm value for C{ed25519} keys.

@cvar FINGERPRINT_TYPE_SHA1: The type for SHA-1 fingerprints.
@cvar FINGERPRINT_TYPE_SHA256: The type for SHA-256 fingerprints.

@see: U{RFC 4255 <https://tools.ietf.org/html/rfc4255>}
      and
      U{RFC 6594 <https://tools.ietf.org/html/rfc6594>}
r5   	algorithmfingerprintTypefingerprintrn  )r  r  r  r   r   r   r   c                4    Xl         X l        X0l        X@l        g r   r  )r   r  r  r  rn  s        r   r   Record_SSHFP.__init__M  s    ".&r   Nc                    UR                  [        R                  " SU R                  U R                  5      5        UR                  U R
                  5        g )N!BB)r   r   r   r  r  r  rB  s      r   r   Record_SSHFP.encodeS  s7    FKKt~~t7K7KLMD$$%r   c                    [         R                  " S[        US5      5      nUu  U l        U l        [        XS-
  5      U l        g )Nr  r   )r   r   r   r  r  r  r  s       r   r   Record_SSHFP.decodeW  s9    MM%ua!8912.-(
;r   c                Z    [        U R                  U R                  U R                  45      $ r   )r  r  r  r  r  s    r   r  Record_SSHFP.__hash__\  s$    T^^T%9%94;K;KLMMr   )r  r  r  rn  )r   r   r   r   r   )r   r   r   r   r   r  rw  r  r5   r   ALGORITHM_RSAALGORITHM_DSSALGORITHM_ECDSAALGORITHM_Ed25519FINGERPRINT_TYPE_SHA1FINGERPRINT_TYPE_SHA256r   r   r   r  r   r   r   r   r_   r_      sT    : MNDNDMMO&<
Nr   r_   c                  P    \ rS rSrSr\rSrS\4S4r	Sr
S rSS	 jrSS
 jrS rSrg)ra   i`  z
Freeform text.

@type data: L{list} of L{bytes}
@ivar data: Freeform text which makes up this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be cached.
r4   r  rn  r  rn  c                d    [        U5      U l        [        UR                  SS 5      5      U l        g )Nrn  )r   r  r   rO  rn  )r   r  kws      r   r   Record_TXT.__init__r  s$    J	BFF5$/0r   Nc           	         U R                    H5  nUR                  [        R                  " S[	        U5      5      U-   5        M7     g r  )r  r   r   r   r   )r   r   r   ds       r   r   Record_TXT.encodew  s0    AKKD#a&1A56 r   c                "   Sn/ U l         X2:  aV  [        R                  " S[        US5      5      S   nU R                   R	                  [        X5      5        X4S-   -  nX2:  a  MV  X2:w  a&  [
        R                  " SX0R                  U4-  5        g g )Nr   r  r   z1Decoded %d bytes in %s record, but rdlength is %d)r  r   r   r   r   r   msgr  )r   r   r   soFarLs        r   r   Record_TXT.decode{  s    	ndM%$;<Q?AII]545UNE n ?GGC,,f56 r   c                >    [        [        U R                  5      5      $ r   )r  tupler  r  s    r   r  Record_TXT.__hash__  s    E$))$%%r   r   )r   r   r   r   r   r4   r   r  r   r  rw  r   r   r   r  r   r   r   r   ra   ra   `  s<     DM~.6N'1
7&r   ra   c                  T    \ rS rSrSrSrSrSrS\4S4r	SS jr
SS	 jrSS
 jrS rSrg)rc   i  a  
Encapsulate the wire data for unknown record types so that they can
pass through the system unchanged.

@type data: L{bytes}
@ivar data: Wire data which makes up this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds which this record should be cached.

@since: 11.1
NUNKNOWNr  r  rn  c                0    Xl         [        U5      U l        g r   )r  r   rn  )r   r  rn  s      r   r   UnknownRecord.__init__  s    	C=r   c                :    UR                  U R                  5        g)zK
Write the raw bytes corresponding to this record's payload to the
stream.
N)r   r  rB  s      r   r   UnknownRecord.encode  s    
 	DIIr   c                @    Uc  [        S5      e[        X5      U l        g)zf
Load the bytes which are part of this record from the stream and store
them unparsed and unmodified.
Nz)must know length for unknown record types)	Exceptionr   r  r  s      r   r   UnknownRecord.decode  s!    
 >GHH!%0	r   c                D    [        U R                  U R                  45      $ r   )r  r  rn  r  s    r   r  UnknownRecord.__hash__  rf  r   r  r   )r   r   r   r   r   r   r  rw  r   r  r   r   r   r  r   r   r   r   rc   rc     s<     DM'z*E2N!1+r   rc   c                       \ rS rSrSr\rSrSrg)r]   i  aO  
Structurally, freeform text. Semantically, a policy definition, formatted
as defined in U{rfc 4408<http://www.faqs.org/rfcs/rfc4408.html>}.

@type data: L{list} of L{bytes}
@ivar data: Freeform text which makes up this record.

@type ttl: L{int}
@ivar ttl: The maximum number of seconds
           which this record should be cached.
r2   r   N)	r   r   r   r   r   r2   r   r  r   r   r   r   r]   r]     s    
 DMr   r]   c                  `    \ rS rSrSrSrSr/ SQr\r	SSSSS\
S	S4S
 jrSS jrSS jrS rSrg)r`   i  a  
A transaction signature, encapsulated in a RR, as described
in U{RFC 2845 <https://tools.ietf.org/html/rfc2845>}.

@type algorithm: L{Name}
@ivar algorithm: The name of the signature or MAC algorithm.

@type timeSigned: L{int}
@ivar timeSigned: Signing time, as seconds from the POSIX epoch.

@type fudge: L{int}
@ivar fudge: Allowable time skew, in seconds.

@type MAC: L{bytes}
@ivar MAC: The message digest or signature.

@type originalID: L{int}
@ivar originalID: A message ID.

@type error: L{int}
@ivar error: An error code (extended C{RCODE}) carried
      in exceptional cases.

@type otherData: L{bytes}
@ivar otherData: Other data carried in exceptional cases.

r6   )r  
timeSignedfudgeMAC
originalIDerror	otherDatarn  )r  r  r  r  r  Nr   r   r   c	                    Uc  S O
[        U5      U l        X l        [        U5      U l        X@l        XPl        X`l        Xpl        Xl	        g r   )
rk   r  r  r   r  r  r  r  r  rn  )	r   r  r  r  r  r  r  r  rn  s	            r   r   Record_TSIG.__init__  s?      "+!2Y$e_
$
"r   c           
     2   U R                   R                  X5        UR                  [        R                  " SU R
                  5      SS  5        UR                  [        R                  " SU R                  [        U R                  5      5      5        UR                  U R                  5        UR                  [        R                  " SU R                  U R                  [        U R                  5      5      5        UR                  U R                  5        g )Nz!Qr   rA  r9  )r  r   r   r   r   r  r  r   r  r  r  r  rB  s      r   r   Record_TSIG.encode	  s    e.FKKdoo6qr:;FKKtzz3txx=ABDHHKKS=PQ	
 	DNN#r   c                P   [        5       nUR                  U5        X0l        [        R                  " SS[        US5      -   5      nUu  U l        U l        n[        X5      U l        [        R                  " S[        US5      5      nUu  U l	        U l
        n[        X5      U l        g )Nz!QHHs     
   r9  r   )rk   r   r  r   r   r   r  r  r  r  r  r  )r   r   r   r  fields	macLengthotherLengths          r   r   Record_TSIG.decode	  s    F	"v{]5"5M'MN17.Y 2v}UA'>?390[&u:r   c                p    [        U R                  U R                  U R                  U R                  45      $ r   )r  r  r  r  r  r  s    r   r  Record_TSIG.__hash__%	  s&    T^^T__dhhPQQr   )r  r  r  r  r  r  r  rn  r   )r   r   r   r   r   r  rw  r  r6   r   rr   r   r   r   r  r   r   r   r   r`   r`     sR    8 M	 NND 2$	;Rr   r`   c                X    U " SUR                   SS.UD6nUR                  SS Ul        U$ )av  
Generate a L{Message} like instance suitable for use as the response to
C{message}.

The C{queries}, C{id} attributes will be copied from C{message} and the
C{answer} flag will be set to L{True}.

@param responseConstructor: A response message constructor with an
     initializer signature matching L{dns.Message.__init__}.
@type responseConstructor: C{callable}

@param message: A request message.
@type message: L{Message}

@param kwargs: Keyword arguments which will be passed to the initialiser
    of the response message.
@type kwargs: L{dict}

@return: A L{Message} like response instance.
@rtype: C{responseConstructor}
T)idanswerNr   )r  queries)responseConstructormessager  responses       r   _responseFromMessager  )	  s2    , #HgjjHHHq)HOr   c                   / n[         R                  " U R                  R                  5      nU HL  nUR                  U   R
                  n[        XU5      nXQ;   d  Xv:w  d  M4  UR                  SU SU< 35        MN     U$ )a  
Inspect the function signature of C{obj}'s constructor,
and get a list of which arguments should be displayed.
This is a helper function for C{_compactRepr}.

@param obj: The instance whose repr is being generated.
@param alwaysShow: A L{list} of field names which should always be shown.
@param fieldNames: A L{list} of field attribute names which should be shown
    if they have non-default values.
@return: A L{list} of displayable arguments.
rM  =)inspect	signature	__class__r   
parametersdefaultry  r   )obj
alwaysShow
fieldNamesdisplayableArgsr  r   defaultValue
fieldValues           r   _getDisplayableArgumentsr  D	  s}     O!!#--"8"89I ++D199S5
J$>""QtfAj^#<=	  r   c                   Uc  / nUc  / nUc  / nUc  / n/ nU H+  nXa;   d  [        XS5      S:X  d  M  UR                  U5        M-     [        XU5      nSU R                  R                  /U-   nU(       a/  UR                  SR                  SR                  U5      5      5        U H0  n[        X/ 5      n	U	(       d  M  UR                  SU SU	< 35        M2     UR                  S5        S	R                  U5      $ )
a  
Return a L{str} representation of C{obj} which only shows fields with
non-default values, flags which are True and sections which have been
explicitly set.

@param obj: The instance whose repr is being generated.
@param alwaysShow: A L{list} of field names which should always be shown.
@param flagNames: A L{list} of flag attribute names which should be shown if
    they are L{True}.
@param fieldNames: A L{list} of field attribute names which should be shown
    if they have non-default values.
@param sectionNames: A L{list} of section attribute names which should be
    shown if they have been assigned a value.

@return: A L{str} representation of C{obj}.
FT<z	 flags={},rM  r  rN   )ry  r   r  r  r   r   r   )
r  r  	flagNamesr  sectionNamessetFlagsr   r  outsections
             r   _compactReprr  \	  s    . 
	
HE!:d!BOOD!  /s
KO&&
'/
9C

;%%chhx&89:#R(7JJ4&'-. 
 JJsO773<r   c                  D   \ rS rSrSrSrSr\R                  " \5      r	S=r
=r=rrSSSSSS\SSSS4S jrSS	 jr\\4S
 jrS rSS jrS r0 r\" 5        H:  r\R5                  S5      (       d  M  \" 5       \   \\" 5       \   R6                  '   M<     CS rS rS rSrg)rj   i	  a  
L{Message} contains all the information represented by a single
DNS request or response.

@ivar id: See L{__init__}
@ivar answer: See L{__init__}
@ivar opCode: See L{__init__}
@ivar recDes: See L{__init__}
@ivar recAv: See L{__init__}
@ivar auth: See L{__init__}
@ivar rCode: See L{__init__}
@ivar trunc: See L{__init__}
@ivar maxSize: See L{__init__}
@ivar authenticData: See L{__init__}
@ivar checkingDisabled: See L{__init__}

@ivar queries: The queries which are being asked of or answered by
    DNS server.
@type queries: L{list} of L{Query}

@ivar answers: Records containing the answers to C{queries} if
    this is a response message.
@type answers: L{list} of L{RRHeader}

@ivar authority: Records containing information about the
    authoritative DNS servers for the names in C{queries}.
@type authority: L{list} of L{RRHeader}

@ivar additional: Records containing IP addresses of host names
    in C{answers} and C{authority}.
@type additional: L{list} of L{RRHeader}

@ivar _flagNames: The names of attributes representing the flag header
    fields.
@ivar _fieldNames: The names of attributes representing non-flag fixed
    header fields.
@ivar _sectionNames: The names of attributes representing the record
    sections of this message.
)r  r  opCoderecDesrecAvr  rCodetruncmaxSizeauthenticDatacheckingDisabledr  answers	authority
additionalz!H2B4HNr      c                    Xl         Xl        X l        X0l        X`l        Xl        X@l        XPl        Xpl        Xl	        Xl
        / U l        / U l        / U l        / U l        g)a	  
@param id: A 16 bit identifier assigned by the program that
    generates any kind of query.  This identifier is copied to
    the corresponding reply and can be used by the requester
    to match up replies to outstanding queries.
@type id: L{int}

@param answer: A one bit field that specifies whether this
    message is a query (0), or a response (1).
@type answer: L{int}

@param opCode: A four bit field that specifies kind of query in
    this message.  This value is set by the originator of a query
    and copied into the response.
@type opCode: L{int}

@param recDes: Recursion Desired - this bit may be set in a
    query and is copied into the response.  If RD is set, it
    directs the name server to pursue the query recursively.
    Recursive query support is optional.
@type recDes: L{int}

@param recAv: Recursion Available - this bit is set or cleared
    in a response and denotes whether recursive query support
    is available in the name server.
@type recAv: L{int}

@param auth: Authoritative Answer - this bit is valid in
    responses and specifies that the responding name server
    is an authority for the domain name in question section.
@type auth: L{int}

@ivar rCode: A response code, used to indicate success or failure in a
    message which is a response from a server to a client request.
@type rCode: C{0 <= int < 16}

@param trunc: A flag indicating that this message was
    truncated due to length greater than that permitted on the
    transmission channel.
@type trunc: L{int}

@param maxSize: The requestor's UDP payload size is the number
    of octets of the largest UDP payload that can be
    reassembled and delivered in the requestor's network
    stack.
@type maxSize: L{int}

@param authenticData: A flag indicating in a response that all
    the data included in the answer and authority portion of
    the response has been authenticated by the server
    according to the policies of that server.
    See U{RFC2535 section-6.1<https://tools.ietf.org/html/rfc2535#section-6.1>}.
@type authenticData: L{int}

@param checkingDisabled: A flag indicating in a query that
    pending (non-authenticated) data is acceptable to the
    resolver sending the query.
    See U{RFC2535 section-6.1<https://tools.ietf.org/html/rfc2535#section-6.1>}.
@type authenticData: L{int}
N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r   r  r  r  r  r  r  r  r  r  r  r  s               r   r   Message.__init__	  sZ    T 	


* 0r   c                    [        U SSSSS9$ )z
Generate a repr of this L{Message}.

Only includes the non-default fields and sections and only includes
flags which are set. The C{id} is always shown.

@return: The native string repr.
)r  r  r  r  r  r  r  )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  s    r   rV  Message.__repr__0
  s$      <J
 	
r   c                N    U R                   R                  [        XU5      5        g)z
Add another query to this Message.

@type name: L{bytes}
@param name: The name to query.

@type type: L{int}
@param type: Query type

@type cls: L{int}
@param cls: Query class
N)r  r   rl   r=  s       r   addQueryMessage.addQueryI
  s     	E$c23r   c                   0 n[        5       nU R                   H  nUR                  X25        M     U R                   H  nUR                  X25        M     U R                   H  nUR                  X25        M     U R
                   H  nUR                  X25        M     UR                  5       n[        U5      U R                  -   nU R                  (       a2  X`R                  :  a#  SU l
        US U R                  U R                  -
   nU R                  S-  S-  U R                  S-  S-  -  U R                  S-  S-  -  U R                  S-  S-  -  U R                  S-  -  nU R                  S-  S-  U R                   S-  S-  -  U R"                  S-  S-  -  U R$                  S-  -  nUR'                  [(        R*                  " U R,                  U R.                  UU[        U R                  5      [        U R                  5      [        U R                  5      [        U R
                  5      5      5        UR'                  U5        g )Nr      rm  r   r   r   r   )r   r  r   r  r  r  rp  r   r"  r  r  r  r  r  r  r  r  r  r  r   r   r   	headerFmtr  )	r   r   r   body_tmpqbodysizebyte3byte4s	            r   r   Message.encodeX
  s   9AHHX( AHHX( AHHX(  AHHX( !  "4y4??*<<D<</DJ8$,,89DkkAo!#c!a')		A!#% 

Q1$& {{Q	  	 jj1n"""Q&1,.%%)a/1 zzC! 	 	KKDLL!DLL!DNN#DOO$		
 	Dr   c                   SU l         [        XR                  5      n[        R                  " U R
                  U5      nUu  U l        pVpxpUS-	  S-  U l        US-	  S-  U l        US-	  S-  U l	        US-	  S-  U l
        US-  U l        US-	  S-  U l        US-	  S-  U l        US-	  S-  U l        US-  U l        / U l        [#        U5       H:  n[%        5       n UR'                  U5        U R                   R+                  U5        M<     U R,                  U4U R.                  U	4U R0                  U
44nU H  u  pU R3                  XU5        M     g ! [(         a       g f = f)	Nr   r	  r   r   rm  r   r   r   )r  r   r"  r   r   r
  r  r  r  r  r  r  r  r  r  r  r  rangerl   r   r   r   r  r  r  parseRecords)r   r   r   headerr  r  r  nqueriesnansnnsnaddir  itemsr   r\  s                   r   r   Message.decode
  s]   uoo6MM$..&1;<8xszQ&zS(aZ1$	qjA%
aiqjA%
#qjA-!&!q 0S[
xAA LL" ! ,,%'<tPT>UVDAaE*   s   E
EEc                   [        U5       H  n[        U R                  S9n UR                  U5        U R                  UR                  5      nU(       d  ML  U" UR                  S9Ul         UR                  R                  X5R                  5        UR                  U5        M     g ! [         a       g f = f! [         a       g f = f)Nr  )rn  )r  rm   r  r   r   lookupRecordTyper   rn  ro  ru  r   )r   r   numr   r  r  rQ  s          r   r  Message.parseRecords
  s    sA499-Fe$ %%fkk2A6::.FN%%e__= KK     s#   B).%B:)
B76B7:
CCRecord_c                B    U R                   R                  U[        5      $ )a  
Retrieve the L{IRecord} implementation for the given record type.

@param type: A record type, such as C{A} or L{NS}.
@type type: L{int}

@return: An object which implements L{IRecord} or L{None} if none
    can be found for the given type.
@rtype: C{Type[IRecord]}
)_recordTypesrO  rc   )r   r   s     r   r  Message.lookupRecordType
  s       $$T=99r   c                X    [        5       nU R                  U5        UR                  5       $ )zb
Encode this L{Message} into a byte string in the format described by RFC
1035.

@rtype: L{bytes}
)r   r   rp  )r   r   s     r   toStrMessage.toStr
  s$     	E~~r   c                <    [        U5      nU R                  U5        g)zf
Decode a byte string in the format described by RFC 1035 into this
L{Message}.

@param str: L{bytes}
N)r   r   )r   r   r   s      r   fromStrMessage.fromStr
  s     Er   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   ) r   r   r   r   r   rw  r
  r   r  r"  r  r  r+  nsrr   r   rV  r=   r<   r  r   r   r  r#  globalsr   
startswithr   r  r&  r)  r   r   r   r   rj   rj   	  s    &P$ I+J $('G'g'b Yv
2 #.2 4*X+: * L	??9%%184L4--.  	:	 r   rj   c                  x    \ rS rSrSrSr\rSS\SSSSSSSSSSSSSS4S jr	SS	 jr
S
 rS r\S 5       rS rSrg)_EDNSMessagei
  ar  
An I{EDNS} message.

Designed for compatibility with L{Message} but with a narrower public
interface.

Most importantly, L{_EDNSMessage.fromStr} will interpret and remove I{OPT}
records that are present in the additional records section.

The I{OPT} records are used to populate certain I{EDNS} specific attributes.

L{_EDNSMessage.toStr} will add suitable I{OPT} records to the additional
section to represent the extended EDNS information.

@see: U{https://tools.ietf.org/html/rfc6891}

@ivar id: See L{__init__}
@ivar answer: See L{__init__}
@ivar opCode: See L{__init__}
@ivar auth: See L{__init__}
@ivar trunc: See L{__init__}
@ivar recDes: See L{__init__}
@ivar recAv: See L{__init__}
@ivar rCode: See L{__init__}
@ivar ednsVersion: See L{__init__}
@ivar dnssecOK: See L{__init__}
@ivar authenticData: See L{__init__}
@ivar checkingDisabled: See L{__init__}
@ivar maxSize: See L{__init__}

@ivar queries: See L{__init__}
@ivar answers: See L{__init__}
@ivar authority: See L{__init__}
@ivar additional: See L{__init__}

@ivar _messageFactory: A constructor of L{Message} instances. Called by
    C{_toMessage} and C{_fromMessage}.
r  r  r  r  r  r  r  r  ednsVersionrb  r  r  r  r  r  r  r  r   Fr  Nc                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Uc  / nXl        Uc  / nXl        Uc  / nUU l        Uc  / nUU l        g)a  
Construct a new L{_EDNSMessage}

@see: U{RFC1035 section-4.1.1<https://tools.ietf.org/html/rfc1035#section-4.1.1>}
@see: U{RFC2535 section-6.1<https://tools.ietf.org/html/rfc2535#section-6.1>}
@see: U{RFC3225 section-3<https://tools.ietf.org/html/rfc3225#section-3>}
@see: U{RFC6891 section-6.1.3<https://tools.ietf.org/html/rfc6891#section-6.1.3>}

@param id: A 16 bit identifier assigned by the program that generates
    any kind of query.  This identifier is copied the corresponding
    reply and can be used by the requester to match up replies to
    outstanding queries.
@type id: L{int}

@param answer: A one bit field that specifies whether this message is a
    query (0), or a response (1).
@type answer: L{bool}

@param opCode: A four bit field that specifies kind of query in this
    message.  This value is set by the originator of a query and copied
    into the response.
@type opCode: L{int}

@param auth: Authoritative Answer - this bit is valid in responses, and
    specifies that the responding name server is an authority for the
    domain name in question section.
@type auth: L{bool}

@param trunc: Truncation - specifies that this message was truncated due
    to length greater than that permitted on the transmission channel.
@type trunc: L{bool}

@param recDes: Recursion Desired - this bit may be set in a query and is
    copied into the response.  If set, it directs the name server to
    pursue the query recursively. Recursive query support is optional.
@type recDes: L{bool}

@param recAv: Recursion Available - this bit is set or cleared in a
    response, and denotes whether recursive query support is available
    in the name server.
@type recAv: L{bool}

@param rCode: Extended 12-bit RCODE. Derived from the 4 bits defined in
    U{RFC1035 4.1.1<https://tools.ietf.org/html/rfc1035#section-4.1.1>}
    and the upper 8bits defined in U{RFC6891
    6.1.3<https://tools.ietf.org/html/rfc6891#section-6.1.3>}.
@type rCode: L{int}

@param ednsVersion: Indicates the EDNS implementation level. Set to
    L{None} to prevent any EDNS attributes and options being added to
    the encoded byte string.
@type ednsVersion: L{int} or L{None}

@param dnssecOK: DNSSEC OK bit as defined by
    U{RFC3225 3<https://tools.ietf.org/html/rfc3225#section-3>}.
@type dnssecOK: L{bool}

@param authenticData: A flag indicating in a response that all the data
    included in the answer and authority portion of the response has
    been authenticated by the server according to the policies of that
    server.
    See U{RFC2535 section-6.1<https://tools.ietf.org/html/rfc2535#section-6.1>}.
@type authenticData: L{bool}

@param checkingDisabled: A flag indicating in a query that pending
    (non-authenticated) data is acceptable to the resolver sending the
    query.
    See U{RFC2535 section-6.1<https://tools.ietf.org/html/rfc2535#section-6.1>}.
@type authenticData: L{bool}

@param maxSize: The requestor's UDP payload size is the number of octets
    of the largest UDP payload that can be reassembled and delivered in
    the requestor's network stack.
@type maxSize: L{int}

@param queries: The L{list} of L{Query} associated with this message.
@type queries: L{list} of L{Query}

@param answers: The L{list} of answers associated with this message.
@type answers: L{list} of L{RRHeader}

@param authority: The L{list} of authority records associated with this
    message.
@type authority: L{list} of L{RRHeader}

@param additional: The L{list} of additional records associated with
    this message.
@type additional: L{list} of L{RRHeader}
Nr0  )r   r  r  r  r  r  r  r  r  r1  rb  r  r  r  r  r  r  r  s                     r   r   _EDNSMessage.__init__   s    Z 	


& * 0?G?GI"J$r   c                    [        U SSSSS9$ )N)r  r  r  r  r  r  r  rb  )r  r  r  r  r1  r   r  r  r  r  s    r   rV  _EDNSMessage.__repr__  s#    	 KJ
 	
r   c                b   U R                  U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  S-  U R                  U R                  S9
nU R                  SS Ul        U R                  SS Ul        U R                  SS Ul        U R                  SS Ul        U R                  bR  [!        U R                  U R"                  U R$                  U R                  S-	  S9nUR                  R'                  U5        U$ )a  
Convert to a standard L{dns.Message}.

If C{ednsVersion} is not None, an L{_OPTHeader} instance containing all
the I{EDNS} specific attributes and options will be appended to the list
of C{additional} records.

@return: A L{dns.Message}
@rtype: L{dns.Message}
rm  )
r  r  r  r  r  r  r  r  r  r  Nr   )ra  rb  r_  r`  )_messageFactoryr  r  r  r  r  r  r  r  r  r  r  r  r  r  r1  rZ  rb  r  r   )r   mrq  s      r   
_toMessage_EDNSMessage._toMessage  s       ww;;;;**;;****s",,!22 ! 
 LLO	LLO	nnQ'q)'((#||"jjAoA LL"r   c                >    U R                  5       R                  5       $ )zf
Encode to wire format by first converting to a standard L{dns.Message}.

@return: A L{bytes} string.
)r9  r&  r  s    r   r&  _EDNSMessage.toStr  s      &&((r   c                   / n/ nUR                    HN  nUR                  [        :X  a&  UR                  [        R                  U5      5        M=  UR                  U5        MP     U " S0 SUR                  _SUR                  _SUR                  _SUR                  _SUR                  _SUR                  _SUR                  _SUR                  _S	UR                  _S
UR                  _SS_SS_SUR                   SS _SUR"                  SS _SUR$                  SS _SU_6n['        U5      S:X  aY  US   nUR(                  Ul        UR,                  Ul        UR.                  Ul        UR2                  S-  UR                  -  Ul        U$ )aP  
Construct and return a new L{_EDNSMessage} whose attributes and records
are derived from the attributes and records of C{message} (a L{Message}
instance).

If present, an C{OPT} record will be extracted from the C{additional}
section and its attributes and options will be used to set the EDNS
specific attributes C{extendedRCODE}, C{ednsVersion}, C{dnssecOK},
C{ednsOptions}.

The C{extendedRCODE} will be combined with C{message.rCode} and assigned
to C{self.rCode}.

@param message: The source L{Message}.
@type message: L{Message}

@return: A new L{_EDNSMessage}
@rtype: L{_EDNSMessage}
r  r  r  r  r  r  r  r  r  r  r1  Nrb  Fr  r  r  r  r   r   r   r   )r  r   r.   r   rZ  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r   ra  r1  rb  r_  r  r`  )r<  r  r  
optRecordsr  
newMessageopts          r   _fromMessage_EDNSMessage._fromMessage  s   * 

##Avv}!!*"9"9!"<=!!!$	 $  
zz
>>
 >>
 	

 --
 >>
 --
 --
 "//
 %55
 
 
 OOA&
  OOA&!
" ''*#
$ "%

* z?a Q-C%([[J""%,,J!$!3!3J"00A5EJr   c           	         U R                  5       nUR                  U5        U R                  U5      nU R                   H  n[	        X[        X45      5        M     g)z
Decode from wire format, saving flags, values and records to this
L{_EDNSMessage} instance in place.

@param bytes: The full byte string to be decoded.
@type bytes: L{bytes}
N)r7  r)  rA  rw  rx  ry  )r   r~   r8  ednsMessager|  s        r   r)  _EDNSMessage.fromStr,  sM       "			%''*..HDGK$BC /r   )r  r  r  r  r  r  r  rb  r1  r  r  r  r  r  r  r  r  r  )r   r   r   r   r   rw  rj   r7  ru   r   rV  r9  r&  r  rA  r)  r   r   r   r   r/  r/  
  s~    %N( O %I%V
$(T) : :xDr   r/  c                  B    \ rS rSrSrSrSrS
S jrS rS r	S r
S rS	rg)rp   i<  z
DNS protocol mixin shared by UDP and TCP implementations.

@ivar _reactor: A L{IReactorTime} and L{IReactorUDP} provider which will
    be used to issue DNS queries and manage request timeouts.
Nc                f    Xl         [        R                  " SS5      U l        Uc  SSKJn  X l        g )Ni   i   r   )reactor)
controllerrandom	randranger  twisted.internetrH  _reactor)r   rI  rH  s      r   r   DNSMixin.__init__G  s(    $""5%0?0r   c                >     [        5       nXR                  ;  a  U$ M  )z!
Return a unique ID for queries.
)r   liveMessagesr   r  s     r   pickIDDNSMixin.pickIDN  s$     B***	 r   c                <    U R                   R                  " X/UQ76 $ )z<
Wrapper around reactor.callLater, mainly for test purpose.
)rM  	callLater)r   periodfuncargss       r   rU  DNSMixin.callLaterW  s     }}&&v;d;;r   c                   [        USS9nXl         U" U5        [        R
                  " 5       nU R                  X R                  Xc5      nXg4U R                  U'   U$ ! [         a    [        R                  " 5       s $ f = f)aJ  
Send out a message with the given queries.

@type queries: L{list} of C{Query} instances
@param queries: The queries to transmit

@type timeout: L{int} or C{float}
@param timeout: How long to wait before giving up

@type id: L{int}
@param id: Unique key for this request

@type writeMessage: C{callable}
@param writeMessage: One-parameter callback which writes the message

@rtype: C{Deferred}
@return: a C{Deferred} which will be fired with the result of the
    query, or errbacked with any errors that could happen (exceptions
    during writing of the query, timeout errors, ...).
r   )r  )	rj   r  BaseExceptionr   failDeferredrU  _clearFailedrP  )r   r  timeoutr  writeMessager8  resultDeferred
cancelCalls           r   _queryDNSMixin._query]  s{    * Bq!		 O )^^G->->S
!/ <"  	 ::<	 s   A A?>A?c                     U R                   U	 UR                  [        R                  " [        U5      5      5        g! [         a     N;f = f)z%
Clean the Deferred after a timeout.
N)rP  KeyErrorerrbackr   Failurerz   )r   deferredr  s      r   r^  DNSMixin._clearFailed  sH    	!!"% 	)=b)ABC  		s   > 
A
A)rM  rI  r  r   )r   r   r   r   r   r  rP  r   rR  rU  rc  r^  r   r   r   r   rp   rp   <  s.     
BL <!FDr   rp   c                  J    \ rS rSrSrSrS rS rS rS r	S r
S	 rSS
 jrSrg)ro   i  z
DNS protocol over UDP.
Nc                .    0 U l         0 U l        SU l        g)z'
Stop protocol: reset state variables.
NrP  resends	transportr  s    r   stopProtocol DNSDatagramProtocol.stopProtocol  s     r   c                     0 U l         0 U l        g)z#
Upon start, reset internal state.
N)rP  rn  r  s    r   startProtocol!DNSDatagramProtocol.startProtocol  s     r   c                X    U R                   R                  UR                  5       U5        g)@
Send a message holding DNS queries.

@type message: L{Message}
N)ro  r   r&  )r   r  r  s      r   r`   DNSDatagramProtocol.writeMessage  s     	W]]_g6r   c                :    U R                   R                  SU SS9  g )Nr   r  )maxPacketSize)rM  	listenUDPr  s    r   startListening"DNSDatagramProtocol.startListening  s    4s;r   c                    [        5       n UR                  U5        UR                  U R                  ;   aU  U R                  UR                     u  pVU R                  UR                  	 UR                  5          UR                  U5        gUR                  U R                  ;  a  U R                   R#                  X0U5        gg! [         a'    [        R                  " S[        U5      U4-  5         g[         a&  n[        R                  " SU SU 35         SnAgSnAf[         a-    [        R                  " [        R                  " 5       S5         gf = f! [         a    [        R                  " 5          gf = f)zQ
Read a datagram, extract the message in it and trigger the associated
Deferred.
z#Truncated packet (%d bytes) from %sNzInvalid packet (z) from zUnexpected decoding error)rj   r)  r   r   r  r   r   r[  errr   rh  r  rP  cancelcallbackrn  rI  messageReceived)r   r  addrr8  exr  	cancellers          r   datagramReceived$DNSDatagramProtocol.datagramReceived  s/   
 I	IIdO 444$$$,,QTT2LA!!!$$'

1 tt4<<'//> (1  	GG9SY<MMN 	GG&rd'$89 	
 GGGOO%'BC	 ! 	s5   C :E .E4	E=D7EEE=<E=c                @     U R                   U	 g! [         a     gf = f)z>
Mark message ID as no longer having duplication suppression.
N)rn  rf  rQ  s     r   removeResend DNSDatagramProtocol.removeResend  s%    	R  		s    
c                  ^ ^ T R                   (       d   T R                  5         Uc  T R                  5       nOST R                  U'   UU 4S jnT R                  X#XE5      $ ! [         a    [        R                  " 5       s $ f = f)z
Send out a message with the given queries.

@type address: L{tuple} of L{str} and L{int}
@param address: The address to which to send the query

@type queries: L{list} of C{Query} instances
@param queries: The queries to transmit

@rtype: C{Deferred}
r   c                *   > TR                  U T5        g r   )r`  )r8  r  r   s    r   r`  /DNSDatagramProtocol.query.<locals>.writeMessage  s    a)r   )ro  r{  r   r   r\  rR  rn  rc  )r   r  r  r_  r  r`  s   ``    r   queryDNSDatagramProtocol.query  sr     ~~$##% :B DLL	* {{7R>> % $zz|#$s   A! !BBrm  )r  N)r   r   r   r   r   rn  rp  rs  r`  r{  r  r  r  r   r   r   r   ro   ro     s2     G7<!?F?r   ro   c                  B    \ rS rSrSrSrSrS rS rS r	S r
SS	 jrS
rg)rq   i  z
DNS protocol over TCP.
Nr   c                    UR                  5       nU R                  R                  [        R                  " S[        U5      5      U-   5        g)rv  r  N)r&  ro  r   r   r   r   )r   r  r   s      r   r`  DNSProtocol.writeMessage  s5     MMOV[[s1v6:;r   c                H    0 U l         U R                  R                  U 5        g)zF
Connection is made: reset internal state, and notify the controller.
N)rP  rI  connectionMader  s    r   r  DNSProtocol.connectionMade  s     &&t,r   c                :    U R                   R                  U 5        g)zB
Notify the controller that this protocol is no longer
connected.
N)rI  connectionLost)r   reasons     r   r  DNSProtocol.connectionLost  s    
 	&&t,r   c                   U =R                   U-  sl         U R                   (       GaN  U R                  cY  [        U R                   5      S:  a@  [        R                  " SU R                   S S 5      S   U l        U R                   SS  U l         [        U R                   5      U R                  :  a  U R                   S U R                   n[        5       nUR                  U5         U R                  UR                     u  pEU R                  UR                  	 UR                  5          UR                  U5        U R                   U R                  S  U l         S U l        Og U R                   (       a  GMM  g g ! [         a    [        R                  " 5          N^f = f! [         a    U R                  R!                  X05         Nf = f)Nr   r  r   )bufferr   r   r   r   rj   r)  rP  r  r  r  r[  r   r~  rf  rI  r  )r   r  myChunkr8  r  r  s         r   dataReceivedDNSProtocol.dataReceived  sU   tkkk{{"s4;;'71'<$mmD$++bq/B1E"kk!"o4;;4;;.++m4I		'""#'#4#4QTT#:LA ))!$$/$$&"

1 #kk$++-8"5 kkk( ) "	"   =OO33A<=s$   &F )E7 7FF%GGc                Z    U R                  5       nU R                  XX0R                  5      $ )z
Send out a message with the given queries.

@type queries: L{list} of C{Query} instances
@param queries: The queries to transmit

@rtype: C{Deferred}
)rR  rc  r`  )r   r  r_  r  s       r   r  DNSProtocol.query4  s&     [[]{{7R1B1BCCr   )r  r   rP  )r   )r   r   r   r   r   r   r  r`  r  r  r  r  r   r   r   r   rq   rq     s-     FF<-->
Dr   rq   )r   zstr | bytesr  r~   )r   r   r  r   )r   zUnion[str, bytes, int]r  r   )r   Noner  r  )r   r/  r  zUnion[int, None])NNNN)r  r  r  Sequence[str] | Noner  r  r  r  r  r  r  r   )r   
__future__r   r  rJ  r  r   ior   	itertoolsr   typingr   r   r   r	   r
   zope.interfacer   r   r   rL  r   r   twisted.internet.errorr   twisted.pythonr   r   r   r   tputiltwisted.python.compatr   r   r   __all__r  r   r   r   r   rx   r  r   r,   r%   r&   r   r1   r$   r'   r)   r-   r7   r/   r!   r(   r*   r4   r0   r   r   r3   r+   r   r    r.   r5   r2   r   r6   re   r?   r>   r#   r"   r=   rh   r  rg   r<   r:   r9   r;   r8   rd   rf   ru   rs   rv   rt   rw   rr   r@   rD   rA   rB   rC   rE   rF   rG   rH   r   twisted.names.errorry   rz   r{   r   r   r   r   r   r   r   r   ri   rk   rl   FancyStrMixinFancyEqMixinrZ  r  rm   rn   rX   rQ   rR   rM   rP   rS   rU   rZ   rN   rI   r\   rY   rb   rK   rJ   r^   rW   rL   r[   rO   rT   rV   r_   ra   rc   r]   r`   r  r  r  rj   r/  rp   DatagramProtocolro   Protocolrq   )kvs   00r   <module>r     s1	  
 #       C C < < - 4 B B ? ?eP ??CK 
* 
!RL'					


 
s  	
 
7     	&   
7 
7   !" #$ 
7&	7	7	7&&;@ ).c3 %dE5+ 	&&	7	7 !&k&7&7&9;;L;L;N OP OfqQT OP	q!BB	T2tRr4eD"/"5"5"78"7qt"78 #(( *i		 27q .GWeWh"2r] (Ei E (BF<B, 
 
 
 
4$ $Nz7  Z.) .) .)b Zc' c' c'L Z9I 9I  9Ix Zw
%%v':': w
 w
t Z91--v/B/B 91 91x Zwv"" w wt "6'')<)< " "L 
 

 
<     <   ..v"" .. ..b p
$$f&:&: p
 p
f "&&&(;(; " "> 9=$$f&:&: 9= 9=x +"&%%v';'; +" +"\ `
$$f&9&9 `
 `
F @J$$f&:&: @J @JF w
6&&(<(< w
 w
t .36'')<)< .3 .3b 0+##V%9%9 0+ 0+f 296'')<)< 29 29j 826&&(<(< 82 82v *2$$f&9&9 *2 *2Z <N6&&(<(< <N <N~ (&$$f&:&: (& (&V )+F'')=)= )+ )+X " [R&%%v';'; [R [R|64 (,&*'+)-5	5$5 $5 %	5
 '5 	5pKf!! K\
WD6&& WDt
LD LD^h?(H$=$= h?VHD(H-- HDg_ Q 9s   ?Z: [ 