U
    Â@Ûf0Ö  ã                   @   s`  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZmZmZmZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZdd„ Zdd„ Z ej! "d¡Z#e#�r>ddl$Z%ddl&Z&e%j'Z(e%j)j*j+Z,G d	d
„ d
e(ƒZ-G dd„ de&j.ƒZ/nG dd„ dƒZ/e#Z0zddl1Z1W n$ e2k
�r€   G dd„ dƒZ1Y nX ejZ3G dd„ dej4j5ƒZ6G dd„ dej4j7ƒZ8G dd„ dej4j5ƒZ9G dd„ dej4j5ƒZ:ej;j<Z<dd„ Z=dd„ Z>dd„ Z?e@edƒ�rejAaBnejCaBdd „ ZDd!d"„ ZEd#d$„ ZFd%d&„ ZGdhd(d)„ZHdid*d+„ZIdd,ddd-d-dd.d'dd'dejJfejKjLeMeeN eOeeM eOePePee eMePeeM eePeMf ed/ eeO ejKjLd0œd1d2„ZQd3d4„ ZRd5d6„ ZSdjeeejKjLeTf eeeN eeOeNf d7œd8d9„ZUdkeee eeN ePePeeejVjWejXjYf  eeT ePePePeejKjL ed;œd<d=„ZZdlejKjLeMeeN eOeeM eOePePePePee ePejKjLd?œd@dA„Z[dmejKjLeMeeN eOeeM eOePePePee ee ePeejKjLePf dBœdCdD„Z\dEdF„ Z]dGdH„ Z^dneeejKjLeTf eeN eeOeNf dIœdJdK„Z_doeeeN ePeeejVjWejXjYf  eeT ePeejKjLeNf dLœdMdN„Z`dOdP„ ZadpejKjLeMeeN eOeeM eOePePee ejKjLdQœ
dRdS„ZbdTdU„ ZceeM eePeMf e1jddVœdWdX„ZedqejKjLeMeeN eOeeM eOePePee1jf ee1jd eeM eePeMf ejKjLdZœd[d\„ZgdrejKjLeMeeN eOeeM eOePePeejhji eePeMf eeM ejKjLd]œd^d_„Zhejjjkejljmdd>ddd'ddddd-ejXjnfeMeejVjWeMf eejjjoeMf eejljpeMf eeN eOeeejVjWejXjYf  eeejVjWeMf  ePeeN eeM eOeOePeejVjWeMf ed`œdadb„Z;G dcdd„ ddejqƒZrdd>dddderjsfeMejtjueejKjL eOeeN eeN eeM eOerddeœ
dfdg„ZvdS )szTalk to a DNS server.é    N)ÚAnyÚDictÚOptionalÚTupleÚUnionc                 C   s,   | d krd S | t   ¡  }|dkr(tjj‚|S )Nç        )ÚtimeÚdnsÚ	exceptionÚTimeout)Ú
expirationÚtimeout© r   úC/var/www/html/chatgpt/venv/lib/python3.8/site-packages/dns/query.pyÚ
_remaining/   s    r   c                 C   s   |d krd S t t ¡ |  |ƒS ©N)Úminr   )r   r   r   r   r   Ú_expiration_for_this_attempt8   s    r   Zdohc                       s0   e Zd Z‡ fdd„Zddd„Zd	dd„Z‡  ZS )
Ú_NetworkBackendc                    s&   t ƒ  ¡  || _|| _|| _|| _d S r   )ÚsuperÚ__init__Ú_local_portÚ	_resolverÚ_bootstrap_addressÚ_family)ÚselfÚresolverÚ
local_portÚbootstrap_addressÚfamily©Ú	__class__r   r   r   G   s
    
z_NetworkBackend.__init__Nc              	   C   s  g }t |ƒ\}}tj |¡r(| |¡ nP| jd k	r@| | j¡ n8t|ƒ}| j}	|r^tj |¡}	| j	j
||	|d�}
|
 ¡ }|D ]”}tj |¡}|d k	sž| jdkr´tj || jf|¡}nd }t|tj|ƒ}td|ƒ}z(t|tj ||f|¡|ƒ t|ƒW   S  tk
�r   Y q|X q|tj‚d S )N)r   Úlifetimer   g       @)Ú_compute_timesr	   ÚinetÚ
is_addressÚappendr   r   r   Úaf_for_addressr   Úresolve_nameÚ	addressesr   Úlow_level_address_tupleÚ_make_socketÚsocketÚSOCK_STREAMr   Ú_connectÚ_CoreSyncStreamÚ	ExceptionÚhttpcoreZConnectError)r   ÚhostÚportr   Úlocal_addressÚsocket_optionsr)   Ú_r   r   ZanswersÚaddressÚafÚsourceÚsockZattempt_expirationr   r   r   Úconnect_tcpN   sH    
  ÿ ÿ
ýz_NetworkBackend.connect_tcpc                 C   s   t ‚d S r   ©ÚNotImplementedError)r   Úpathr   r5   r   r   r   Úconnect_unix_socketu   s    z#_NetworkBackend.connect_unix_socket)N)N)Ú__name__Ú
__module__Ú__qualname__r   r;   r?   Ú__classcell__r   r   r    r   r   F   s
    ÿ
