o
    Òó·iŽ$  ã                   @   sP  d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZmZmZ edƒ\ZZZd	ZeejƒG d
d„ dƒƒZd&dd„Zi ejd“ejd“ejd“ejd“ejd“ej d“ej!d“ej"d“ej#d“ej$d“ej%d“ej&d“ej'd“ej(d“ej)d“ej*d“ej+d“ej,d ej-d!ej.d"ej/d#ej0d$ej1d%i¥Z2dS )'z>
Base functionality useful to various parts of Twisted Names.
é    N)Úimplementer)ÚdeferÚerrorÚ
interfaces)ÚLogger)Údns)ÚDNSFormatErrorÚDNSNameErrorÚDNSNotImplementedErrorÚDNSQueryRefusedErrorÚDNSServerErrorÚDNSUnknownErroré   )© r   r   c                
   @   sV  e Zd ZdZeƒ Zejeej	e
ejeejeejeiZdZdd„ Zdd„ Zd>dd„Zd	d
„ Zd>dd„Zd>dd„Zd>dd„Zd>dd„Zd>dd„Zd>dd„Zd>dd„Zd>dd„Zd>dd„Zd>dd„Z d>dd „Z!d>d!d"„Z"d>d#d$„Z#d>d%d&„Z$d>d'd(„Z%d>d)d*„Z&d>d+d,„Z'd>d-d.„Z(d>d/d0„Z)d>d1d2„Z*d>d3d4„Z+d>d5d6„Z,d>d7d8„Z-d?d:d;„Z.d<d=„ Z/dS )@ÚResolverBaseaN  
    L{ResolverBase} is a base class for implementations of
    L{interfaces.IResolver} which deals with a lot
    of the boilerplate of implementing all of the lookup methods.

    @cvar _errormap: A C{dict} mapping DNS protocol failure response codes
        to exception classes which will be used to represent those failures.
    Nc                 C   s,   i | _ t  ¡ D ]\}}t| |ƒ| j |< qd S ©N)ÚtypeToMethodÚitemsÚgetattr)ÚselfÚkÚvr   r   úZC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/names/common.pyÚ__init__7   s   ÿzResolverBase.__init__c                 C   s   | j  |t¡S )z¥
        Convert a response code (one of the possible values of
        L{dns.Message.rCode} to an exception instance representing it.

        @since: 10.0
        N)Ú	_errormapÚgetr   )r   ZresponseCoder   r   r   ÚexceptionForCode<   s   zResolverBase.exceptionForCodec              
   C   sb   z| j |j }W n ty'   | jjd|d� t | j|jjt	j
|j|¡ Y S w t ||jj|¡S )Nz:Query of unknown type {query.type} for {query.name.name!r})Úquery)r   ÚtypeÚKeyErrorÚ_logÚdebugr   ZmaybeDeferredÚ_lookupÚnamer   ÚIN)r   r   ÚtimeoutÚmethodr   r   r   r   E   s   þÿû	zResolverBase.queryc                 C   s   t  tdƒ¡S )NúResolverBase._lookup)r   ZfailÚNotImplementedError)r   r#   Úclsr   r%   r   r   r   r"   S   s   r'   c                 C   ó   |   t |¡tjtj|¡S r   )r"   r   ÚdomainStringr$   ÚA©r   r#   r%   r   r   r   ÚlookupAddressV   ó   zResolverBase.lookupAddressc                 C   r*   r   )r"   r   r+   r$   ÚAAAAr-   r   r   r   ÚlookupIPV6AddressY   r/   zResolverBase.lookupIPV6Addressc                 C   r*   r   )r"   r   r+   r$   ÚA6r-   r   r   r   ÚlookupAddress6\   r/   zResolverBase.lookupAddress6c                 C   r*   r   )r"   r   r+   r$   ÚMXr-   r   r   r   ÚlookupMailExchange_   r/   zResolverBase.lookupMailExchangec                 C   r*   r   )r"   r   r+   r$   ÚNSr-   r   r   r   ÚlookupNameserversb   r/   zResolverBase.lookupNameserversc                 C   r*   r   )r"   r   r+   r$   ÚCNAMEr-   r   r   r   ÚlookupCanonicalNamee   r/   z ResolverBase.lookupCanonicalNamec                 C   r*   r   )r"   r   r+   r$   ÚMBr-   r   r   r   ÚlookupMailBoxh   r/   zResolverBase.lookupMailBoxc                 C   r*   r   )r"   r   r+   r$   ÚMGr-   r   r   r   ÚlookupMailGroupk   r/   zResolverBase.lookupMailGroupc                 C   r*   r   )r"   r   r+   r$   ÚMRr-   r   r   r   ÚlookupMailRenamen   r/   zResolverBase.lookupMailRenamec                 C   r*   r   )r"   r   r+   r$   ÚPTRr-   r   r   r   ÚlookupPointerq   r/   zResolverBase.lookupPointerc                 C   r*   r   )r"   r   r+   r$   ÚSOAr-   r   r   r   ÚlookupAuthorityt   r/   zResolverBase.lookupAuthorityc                 C   r*   r   )r"   r   r+   r$   ÚNULLr-   r   r   r   Ú
lookupNullw   r/   zResolverBase.lookupNullc                 C   r*   r   )r"   r   r+   r$   ÚWKSr-   r   r   r   ÚlookupWellKnownServicesz   r/   z$ResolverBase.lookupWellKnownServicesc                 C   r*   r   )r"   r   r+   r$   ÚSRVr-   r   r   r   ÚlookupService}   r/   zResolverBase.lookupServicec                 C   r*   r   )r"   r   r+   r$   ÚHINFOr-   r   r   r   ÚlookupHostInfo€   r/   zResolverBase.lookupHostInfoc                 C   r*   r   )r"   r   r+   r$   ÚMINFOr-   r   r   r   ÚlookupMailboxInfoƒ   r/   zResolverBase.lookupMailboxInfoc                 C   r*   r   )r"   r   r+   r$   ÚTXTr-   r   r   r   Ú
lookupText†   r/   zResolverBase.lookupTextc                 C   r*   r   )r"   r   r+   r$   ÚSPFr-   r   r   r   ÚlookupSenderPolicy‰   r/   zResolverBase.lookupSenderPolicyc                 C   r*   r   )r"   r   r+   r$   ÚRPr-   r   r   r   ÚlookupResponsibilityŒ   r/   z!ResolverBase.lookupResponsibilityc                 C   r*   r   )r"   r   r+   r$   ÚAFSDBr-   r   r   r   ÚlookupAFSDatabase�   r/   zResolverBase.lookupAFSDatabasec                 C   r*   r   )r"   r   r+   r$   ÚAXFRr-   r   r   r   Ú
lookupZone’   r/   zResolverBase.lookupZonec                 C   r*   r   )r"   r   r+   r$   ÚNAPTRr-   r   r   r   ÚlookupNamingAuthorityPointer•   r/   z)ResolverBase.lookupNamingAuthorityPointerc                 C   r*   r   )r"   r   r+   r$   ÚALL_RECORDSr-   r   r   r   ÚlookupAllRecords˜   r/   zResolverBase.lookupAllRecordsé
   c                 C   s*   t  |¡}|  ||¡}| | j||¡ |S r   )r   r+   r[   ÚaddCallbackÚ
_cbRecords)r   r#   r%   ÚeffortÚdr   r   r   ÚgetHostByNameœ   s   
zResolverBase.getHostByNamec                 C   s8   |\}}}t | t |¡|| | |ƒ}|st |¡‚|S r   )ÚextractRecordr   ÚNamer   ZDNSLookupError)r   Úrecordsr#   r_   ÚansÚauthÚaddÚresultr   r   r   r^   ¥   s
   

