+
    Dfj0                         R t ^ RIHt ^ RIHtHtHt ^ RIHt  ! R R4      t	 ! R R]P                  4      tR t ! R	 R
4      tRR ltR# )z
Resolver implementation for querying successive authoritative servers to
lookup a record, starting from the root nameservers.

@author: Jp Calderone

todo::
    robustify it
    documentation
)defer)commondnserror)Failurec                   *   a  ] tR t^t o RtR tRtV tR# )_DummyControllerz
A do-nothing DNS controller.  This is useful when all messages received
will be responses to previously issued queries.  Anything else received
will be ignored.
c                    R # N )selfargss   &*4/usr/lib/python3/dist-packages/twisted/names/root.pymessageReceived _DummyController.messageReceived   s        r   N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classdictcell____classdict__s   @r   r   r      s      r   r   c                   L   a  ] tR t^ t o RtR
R ltR tR tR tR t	R t
R	tV tR# )ResolveraS  
L{Resolver} implements recursive lookup starting from a specified list of
root servers.

@ivar hints: See C{hints} parameter of L{__init__}
@ivar _maximumQueries: See C{maximumQueries} parameter of L{__init__}
@ivar _reactor: See C{reactor} parameter of L{__init__}
@ivar _resolverFactory: See C{resolverFactory} parameter of L{__init__}
Nc                    \         P                  P                  V 4       Wn        W n        W0n        Vf   ^ RIHp W@n        R# )a  
@param hints: A L{list} of L{str} giving the dotted quad
    representation of IP addresses of root servers at which to
    begin resolving names.
@type hints: L{list} of L{str}

@param maximumQueries: An optional L{int} giving the maximum
     number of queries which will be attempted to resolve a
     single name.
@type maximumQueries: L{int}

@param reactor: An optional L{IReactorTime} and L{IReactorUDP}
     provider to use to bind UDP ports and manage timeouts.
@type reactor: L{IReactorTime} and L{IReactorUDP} provider

@param resolverFactory: An optional callable which accepts C{reactor}
     and C{servers} arguments and returns an instance that provides a
     C{queryUDP} method. Defaults to L{twisted.names.client.Resolver}.
@type resolverFactory: callable
Nr   )	r   ResolverBase__init__hints_maximumQueries_reactortwisted.names.clientr   _resolverFactory)r   r!   maximumQueriesreactorresolverFactorys   &&&&&r   r    Resolver.__init__+   s7    * 	$$T*
-"H /r   c                b    V P                    Uu. uF  q\        P                  3NK  	  up# u upi )zj
Return a list of two-tuples representing the addresses of the root
servers, as defined by C{self.hints}.
)r!   r   PORT)r   ips   & r   _rootsResolver._rootsH   s&    
 *.42SXX444s   ,c                    V P                  W P                  R7      pVP                  V.V4      pV'       d   VP                  VP                  4       V# )a  
Issue one query and return a L{Deferred} which fires with its response.

@param query: The query to issue.
@type query: L{dns.Query}

@param servers: The servers which might have an answer for this
    query.
@type servers: L{list} of L{tuple} of L{str} and L{int}

@param timeout: A timeout on how long to wait for the response.
@type timeout: L{tuple} of L{int}

@param filter: A flag indicating whether to filter the results.  If
    C{True}, the returned L{Deferred} will fire with a three-tuple of
    lists of L{twisted.names.dns.RRHeader} (like the return value of
    the I{lookup*} methods of L{IResolver}.  IF C{False}, the result
    will be a L{Message} instance.
@type filter: L{bool}

@return: A L{Deferred} which fires with the response or a timeout
    error.
@rtype: L{Deferred}
)serversr'   )r%   r#   queryUDPaddCallbackfilterAnswers)r   queryr0   timeoutfilterrds   &&&&&  r   _queryResolver._queryO   sE    2 !!'==!IJJw(MM!//*r   c                    Vf   RpV P                  \        P                  ! WV4      V P                  4       W@P                  4      # )z
Implement name lookup by recursively discovering the authoritative
server for the name and then asking it, starting at one of the servers
in C{self.hints}.
)         -   )_discoverAuthorityr   Queryr-   r"   )r   nameclstyper5   s   &&&&&r   _lookupResolver._lookupn   sA     ? %G&&IId#&w@T@T
 	