( ÿr   c                       s*   e Zd Zdddejdœ‡ fdd„
Z‡  ZS )Ú_HTTPTransportr   N)r   r   r   r   c                   s>   |d krdd l }|j ¡ }tƒ j||Ž t||||ƒ| j_d S ©Nr   )Zdns.resolverr   ÚResolverr   r   r   Ú_poolZ_network_backend)r   r   r   r   r   ÚargsÚkwargsr	   r    r   r   r   {   s    	
   ÿz_HTTPTransport.__init__)r@   rA   rB   r,   Ú	AF_UNSPECr   rC   r   r   r    r   rD   z   s
   úrD   c                   @   s   e Zd Zdd„ ZdS )rD   c                 C   s   t ‚d S r   r<   )r   r2   r3   r   r4   r   r   r   r;   ‘   s    z_HTTPTransport.connect_tcpN)r@   rA   rB   r;   r   r   r   r   rD   �   s   c                   @   sX   e Zd ZdZG dd„ deƒZG dd„ deƒZG dd„ dƒZG dd	„ d	ƒZe	d
d„ ƒZ
dS )Ússlr   c                   @   s   e Zd ZdS )zssl.WantReadExceptionN©r@   rA   rB   r   r   r   r   ÚWantReadExceptionž   s   rM   c                   @   s   e Zd ZdS )zssl.WantWriteExceptionNrL   r   r   r   r   ÚWantWriteException¡   s   rN   c                   @   s   e Zd ZdS )zssl.SSLContextNrL   r   r   r   r   Ú
SSLContext¤   s   rO   c                   @   s   e Zd ZdS )zssl.SSLSocketNrL   r   r   r   r   Ú	SSLSocket§   s   rP   c                 O   s   t dƒ‚d S )Nzno ssl support)r0   )ÚclsrH   rI   r   r   r   Úcreate_default_contextª   s    zssl.create_default_contextN)r@   rA   rB   Ú	CERT_NONEr0   rM   rN   rO   rP   ÚclassmethodrR   r   r   r   r   rK   ›   s   rK   c                   @   s   e Zd ZdZdS )ÚUnexpectedSourcez=A DNS query response came from an unexpected address or port.N©r@   rA   rB   Ú__doc__r   r   r   r   rU   ´   s   rU   c                   @   s   e Zd ZdZdS )ÚBadResponsez<A DNS query response does not respond to the question asked.NrV   r   r   r   r   rX   ¸   s   rX   c                   @   s   e Zd ZdZdS )ÚNoDOHzMDNS over HTTPS (DOH) was requested but the httpx module is not
    available.NrV   r   r   r   r   rY   ¼   s   rY   c                   @   s   e Zd ZdZdS )ÚNoDOQzNDNS over QUIC (DOQ) was requested but the aioquic module is not
    available.NrV   r   r   r   r   rZ   Á   s   rZ   c                 C   s(   t   ¡ }| d kr|d fS |||  fS d S r   )r   )r   Únowr   r   r   r#   Ê   s    r#   c                 C   s–   |r t | tjƒr |  ¡ dkr dS tƒ }d}|r8|tjO }|rF|tjO }|rV| | |¡ |d krdd }n|t	 	¡  }|dkr€t
jj‚| |¡s’t
jj‚d S )Nr   Tr   )Ú
isinstancerK   rP   ÚpendingÚ_selector_classÚ	selectorsÚ
EVENT_READÚEVENT_WRITEÚregisterr   r	   r
   r   Úselect)ÚfdÚreadableÚwritabler6   r   ÚselÚeventsr   r   r   r   Ú	_wait_forÒ   s"    