zResolverBase._cbRecordsr   )Nr\   )0Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r   ZEFORMATr   ZESERVERr   ZENAMEr	   ZENOTIMPr
   ZEREFUSEDr   r   r   r   r   r   r"   r.   r1   r3   r5   r7   r9   r;   r=   r?   rA   rC   rE   rG   rI   rK   rM   rO   rQ   rS   rU   rW   rY   r[   ra   r^   r   r   r   r   r   !   sN    	û
	























	r   r\   c                    s~  ˆ sdS t tdƒr?|D ]}|jˆkr#|jtjkr#t tj|jj	¡  S q|D ]}|jˆkr>|jtj
kr>t tj|jj	¡  S q&|D ]}|jˆkrY|jtjkrYt tj|jj	¡  S qA|D ],}|jˆkrˆ|jtjkrˆt| |jj|ˆ d ƒ}|s„| j|jjjˆ d d�  S |  S q\|D ]1}|jtjkr”q‹ddlm} |j|jjj d¡tjfgd�‰‡ ‡‡fd	d
„}ˆ ˆj¡ |¡  S dS )am  
    Resolve a name to an IP address, following I{CNAME} records and I{NS}
    referrals recursively.

    This is an implementation detail of L{ResolverBase.getHostByName}.

    @param resolver: The resolver to use for the next query (unless handling
    an I{NS} referral).
    @type resolver: L{IResolver}

    @param name: The name being looked up.
    @type name: L{dns.Name}

    @param answers: All of the records returned by the previous query (answers,
    authority, and additional concatenated).
    @type answers: L{list} of L{dns.RRHeader}

    @param level: Remaining recursion budget. This is decremented at each
    recursion. The query returns L{None} when it reaches 0.
    @type level: L{int}

    @returns: The first IPv4 or IPv6 address (as a dotted quad or colon
    quibbles), or L{None} when no result is found.
    @rtype: native L{str} or L{None}
    NÚ	inet_ntopé   )r_   r   )ÚclientÚascii)Zserversc                    s$   | \}}}t ˆˆ|| | ˆ d ƒS )Nrn   )rb   )rd   re   rf   rg   ©Úlevelr#   Z
nsResolverr   r   Ú
queryAgainè   s   
z!extractRecord.<locals>.queryAgain)ÚhasattrÚsocketr#   r   r   r2   rm   ÚAF_INET6ÚpayloadÚaddressr0   r,   ÚAF_INETr8   rb   ra   r6   Útwisted.namesro   ÚResolverÚdecodeZPORTr.   r]   )Úresolverr#   Zanswersrr   Úrrh   ro   rs   r   rq   r   rb   ­   sB   
€€€€ÿÿñrb   r.   r1   r3   r7   r9   rC   r;   r=   r?   rE   rG   rA   rK   rM   r5   rO   rQ   rS   rU   rI   rY   rW   r[   )r\   )3rl   ru   Zzope.interfacer   Ztwisted.internetr   r   r   Ztwisted.loggerr   rz   r   Ztwisted.names.errorr   r	   r
   r   r   r   ÚrangeZ_ANSZ_AUTHZ_ADDZEMPTY_RESULTZ	IResolverr   rb   r,   r0   r2   r6   r8   rB   r:   r<   r>   rD   rF   r@   rJ   rL   r4   rN   rP   rR   rT   rH   rX   rV   rZ   r   r   r   r   r   Ú<module>   sn     
Bÿþýüûúùø	÷
öõôóòñðï
é