r   c                    V^ 8:  d    \        \        P                  ! R4      4      # V P                  WVR4      pVP	                  V P
                  WV^,
          4       V# )a  
Issue a query to a server and follow a delegation if necessary.

@param query: The query to issue.
@type query: L{dns.Query}

@param servers: The servers which might have an answer for this
    query.
@type servers: L{list} of L{tuple} of L{str} and L{int}

@param timeout: A C{tuple} of C{int} giving the timeout to use for this
    query.

@param queriesLeft: A C{int} giving the number of queries which may
    yet be attempted to answer this query before the attempt will be
    abandoned.

@return: A L{Deferred} which fires with a three-tuple of lists of
    L{twisted.names.dns.RRHeader} giving the response, or with a
    L{Failure} if there is a timeout or response error.
z"Query limit reached without resultF)r   r   ResolverErrorr9   r2   _discoveredAuthority)r   r4   r0   r5   queriesLeftr8   s   &&&&& r   r@   Resolver._discoverAuthority|   sT    . !5../STUUKK7	d//qQr   c                  a aaaaa VP                   \        P                  8w  d+   \        S P	                  VP                   4      ! V4      4      # / oVP
                   F.  pSP                  VP                  . 4      P                  V4       K0  	  V3R lp\        4       pSP                  pRp	 VP                  V4       V	oV! VSP                  SP                  4      p	V	f   VSP                  8X  d   MS P                  \        P                  ! \        V4      SP                  SP                  4      S P!                  4       SS4      p
V3R lpV
P#                  V4       V
# V	P                  SP                  8X  d$   VP
                  VP$                  VP&                  3# V	P(                  P                  V9   d   \*        P,                  ! R4      hV	P(                  P                  pEK>  / pVP&                   FT  pVP                  \        P.                  8X  g   K$  VP(                  P1                  4       WP                  P                  &   KV  	  . p. pVP$                   F  pVP                  \        P2                  8X  g   K$  VP(                  P                  P                  pVV9   d+   VP                  VV,          \        P4                  34       Ku  VP                  V4       K  	  V'       d   S P                  SVSS4      # V'       dH   S P7                  V^ ,          S4      p
R pV
P#                  V4       V
P#                  VVV V3R l4       V
# \        \*        P,                  ! R4      4      # )a  
Interpret the response to a query, checking for error codes and
following delegations if necessary.

@param response: The L{Message} received in response to issuing C{query}.
@type response: L{Message}

@param query: The L{dns.Query} which was issued.
@type query: L{dns.Query}.

@param timeout: The timeout to use if another query is indicated by
    this response.
@type timeout: L{tuple} of L{int}

@param queriesLeft: A C{int} giving the number of queries which may
    yet be attempted to answer this query before the attempt will be
    abandoned.

@return: A L{Failure} indicating a response error, a three-tuple of
    lists of L{twisted.names.dns.RRHeader} giving the response to
    C{query} or a L{Deferred} which will fire with one of those.
c                    < R pSP                  V . 4       FN  pVP                  V8X  g   K  VP                  V8X  d   Vu # VP                  \        P                  8X  g   KL  TpKP  	  V# r
   )getrC   rD   r   CNAME)rB   rD   rC   cnamerecordrecordss   &&&  r   findAnswerOrCName8Resolver._discoveredAuthority.<locals>.findAnswerOrCName   sV    E!++dB/::${{d*%		1 & 0 Lr   Nc                 :   < V w  rpVP                  ^ S4       WV3#     )insert)resultsanswers	authority
additionalpreviouss   &   r   
cbResolved1Resolver._discoveredAuthority.<locals>.cbResolved   s&    9@6Jq(3 'J??r   zCycle in CNAME processingc                 N    V w  rpV^ ,          P                   P                  4       # rV   )payload
dottedQuad)rY   rZ   r[   r\   s   &   r   getOneAddress4Resolver._discoveredAuthority.<locals>.getOneAddress   s%    18.Jqz))4466r   c                 \   < SP                  SV \        P                  3.SS^,
          4      # )r<   )r@   r   r+   )hintrJ   r4   r   r5   s   &r   <lambda>/Resolver._discoveredAuthority.<locals>.<lambda>  s)    T44T388,-war   z/Stuck at response without answers or delegation)rCoder   OKr   exceptionForCoderZ   
setdefaultrB   appendsetaddrD   rC   r@   rA   strr-   r2   r[   r\   ra   r   rH   Arb   NSr+   lookupAddress)r   responser4   r5   rJ   answerrS   seenrB   rQ   r8   r^   	addressesrrr!   trapsnsrc   r]   rR   s   f&fff             @@r   rI   Resolver._discoveredAuthority   s   . >>SVV#400@JKK &&Fv{{B/66v> '
	 uzzHHTNH&tUZZCF~5::%  //		#d)UZZC#	A@
 MM*-H