ri   c                 C   s   | a d S r   )r^   )Zselector_classr   r   r   Ú_set_selector_classî   s    rj   ÚPollSelectorc                 C   s   t | ddd|ƒ d S )NTF©ri   ©Úsr   r   r   r   Ú_wait_for_readable  s    ro   c                 C   s   t | ddd|ƒ d S )NFTrl   rm   r   r   r   Ú_wait_for_writable  s    rp   c                 C   sd   z(t j | |d ¡}t j | |d ¡}W n t jjk
rB   Y dS X ||kob|dd … |dd … kS )Nr   Fé   )r	   r$   Ú	inet_ptonr
   ÚSyntaxError)r8   Za1Za2Zn1Zn2r   r   r   Ú_addresses_equal
  s    rt   c                 C   s`   |sdS t | ||ƒs<tj |d ¡r@|dd … |dd … kr@dS |rHdS td|› d|› �ƒ‚d S )NTr   rq   Fzgot a response from z instead of )rt   r	   r$   Úis_multicastrU   )r8   Úfrom_addressÚdestinationÚignore_unexpectedr   r   r   Ú_matches_destination  s    ÿÿÿry   Tc                 C   sÎ   d }d }zt j | ¡}| }W n tk
r6   |r2‚ Y nX |rbt j |¡}|r^||krbtdƒ‚n|}|r˜|s˜zt j |¡}W n tk
r–   tdƒ‚Y nX |r®t j ||f|¡}|rÄt j ||f|¡}|||fS )Nz5different address families for source and destinationz3source_port specified but address family is unknown)r	   r$   r'   r0   Ú
ValueErrorZ
any_for_afr*   )Úwherer3   r9   Úsource_portZwhere_must_be_addressr8   rw   Zsafr   r   r   Ú_destination_and_source&  s4    ÿr}   c                 C   sj   t | |ƒ}z<| d¡ |d k	r(| |¡ |r>|j|d|d�W S |W S W n tk
rd   | ¡  ‚ Y nX d S )NF)Údo_handshake_on_connectÚserver_hostname)Úsocket_factoryÚsetblockingÚbindÚwrap_socketr0   Úclose)r8   Útyper9   Ússl_contextr   rn   r   r   r   r+   R  s    


ý
r+   i»  Fz
/dns-queryzdns.resolver.Resolver)Úqr{   r   r3   r9   r|   Úone_rr_per_rrsetÚignore_trailingÚsessionr>   Úpostr   Úverifyr   r   Úreturnc              
   C   sÌ  t st‚|r t|tjƒs tdƒ‚|  ¡ }t||||dƒ\}}}d}ddi}|dk	r’tj	 
|¡r’|tjkrxd |||	¡}q–|tjkr–d |||	¡}n|}|dkr¨d}d}n|d }|d	 }t|d
d
|||||d�}|ràt |¡}ntjd
d
||d�}|�f}|
�r*| dtt|ƒƒdœ¡ |j||||d�}n.t |¡ d¡}| ¡ }|j|||d|id�}W 5 Q R X |jdk �sz|jdk�r�td ||j|j¡ƒ‚tjj|j| j| j ||d�}|j! "¡ |_#|  $|¡�sÈt%‚|S )a´  Return the response obtained after sending a query via DNS-over-HTTPS.

    *q*, a ``dns.message.Message``, the query to send.

    *where*, a ``str``, the nameserver IP address or the full URL. If an IP address is
    given, the URL will be constructed using the following schema:
    https://<IP-address>:<port>/<path>.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query
    times out. If ``None``, the default, wait forever.

    *port*, a ``int``, the port to send the query to. The default is 443.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source
    address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message. The default is
    0.

    *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``. If ``True``, ignore trailing junk at end of the
    received message.

    *session*, an ``httpx.Client``.  If provided, the client session to use to send the
    queries.

    *path*, a ``str``. If *where* is an IP address, then *path* will be used to
    construct the URL to send the DNS query to.

    *post*, a ``bool``. If ``True``, the default, POST method will be used.

    *bootstrap_address*, a ``str``, the IP address to use to bypass resolution.

    *verify*, a ``bool`` or ``str``.  If a ``True``, then TLS certificate verification
    of the server is done using the default CA bundle; if ``False``, then no
    verification is done; if a `str` then it specifies the path to a certificate file or
    directory which will be used for verification.

    *resolver*, a ``dns.resolver.Resolver`` or ``None``, the resolver to use for
    resolution of hostnames in URLs.  If not specified, a new resolver with a default
    configuration will be used; note this is *not* the default resolver as that resolver
    might have been configured to use DoH causing a chicken-and-egg problem.  This
    parameter only has an effect if the HTTP library is httpx.

    *family*, an ``int``, the address family.  If socket.AF_UNSPEC (the default), both A
    and AAAA records will be retrieved.

    Returns a ``dns.message.Message``.
    z)session parameter must be an httpx.ClientFNÚacceptzapplication/dns-messagezhttps://{}:{}{}zhttps://[{}]:{}{}r   rq   T)r4   Úhttp1Úhttp2rŒ   r   r   r   r   )r�   r�   rŒ   Ú	transport)zcontent-typezcontent-length)ÚheadersÚcontentr   ó   =r	   )r’   r   ÚparamséÈ   i+  z2{} responded with status code {}
Response body: {}©ÚkeyringÚrequest_macrˆ   r‰   )&Úhave_dohrY   r\   ÚhttpxZClientrz   Úto_wirer}   r	   r$   r%   r,   ÚAF_INETÚformatÚAF_INET6rD   Ú
contextlibÚnullcontextÚupdateÚstrÚlenr‹   Úbase64Úurlsafe_b64encodeÚrstripÚdecodeÚgetÚstatus_coder“   ÚmessageÚ	from_wirer˜   r™   ÚelapsedÚtotal_secondsr   Úis_responserX   )r‡   r{   r   r3   r9   r|   rˆ   r‰   rŠ   r>   r‹   r   rŒ   r   r   Úwirer8   r6   Z
the_sourcer‘   r’   Úurlr4   r   ÚcmÚresponseZtwireÚrr   r   r   Úhttpsf  s’    D    ÿ


ø
þÿ   ÿ  ÿÿûrµ   c                 C   s2   z|   |¡W S  tk
r*   t| |ƒ Y q X q dS )z‹Reads a datagram from the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    N)ÚrecvfromÚBlockingIOErrorro   )r:   Úmax_sizer   r   r   r   Ú	_udp_recvú  s    r¹   c                 C   sH   z"|r|   ||¡W S |  |¡W S W q  tk
r@   t| |ƒ Y q X q dS )z¦Sends the specified datagram to destination over the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    N)ÚsendtoÚsendr·   rp   )r:   Údatarw   r   r   r   r   Ú	_udp_send  s    r½   )r:   Úwhatrw   r   r�   c                 C   s4   t |tjjƒr| ¡ }t ¡ }t| |||ƒ}||fS )aý  Send a DNS message to the specified UDP socket.

    *sock*, a ``socket``.

    *what*, a ``bytes`` or ``dns.message.Message``, the message to send.

    *destination*, a destination tuple appropriate for the address family
    of the socket, specifying where to send the query.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.

    Returns an ``(int, float)`` tuple of bytes sent and the sent time.
    )r\   r	   r«   ÚMessagerœ   r   r½   )r:   r¾   rw   r   Ú	sent_timeÚnr   r   r   Úsend_udp  s
    rÂ   ó    )r:   rw   r   rx   rˆ   r˜   r™   r‰   Úraise_on_truncationÚignore_errorsÚqueryr�   c              
   C   sê   d}t | d|ƒ\}}t| j|||ƒs&qt ¡ }ztjj||||||d�}W nj tjjk
r– } z*|	r„|
dk	r„|
 | ¡ ¡s„W Y ¢
qn‚ W 5 d}~X Y n  t	k
r´   |	r®Y qn‚ Y nX |	rÎ|
dk	rÎ|
 |¡sÎq|rÚ||fS |||fS qdS )a  Read a DNS message from a UDP socket.

    *sock*, a ``socket``.

    *destination*, a destination tuple appropriate for the address family
    of the socket, specifying where the message is expected to arrive from.
    When receiving a response, this would be where the associated query was
    sent.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.

    *ignore_unexpected*, a ``bool``.  If ``True``, ignore responses from
    unexpected sources.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *keyring*, a ``dict``, the keyring to use for TSIG.

    *request_mac*, a ``bytes`` or ``None``, the MAC of the request (for TSIG).

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *raise_on_truncation*, a ``bool``.  If ``True``, raise an exception if
    the TC bit is set.

    Raises if the message is malformed, if network errors occur, of if
    there is a timeout.

    If *destination* is not ``None``, returns a ``(dns.message.Message, float)``
    tuple of the received message and the received time.

    If *destination* is ``None``, returns a
    ``(dns.message.Message, float, tuple)``
    tuple of the received message, the received time, and the address where
    the message arrived from.

    *ignore_errors*, a ``bool``.  If various format errors or response
    mismatches occur, ignore them and keep listening for a valid response.
    The default is ``False``.

    *query*, a ``dns.message.Message`` or ``None``.  If not ``None`` and
    *ignore_errors* is ``True``, check that the received message is a response
    to this query, and if not keep listening for a valid response.
    rÃ   éÿÿ  )r˜   r™   rˆ   r‰   rÄ   N)
r¹   ry   r   r   r	   r«   r¬   Ú	Truncatedr¯   r0   )r:   rw   r   rx   rˆ   r˜   r™   r‰   rÄ   rÅ   rÆ   r°   rv   Úreceived_timer´   Úer   r   r   Úreceive_udp2  sJ    >   ÿú
ÿþý
rË   é5   )r‡   r{   r   r3   r9   r|   rx   rˆ   r‰   rÄ   r:   rÅ   r�   c                 C   s¼   |   ¡ }t||||ƒ\}}}t|ƒ\}}|
r8t |
¡}nt|tj|ƒ}|�`}t||||ƒ t	|||||| j
| j||	|| ƒ\}}|| |_|sš|  |¡sšt‚|W  5 Q R £ S Q R X ds¸t‚dS )aý  Return the response obtained after sending a query via UDP.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
    query times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *ignore_unexpected*, a ``bool``.  If ``True``, ignore responses from
    unexpected sources.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *raise_on_truncation*, a ``bool``.  If ``True``, raise an exception if
    the TC bit is set.

    *sock*, a ``socket.socket``, or ``None``, the socket to use for the
    query.  If ``None``, the default, a socket is created.  Note that
    if a socket is provided, it must be a nonblocking datagram socket,
    and the *source* and *source_port* are ignored.

    *ignore_errors*, a ``bool``.  If various format errors or response
    mismatches occur, ignore them and keep listening for a valid response.
    The default is ``False``.

    Returns a ``dns.message.Message``.
    FN)rœ   r}   r#   r    r¡   r+   r,   Ú
