ó
    Ö›‘hˆ0  ã                   ó–   • S r SSKJr  SSKJrJrJr  SSKJr   " S S5      r	 " S S\R                  5      rS	 r " S
 S5      rSS jrg)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                   ó   • \ rS rSrSrS rSrg)Ú_DummyControlleré   z¢
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                 ó   • g ©N© )ÚselfÚargss     ÚVC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/names/root.pyÚmessageReceivedÚ _DummyController.messageReceived   s   € Øó    r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__r   r   r   r	   r	      s   † ñõr   r	   c                   ó@   • \ rS rSrSrSS jrS rS rS rS r	S	 r
S
rg)ÚResolveré    aS  
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                 ó„   • [         R                  R                  U 5        Xl        X l        X0l        Uc  SSKJn  X@l        g)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
Nr   ©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                 ód   • U R                    Vs/ s H  o[        R                  4PM     sn$ s  snf )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ª 2”S—X‘X“©Ñ4Ð4ùÒ4s   �-c                 ó¢   • U R                  X R                  S9nUR                  U/U5      nU(       a  UR                  UR                  5        U$ )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ˆØ�J‰J˜�w Ó(ˆÞØ�M‰M˜!Ÿ/™/Ô*Øˆr   c                 óŒ   • Uc  SnU R                  [        R                  " XU5      U R                  5       X@R                  5      $ )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Ø×&Ñ&Ü�IŠI�d #Ó&¨¯©«°w×@TÑ@Tó
ð 	
r   c                 ó¶   • US::  a  [        [        R                  " S5      5      $ U R                  XUS5      nUR	                  U R
                  XUS-
  5        U$ )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.
r   z"Query limit reached without resultFr<   )r   r   ÚResolverErrorr9   r2   Ú_discoveredAuthority)r   r4   r0   r5   ÚqueriesLeftr8   s         r   r@   ÚResolver._discoverAuthority|   sT   € ð. ˜!ÓÜœ5×.Ò.Ð/SÓTÓUÐUà�K‰K˜¨°Ó7ˆØ	�‰�d×/Ñ/°ÀÈqÁÔQØˆr   c                 óÈ  ^ ^^^^^• UR                   [        R                  :w  a*  [        T R	                  UR                   5      " U5      5      $ 0 mUR
                   H.  nTR                  UR                  / 5      R                  U5        M0     U4S jn[        5       nTR                  nSn	 UR                  U5        U	mU" UTR                  TR                  5      n	U	c  UTR                  :X  a  OôT R                  [        R                  " [        U5      TR                  TR                  5      T R!                  5       TT5      n
U4S jnU
R#                  U5        U
$ U	R                  TR                  :X  a#  UR
                  UR$                  UR&                  4$ U	R(                  R                  U;   a  [*        R,                  " S5      eU	R(                  R                  nGM9  0 nUR&                   HS  nUR                  [        R.                  :X  d  M#  UR(                  R1                  5       XÍR                  R                  '   MU     / n/ nUR$                   H€  nUR                  [        R2                  :X  d  M#  UR(                  R                  R                  nUU;   a&  UR                  UU   [        R4                  45        Mo  UR                  U5        M‚     U(       a  T R                  TUTT5      $ U(       aC  T R7                  US   T5      n
S nU
R#                  U5        U
R#                  UUU U4S j5        U
$ [        [*        R,                  " S5      5      $ )	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                 óÎ   >• S nTR                  U / 5       HK  nUR                  U:X  d  M  UR                  U:X  a  Us  $ UR                  [        R                  :X  d  MI  UnMM     U$ r   )ÚgetrC   rD   r   ÚCNAME)rB   rD   rC   ÚcnameÚrecordÚrecordss        €r   ÚfindAnswerOrCNameÚ8Resolver._discoveredAuthority.<locals>.findAnswerOrCName¹   sV   ø€ ØˆEØ!Ÿ+™+ d¨BÖ/�Ø—:‘: Õ$Ø—{‘{ dÓ*Ø%šØŸ™¬¯	©	Õ1Ø &šñ 0ð ˆLr   Nc                 ó:   >• U u  pnUR                  ST5        XU4$ ©Nr   )Úinsert)ÚresultsÚanswersÚ	authorityÚ
additionalÚpreviouss       €r   Ú
cbResolvedÚ1Resolver._discoveredAuthority.<locals>.cbResolvedÜ   s&   ø€ Ø9@Ñ6˜¨JØŸ™ q¨(Ô3Ø '°JÐ?Ð?r   zCycle in CNAME processingr   c                 óF   • U u  pnUS   R                   R                  5       $ rV   )ÚpayloadÚ
dottedQuad)rX   rY   rZ   r[   s       r   ÚgetOneAddressÚ4Resolver._discoveredAuthority.<locals>.getOneAddress   s%   € Ø18Ñ.� JØ˜q‘z×)Ñ)×4Ñ4Ó6Ð6r   c                 óT   >• TR                  TU [        R                  4/TTS-
  5      $ )Nr<   )r@   r   r+   )ÚhintrJ   r4   r   r5   s    €€€€r   Ú<lambda>Ú/Resolver._discoveredAuthority.<locals>.<lambda>  s)   ø€ ˜T×4Ñ4Ø˜T¤3§8¡8Ð,Ð-¨w¸Àa¹ôr   z/Stuck at response without answers or delegation)ÚrCoder   ÚOKr   ÚexceptionForCoderY   Ú
setdefaultrB   ÚappendÚsetÚaddrD   rC   r@   rA   Ústrr-   r2   rZ   r[   r`   r   rH   ÚAra   ÚNSr+   ÚlookupAddress)r   Úresponser4   r5   rJ   ÚanswerrS   ÚseenrB   rQ   r8   r]   Ú	addressesÚrrr!   ÚtrapsÚnsrb   r\   rR   s   ` ```             @@r   rI   ÚResolver._discoveredAuthorityš   s±  ý€ ð. �>‰>œSŸV™VÓ#Ü˜4×0Ñ0°·±Ô@ÀÓJÓKÐKð ˆØ×&Ô&ˆFØ×Ñ˜vŸ{™{¨BÓ/×6Ñ6°vÖ>ñ 'õ
	ô ‹uˆØ�z‰zˆØˆØØ�H‰H�TŒNØˆHÙ& t¨U¯Z©Z¸¿¹ÓCˆFØ‰~Ø˜5Ÿ:™:Ó%ð ð ×/Ñ/ÜŸ	š	¤# d£)¨U¯Z©Z¸¿¹ÓCØŸ™›ØØ#ó	�Aõ@ð
 —M‘M *Ô-Ø�HØ—‘ §
¡
Ó*Ø ×(Ñ(¨(×*<Ñ*<¸h×>QÑ>QÐRÐRð —>‘>×&Ñ&¨$Ó.Ü×-Ò-Ð.IÓJÐJØ—~‘~×*Ñ*�òE ðJ ˆ	Ø×%Ô%ˆBØ�w‰wœ#Ÿ%™%ÕØ*,¯*©*×*?Ñ*?Ó*A�	Ÿ'™'Ÿ,™,Ó'ñ &ð ˆØˆØ×$Ô$ˆBØ�w‰wœ#Ÿ&™&Õ Ø—Z‘Z—_‘_×)Ñ)�Ø˜“?Ø—L‘L )¨B¡-´·±Ð!:Ö;à—L‘L Ö$ñ %ö Ø×*Ñ*¨5°%¸À+ÓNÐNÞØ×"Ñ" 5¨¡8¨WÓ5ˆAò7ð �M‰M˜-Ô(Ø�M‰M÷ôð
 ˆHäÜ×#Ò#Ð$UÓVóð r   )r"   r#   r%   r!   )é
   NN)r   r   r   r   r   r    r-   r9   rE   r@   rI   r   r   r   r   r   r       s&   † ñô0ò:5òò>
òõ<tr   r   c                 ó   ^ ^• U U4S jnU$ )Nc                  ó:   >^ ^• TR                  U UU4S j5        T$ )Nc                 ó(   >• [        U T5      " T0 TD6$ r   )Úgetattr)r7   r   ÚkwrB   s    €€€r   rf   Ú6makePlaceholder.<locals>.placeholder.<locals>.<lambda>  s   ø€ ¤w¨q°$Ô'7¸Ð'DÀÒ'Dr   )r2   )r   r€   ÚdeferredrB   s   ``€€r   ÚplaceholderÚ$makePlaceholder.<locals>.placeholder  s   ú€ Ø×ÑÖDÔEØˆr   r   )r‚   rB   rƒ   s   `` r   ÚmakePlaceholderr…     s   ù€ öð Ðr   c                   ó&   • \ rS rSrS rS rS rSrg)ÚDeferredResolveri  c                 óH   • / U l         UR                  U R                  5        g r   )Úwaitingr2   ÚgotRealResolver)r   ÚresolverDeferreds     r   r    ÚDeferredResolver.__init__  s   € ØˆŒØ×$Ñ$ T×%9Ñ%9Õ:r   c                 ó”   • U R                   nUR                  U l        UR                  U l        U H  nUR                  U5        M     g r   )r‰   Ú__dict__Ú	__class__Úcallback)r   ÚresolverÚwr8   s       r   rŠ   Ú DeferredResolver.gotRealResolver  s;   € Ø�L‰LˆØ ×)Ñ)ˆŒØ!×+Ñ+ˆŒÛˆAØ�J‰J�xÖ ò r   c                 óÞ   • UR                  S5      (       d  US;   aG  U R                  R                  [        R                  " 5       5        [        U R                  S   U5      $ [        U5      e)NÚlookup)ÚgetHostByNamer4   éÿÿÿÿ)Ú
startswithr‰   rl   r   ÚDeferredr…   ÚAttributeError)r   rB   s     r   Ú__getattr__ÚDeferredResolver.__getattr__%  sS   € Ø�?‰?˜8×$Ñ$¨Ð0JÓ(JØ�L‰L×Ñ¤§¢Ó 0Ô1Ü" 4§<¡<°Ñ#3°TÓ:Ð:Ü˜TÓ"Ð"r   )r�   rŽ   r‰   N)r   r   r   r   r    rŠ   r›   r   r   r   r   r‡   r‡     s   † ò;ò!õ#r   r‡   Nc                 ó,  ^• [        S5       Vs/ s H  n[        [        S5      U-   5      PM     nnU Vs/ s H  o@R                  SU-  5      PM     nn[        R
                  " USS9nU4S jnUR                  U5        [        U5      $ s  snf s  snf )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                 ó`   >• [        U  Vs/ s H  oS   (       d  M  US   PM     snTS9$ s  snf )Nr   r<   )r!   r(   r   )ÚresÚer(   s     €r   ÚbuildResolverÚ bootstrap.<locals>.buildResolverD  s1   ø€ ÜÙ!$Ó-¢˜A¨!­“4�1�Q”4¡Ñ-¸ñ
ð 	
ùÚ-s   ‹+œ	+)ÚrangeÚchrÚordr–   r   ÚDeferredListr2   r‡   )r‘   r(   ÚiÚdomainsr8   ÚLr¤   s    `     r   Ú	bootstrapr­   ,  s…   ø€ ô( +0°¬)Ó4ª) QŒs”3�s“8˜a‘<Ö ©)€GÐ4ÙDKÓLÂG¸q×	Ñ	Ð 5¸Ñ 9Ö	:ÁG€AÐLÜ×Ò˜1¨DÑ1€Aõ
ð
 ‡M�M�-Ô ä˜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   