* (((*<*<h>Q>QRR >>&&$.--.IJJ~~** 	%%Bww#%%*,***?*?*A	'',,' & $$Bww#&& ZZ__))?LL)B-!:;LL$ % **5%+NN""58W5A7 MM-(MM
 H##$UV r   )r"   r#   r%   r!   )
   NN)r   r   r   r   r   r    r-   r9   rE   r@   rI   r   r   r   s   @r   r   r       s/     0:5>
<t tr   r   c                    a a V V3R  lpV# )c                  :   <a a SP                  V VV3R  l4       S# )c                 (   < \        V S4      ! S/ SB # r
   )getattr)r7   r   kwrB   s   &r   rg   6makePlaceholder.<locals>.placeholder.<locals>.<lambda>  s    wq$'7'D'Dr   )r2   )r   r   deferredrB   s   jlr   placeholder$makePlaceholder.<locals>.placeholder  s    DEr   r   )r   rB   r   s   ff r   makePlaceholderr     s     r   c                   2   a  ] tR tRt o R tR tR tRtV tR# )DeferredResolveri  c                J    . V n         VP                  V P                  4       R # r
   )waitingr2   gotRealResolver)r   resolverDeferreds   &&r   r    DeferredResolver.__init__  s    $$T%9%9:r   c                    V P                   pVP                  V n        VP                  V n        V F  pVP                  V4       K  	  R # r
   )r   __dict__	__class__callback)r   resolverwr8   s   &&  r   r    DeferredResolver.gotRealResolver  s;    LL ))!++AJJx  r   c                    VP                  R 4      '       g   VR9   dL   V P                  P                  \        P                  ! 4       4       \        V P                  R,          V4      # \        V4      h)lookup)getHostByNamer4   )
startswithr   rm   r   Deferredr   AttributeError)r   rB   s   &&r   __getattr__DeferredResolver.__getattr__%  sS    ??8$$0J(JLL 01"4<<#3T::T""r   )r   r   r   N)	r   r   r   r   r    r   r   r   r   r   s   @r   r   r     s     ;!# #r   r   Nc                >  a \        ^4       Uu. uF  p\        \        R4      V,           4      NK   	  ppV Uu. uF  q@P                  RV,          4      NK  	  pp\        P
                  ! VRR7      pV3R lpVP                  V4       \        V4      # u upi u upi )a  
Lookup the root nameserver addresses using the given resolver

Return a Resolver which will eventually become a C{root.Resolver}
instance that has references to all the root servers that we were able
to look up.

@param resolver: The resolver instance which will be used to
    lookup the root nameserver addresses.
@type resolver: L{twisted.internet.interfaces.IResolverSimple}

@param resolverFactory: An optional callable which returns a
    resolver instance. It will passed as the C{resolverFactory}
    argument to L{Resolver.__init__}.
@type resolverFactory: callable

@return: A L{DeferredResolver} which will be dynamically replaced
    with L{Resolver} when the root nameservers have been looked up.
az%s.root-servers.netT)consumeErrorsc                 v   < \        V  Uu. uF  q^ ,          '       g   K  V^,          NK  	  upSR7      # u upi )rW   )r!   r(   r   )reser(   s   & r   buildResolver bootstrap.<locals>.buildResolverD  s5    !$-A!41Q44-
 	
-s   66)rangechrordr   r   DeferredListr2   r   )r   r(   idomainsr8   Lr   s   &f     r   	bootstrapr   ,  s    ( +0)4)Qs3s8a< )G4DKLGq		 5 9	:GAL1D1A

 MM- A 5Ls
   $B Br
   )r   twisted.internetr   twisted.namesr   r   r   twisted.python.failurer   r   r   r   r   r   r   r   r   r   <module>r      sK   
	 # , , * nv"" nb# #&r   