SOCK_DGRAMrÂ   rË   r˜   Úmacr   r¯   rX   ÚAssertionError)r‡   r{   r   r3   r9   r|   rx   rˆ   r‰   rÄ   r:   rÅ   r°   r8   rw   Ú
begin_timer   r²   rn   r´   rÉ   r   r   r   Úudpœ  s@    8   ÿ
õ
ÿrÑ   )r‡   r{   r   r3   r9   r|   rx   rˆ   r‰   Úudp_sockÚtcp_sockrÅ   r�   c                 C   sf   z(t | ||||||||d|	|ƒ}|dfW S  tjjk
r`   t| ||||||||
ƒ	}|df Y S X dS )a|  Return the response to the query, trying UDP first and falling back
    to TCP if UDP results in a truncated response.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query
    times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source
    address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message. The default is
    0.

    *ignore_unexpected*, a ``bool``.  If ``True``, ignore responses from unexpected
    sources.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing junk at end of the
    received message.

    *udp_sock*, a ``socket.socket``, or ``None``, the socket to use for the UDP query.
    If ``None``, the default, a socket is created.  Note that if a socket is provided,
    it must be a nonblocking datagram socket, and the *source* and *source_port* are
    ignored for the UDP query.

    *tcp_sock*, a ``socket.socket``, or ``None``, the connected socket to use for the
    TCP query.  If ``None``, the default, a socket is created.  Note that if a socket is
    provided, it must be a nonblocking connected stream socket, and *where*, *source*
    and *source_port* are ignored for the TCP query.

    *ignore_errors*, a ``bool``.  If various format errors or response mismatches occur
    while listening for UDP, ignore them and keep listening for a valid response. The
    default is ``False``.

    Returns a (``dns.message.Message``, tcp) tuple where tcp is ``True`` if and only if
    TCP was used.
    TFN)rÑ   r	   r«   rÈ   Útcp)r‡   r{   r   r3   r9   r|   rx   rˆ   r‰   rÒ   rÓ   rÅ   r³   r   r   r   Úudp_with_fallback÷  s:    9ô
÷rÕ   c              	   C   s„   d}|dkr€z.|   |¡}|dkr$t‚|t|ƒ8 }||7 }W q ttjfk
r^   t| |ƒ Y q tjk
r|   t| |ƒ Y qX q|S )zßRead the specified number of bytes from sock.  Keep trying until we
    either get the desired amount, or we hit EOF.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    rÃ   r   )	ÚrecvÚEOFErrorr¤   r·   rK   ÚSSLWantReadErrorro   ÚSSLWantWriteErrorrp   )r:   Úcountr   rn   rÁ   r   r   r   Ú	_net_readO  s    
rÛ   c              	   C   sx   d}t |ƒ}||k rtz||  ||d… ¡7 }W q ttjfk
rR   t| |ƒ Y q tjk
rp   t| |ƒ Y qX qdS )z‘Write the specified data to the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    r   N)r¤   r»   r·   rK   rÙ   rp   rØ   ro   )r:   r¼   r   ÚcurrentÚlr   r   r   Ú
_net_writed  s    rÞ   )r:   r¾   r   r�   c                 C   sP   t |tjjƒr|jdd�}nt|ƒ dd¡| }t ¡ }t| ||ƒ t|ƒ|fS )a{  Send a DNS message to the specified TCP socket.

    *sock*, a ``socket``.

    *what*, a ``bytes`` or ``dns.message.Message``, the message to send.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.

    Returns an ``(int, float)`` tuple of bytes sent and the sent time.
    T)Zprepend_lengthé   Úbig)	r\   r	   r«   r¿   rœ   r¤   Úto_bytesr   rÞ   )r:   r¾   r   ÚtcpmsgrÀ   r   r   r   Úsend_tcpt  s    rã   )r:   r   rˆ   r˜   r™   r‰   r�   c                 C   sL   t | d|ƒ}t d|¡\}t | ||ƒ}t ¡ }	tjj|||||d�}
|
|	fS )aó  Read a DNS message from a TCP socket.

    *sock*, a ``socket``.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *keyring*, a ``dict``, the keyring to use for TSIG.

    *request_mac*, a ``bytes`` or ``None``, the MAC of the request (for TSIG).

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    Raises if the message is malformed, if network errors occur, of if
    there is a timeout.

    Returns a ``(dns.message.Message, float)`` tuple of the received message
    and the received time.
    rß   ú!Hr—   )rÛ   ÚstructÚunpackr   r	   r«   r¬   )r:   r   rˆ   r˜   r™   r‰   ÚldatarÝ   r°   rÉ   r´   r   r   r   Úreceive_tcp’  s    !ûrè   c                 C   s`   |   |¡}|dkrd S |tjtjtjfkrDt| |ƒ |  tjtj	¡}|dkr\t
|t |¡ƒ‚d S rE   )Ú
connect_exÚerrnoZEINPROGRESSÚEWOULDBLOCKZEALREADYrp   Ú
getsockoptr,   Ú
SOL_SOCKETÚSO_ERRORÚOSErrorÚosÚstrerror)rn   r7   r   Úerrr   r   r   r.   Á  s    

r.   )
r‡   r{   r   r3   r9   r|   rˆ   r‰   r:   r�   c	              
   C   s¼   |   ¡ }	t|ƒ\}
}|r$t |¡}n"t||||ƒ\}}}t|tj|ƒ}|�`}|s\t|||ƒ t	||	|ƒ t
|||| j| j|ƒ\}}||
 |_|  |¡sšt‚|W  5 Q R £ S Q R X ds¸t‚dS )a¥  Return the response obtained after sending a query via TCP.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address, where
    to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
    query times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *sock*, a ``socket.socket``, or ``None``, the connected socket to use for the
    query.  If ``None``, the default, a socket is created.  Note that
    if a socket is provided, it must be a nonblocking connected stream
    socket, and *where*, *port*, *source* and *source_port* are ignored.

    Returns a ``dns.message.Message``.
    FN)rœ   r#   r    r¡   r}   r+   r,   r-   r.   rã   rè   r˜   rÎ   r   r¯   rX   rÏ   )r‡   r{   r   r3   r9   r|   rˆ   r‰   r:   r°   rÐ   r   r²   r8   rw   rn   r´   rÉ   r   r   r   rÔ   Ì  s:    +   ÿ
     ÿ

ÿrÔ   c                 C   sT   z|   ¡  W d S  tjk
r.   t| |ƒ Y q  tjk
rL   t| |ƒ Y q X q d S r   )Údo_handshakerK   rØ   ro   rÙ   rp   rm   r   r   r   Ú_tls_handshake  s    rô   )r   rŒ   r�   c                 C   s„   d }d }t |tƒr>tj |¡r$|}ntj |¡r6|}ntdƒ‚tj||d�}tj	j
|_| d krdd|_| dg¡ |dkr€tj|_|S )Nzinvalid verify string)ÚcafileÚcapathFÚdot)r\   r£   rð   r>   ÚisfileÚisdirrz   rK   rR   Ú
TLSVersionÚTLSv1_2Úminimum_versionÚcheck_hostnameÚset_alpn_protocolsrS   Úverify_mode)r   rŒ   rõ   rö   r†   r   r   r   Ú_make_dot_ssl_context  s     

r   éU  )r‡   r{   r   r3   r9   r|   rˆ   r‰   r:   r†   r   rŒ   r�   c              
   C   sæ   |rt | ||||||||ƒ	S |  ¡ }t|ƒ\}}t||||ƒ\}}}|	dkrZ|sZt|
|ƒ}	t|tj||	|
d��f}t|||ƒ t	||ƒ t
|||ƒ t|||| j| j|ƒ\}}|| |_|  |¡sÄt‚|W  5 Q R £ S Q R X dsât‚dS )ak  Return the response obtained after sending a query via TLS.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
    query times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 853.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *sock*, an ``ssl.SSLSocket``, or ``None``, the socket to use for
    the query.  If ``None``, the default, a socket is created.  Note
    that if a socket is provided, it must be a nonblocking connected
    SSL stream socket, and *where*, *port*, *source*, *source_port*,
    and *ssl_context* are ignored.

    *ssl_context*, an ``ssl.SSLContext``, the context to use when establishing
    a TLS connection. If ``None``, the default, creates one with the default
    configuration.

    *server_hostname*, a ``str`` containing the server's hostname.  The
    default is ``None``, which means that no hostname is known, and if an
    SSL context is created, hostname checking will be disabled.

    *verify*, a ``bool`` or ``str``.  If a ``True``, then TLS certificate verification
    of the server is done using the default CA bundle; if ``False``, then no
    verification is done; if a `str` then it specifies the path to a certificate file or
    directory which will be used for verification.

    Returns a ``dns.message.Message``.

    N)r†   r   F)rÔ   rœ   r#   r}   r   r+   r,   r-   r.   rô   rã   rè   r˜   rÎ   r   r¯   rX   rÏ   )r‡   r{   r   r3   r9   r|   rˆ   r‰   r:   r†   r   rŒ   r°   rÐ   r   r8   rw   rn   r´   rÉ   r   r   r   Útls1  s^    =÷   ÿ

û
     ÿ

ÿr  )r‡   r{   r   r3   r9   r|   rˆ   r‰   Ú
connectionrŒ   r   r�   c              
   C   sê   t jjstdƒ‚d| _|  ¡ }|r2t d¡}|}nt jj|	|
d�}|}|�^ |s`| 	||||¡}t
|ƒ\}}| |¡� }| |d¡ | t|ƒ¡}W 5 Q R X t ¡ }W 5 Q R X t jj|| j| j||d�}t|| dƒ|_|  |¡sæt‚|S )aÎ  Return the response obtained after sending a query via DNS-over-QUIC.

    *q*, a ``dns.message.Message``, the query to send.

    *where*, a ``str``, the nameserver IP address.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query
    times out. If ``None``, the default, wait forever.

    *port*, a ``int``, the port to send the query to. The default is 853.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source
    address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message. The default is
    0.

    *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``. If ``True``, ignore trailing junk at end of the
    received message.

    *connection*, a ``dns.quic.SyncQuicConnection``.  If provided, the
    connection to use to send the query.

    *verify*, a ``bool`` or ``str``.  If a ``True``, then TLS certificate verification
    of the server is done using the default CA bundle; if ``False``, then no
    verification is done; if a `str` then it specifies the path to a certificate file or
    directory which will be used for verification.

    *server_hostname*, a ``str`` containing the server's hostname.  The
    default is ``None``, which means that no hostname is known, and if an
    SSL context is created, hostname checking will be disabled.

    Returns a ``dns.message.Message``.
    zDNS-over-QUIC is not available.r   N)rÿ   Zserver_nameTr—   r   )r	   ÚquicZ	have_quicrZ   Úidrœ   r    r¡   ZSyncQuicManagerÚconnectr#   Zmake_streamr»   Zreceiver   r   r«   r¬   r˜   r™   Úmaxr¯   rX   )r‡   r{   r   r3   r9   r|   rˆ   r‰   r  rŒ   r   r°   ÚmanagerZthe_connectionZthe_managerÚstartr   ÚstreamÚfinishr´   r   r   r   r  œ  s>    2
 ÿû
r  )r{   ÚzoneÚrdtypeÚrdclassr   r3   r˜   ÚkeynameÚ
relativizer"   r9   r|   ÚserialÚuse_udpÚkeyalgorithmr�   c           '      c   s¨  t |tƒrtj |¡}tjj |¡}tj 	|||¡}|tjj
krdtj |dddd| ¡}|j |¡ |dk	r||j|||d� | ¡ }t| ||
|ƒ\}}}
|r°|tjj
kr°tdƒ‚|rºtjntj}t|||
ƒ��Ð}t|	ƒ\}}t|||ƒ t|ƒ}|�rt||d|ƒ nt d|¡| }t|||ƒ d	}d
}d	}d}|�rF|}tjj}nd}|}d} |�sšt|ƒ\}}!|!dk�s‚|dk	�r†|!|k�r†|}!|�ržt|d|!ƒ\}}n&t|d|!ƒ}"t  d|"¡\}t|||!ƒ}|tjj
k}#tjj!||j"|j#d
|| d
|#d�}$|$ $¡ }%|%tj$j%k�rt&|%ƒ‚|$j'} d}&|dk�rª|$j(�r<|$j(d j|k�rHtj) *d¡‚|$j(d }|j+tjj,k�rntj) *d¡‚d}&| -¡ }|tjj
k�rªtj. /|d j.¡|k�r¦d
}nd
}|$j(|&d… D ]´}|�rÎtj) *d¡‚|j+tjj,k�rX|j|k�rX|�r|d j.|k�rtj) *d¡‚d	}n|tjj
k�r&| }||k�rj|tjj0k�sR|tjj
k�rj|�rjd
}n|�r¸tjj0}d	}�q¸|�r�|j"�r�|$j1�s�tj) *d¡‚|$V  �qRW 5 Q R X dS )a³  Return a generator for the responses to a zone transfer.

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *zone*, a ``dns.name.Name`` or ``str``, the name of the zone to transfer.

    *rdtype*, an ``int`` or ``str``, the type of zone transfer.  The
    default is ``dns.rdatatype.AXFR``.  ``dns.rdatatype.IXFR`` can be
    used to do an incremental transfer instead.

    *rdclass*, an ``int`` or ``str``, the class of the zone transfer.
    The default is ``dns.rdataclass.IN``.

    *timeout*, a ``float``, the number of seconds to wait for each
    response message.  If None, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *keyring*, a ``dict``, the keyring to use for TSIG.

    *keyname*, a ``dns.name.Name`` or ``str``, the name of the TSIG
    key to use.

    *relativize*, a ``bool``.  If ``True``, all names in the zone will be
    relativized to the zone origin.  It is essential that the
    relativize setting matches the one specified to
    ``dns.zone.from_xfr()`` if using this generator to make a zone.

    *lifetime*, a ``float``, the total number of seconds to spend
    doing the transfer.  If ``None``, the default, then there is no
    limit on the time the transfer may take.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *serial*, an ``int``, the SOA serial number to use as the base for
    an IXFR diff sequence (only meaningful if *rdtype* is
    ``dns.rdatatype.IXFR``).

    *use_udp*, a ``bool``.  If ``True``, use UDP (only meaningful for IXFR).

    *keyalgorithm*, a ``dns.name.Name`` or ``str``, the TSIG algorithm to use.

    Raises on errors, and so does the generator.

    Returns a generator of ``dns.message.Message`` objects.
    r   ÚINÚSOAz. . %u 0 0 0 0N)Ú	algorithmzcannot do a UDP AXFRrä   FTrÇ   rß   ©r˜   r™   ÚxfrÚoriginÚtsig_ctxÚmultirˆ   z No answer or RRset not for qnamezfirst RRset is not an SOArq   zanswers after final SOAzIXFR base serial mismatchúmissing TSIG)2r\   r£   r	   ÚnameZ	from_textÚ	rdatatypeÚ	RdataTypeÚmaker«   Ú
make_queryÚIXFRÚrrsetÚ	authorityr&   Zuse_tsigrœ   r}   rz   r,   rÍ   r-   r+   r#   r.   r¤   r½   rå   ÚpackrÞ   Úemptyr¹   rÛ   ræ   r¬   r˜   rÎ   ÚrcodeZNOERRORÚTransferErrorr  Zanswerr
   Ú	FormErrorr  r  Úcopyr  ZSerialÚAXFRÚhad_tsig)'r{   r  r  r  r   r3   r˜   r  r  r"   r9   r|   r  r  r  r‡   r#  r°   r8   rw   Ú	sock_typern   r6   r   rÝ   râ   ÚdoneZdelete_modeZexpecting_SOAZ	soa_rrsetr  Zonamer  Úmexpirationrç   Úis_ixfrr´   r'  Zanswer_indexr   r   r   r  ó  sÌ    E
   ÿ


ÿÿø




ÿ
þþr  c                   @   s   e Zd ZdZdZdZdZdS )ÚUDPModea  How should UDP be used in an IXFR from :py:func:`inbound_xfr()`?

    NEVER means "never use UDP; always use TCP"
    TRY_FIRST means "try to use UDP but fall back to TCP if needed"
    ONLY means "raise ``dns.xfr.UseTCP`` if trying UDP does not succeed"
    r   rq   rß   N)r@   rA   rB   rW   ÚNEVERZ	TRY_FIRSTÚONLYr   r   r   r   r1  ­  s   r1  )
r{   Útxn_managerrÆ   r3   r   r"   r9   r|   Úudp_moder�   c	                 C   s>  |dkrt j |¡\}}	nt j |¡}	|jd j}
|
t jjk}| ¡ }| 	¡ }t
| |||ƒ\}}}t|ƒ\}}d}|�r:d}|r–|tjkr–tj}d}n
tj}d}t|||ƒ��„}t|||ƒ |rÐt||d|ƒ n t dt|ƒ¡| }t|||ƒ t j ||
|	|¡��$}d}d}|�st|ƒ\}}|dk�s>|dk	�rB||k�rB|}|�rZt|d|ƒ\}}n&t|d|ƒ}t d|¡\}t|||ƒ}t jj||j|jd||| |d�}z|  |¡}W nF t jj!k
�rö   |�sÐt"‚|tj#k�rÞ‚ d}d}tj}Y �qY nX |j$}�q|�s$|j�r$|j%�s$t j& 'd	¡‚W 5 Q R X W 5 Q R X qrdS )
aŸ  Conduct an inbound transfer and apply it via a transaction from the
    txn_manager.

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *txn_manager*, a ``dns.transaction.TransactionManager``, the txn_manager
    for this transfer (typically a ``dns.zone.Zone``).

    *query*, the query to send.  If not supplied, a default query is
    constructed using information from the *txn_manager*.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *timeout*, a ``float``, the number of seconds to wait for each
    response message.  If None, the default, wait forever.

    *lifetime*, a ``float``, the total number of seconds to spend
    doing the transfer.  If ``None``, the default, then there is no
    limit on the time the transfer may take.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *udp_mode*, a ``dns.query.UDPMode``, determines how UDP is used
    for IXFRs.  The default is ``dns.UDPMode.NEVER``, i.e. only use
    TCP.  Other possibilities are ``dns.UDPMode.TRY_FIRST``, which
    means "try UDP but fallback to TCP if needed", and
    ``dns.UDPMode.ONLY``, which means "try UDP and raise
    ``dns.xfr.UseTCP`` if it does not succeed.

    Raises on errors.
    Nr   TFrä   rÇ   rß   r  r  )(r	   r  r!  Zextract_serial_from_queryÚquestionr  r  r"  Zfrom_wire_originrœ   r}   r#   r1  r2  r,   rÍ   r-   r+   r.   r½   rå   r%  r¤   rÞ   ZInboundr¹   rÛ   ræ   r«   r¬   r˜   rÎ   Zprocess_messageZUseTCPrÏ   r3  r  r,  r
   r)  )r{   r4  rÆ   r3   r   r"   r9   r|   r5  r  r  r0  r  r°   r8   rw   r6   r   Úretryr-  Zis_udprn   râ   Zinboundr.  r  r/  Zrwirerç   rÝ   r´   r   r   r   Úinbound_xfrº  s†    /   ÿ

ÿÿø


r8  )T)NN)N)
NNFFNrÃ   FFFN)
NrÌ   Nr   FFFFNF)
NrÌ   Nr   FFFNNF)N)NFNrÃ   F)NrÌ   Nr   FFN)
Nr  Nr   FFNNNT)	Nr  Nr   FFNTN)wrW   r¥   r    Úenumrê   rð   Úos.pathr_   r,   rå   r   Útypingr   r   r   r   r   Zdns._featuresr	   Zdns.exceptionZdns.inetZdns.messageZdns.nameZdns.quicZ	dns.rcodeZdns.rdataclassZdns.rdatatypeZ
dns.serialZdns.transactionZdns.tsigZdns.xfrr   r   Z	_featuresZhaveZ_have_httpxZhttpcore._backends.syncr1   r›   ZNetworkBackendZ_CoreNetworkBackendZ	_backendsÚsyncZ
SyncStreamr/   r   ZHTTPTransportrD   rš   rK   ÚImportErrorr€   r
   ZDNSExceptionrU   r)  rX   rY   rZ   r  r(  r#   ri   rj   Úhasattrrk   r^   ÚSelectSelectorro   rp   rt   ry   r}   r+   rJ   r«   r¿   r£   ÚfloatÚintÚboolrµ   r¹   r½   ÚbytesrÂ   r  ÚNameZtsigÚKeyrË   rÑ   rÕ   rÛ   rÞ   rã   rè   r.   rÔ   rô   rO   r   rP   r  r  ZSyncQuicConnectionr  r+  Z
rdataclassr  Zdefault_algorithmr  Z
RdataClassÚIntEnumr1  r2  ZtransactionZTransactionManagerr8  r   r   r   r   Ú<module>   s†  	
4 ÿ
,
ñ
ð  ü
û          õ
ôm          ôó^          ôóX ý
ü      úù/       ÷öD 
þ          ô
ón         õ

ôZñð ;÷
ö