a Meh@sfdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlmZddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#e"rddl$Z$e j%j&Z'ddZ(d6dd Z)d7e j*j+e e j,j-e.fee e/e e0e/fd d d Z1d8e j*j+e ee e/e2e2e ee j3j4e j5j6fe e.e2e2e2e e j,j-ed ddZ7d9e j,j-e8e e/e0e e8e0e2e2e2e2e e j*j+e e j*j9e2e j,j-dddZ:d:e j,j-e8e e/e0e e8e0e2e2e2e e j*j+e e j*j;e e j*j9e2e e j,j-e2fdddZde j,j-e8e e/e0e e8e0e2e2e e j*j;e e j*j9e e#jAe e8e e2e8fe j,j-d&d'd(ZBdd)ddd d dd*d%d%ddejCf e j,j-e8e e/e0e e8e0e2e2e d+e8e2e e2e8fe e8e d,e e0e j,j-d-d.d/ZDddddddejEdfe8e jFjGe e j,j-e0e e/e e/e e8e0ee e j*j9dd0 d1d2ZHd?e j,j-e8e e/e0e e8e0e2e2e e jIjJe e2e8fe e j*j9e e8e j,j-d3 d4d5ZIdS)@zTalk to a DNS server.N)AnyDictOptionalTupleUnion) NullContext) BadResponseNoDOHNoDOQUDPMode_compute_times_make_dot_ssl_context_matches_destination _remaininghave_dohsslcCsN|s|rF|dur>|tjkr d}n|tjkr0d}ntd|||fSdSdS)Nz0.0.0.0z::zunknown address family )socketAF_INETAF_INET6NotImplementedError)afZaddressportr2/usr/lib/python3.9/site-packages/dns/asyncquery.py _source_tuple:s  rcCs*|dur"|st}t||dSdSdS)Nr)timemax) expirationZnowrrr_timeoutJs r)sockwhat destinationrreturncs@t|tjjr|}t}|||t||IdH}||fS)aSend a DNS message to the specified UDP socket. *sock*, a ``dns.asyncbackend.DatagramSocket``. *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. The expiration value is meaningless for the asyncio backend, as asyncio's transport sendto() never blocks. Returns an ``(int, float)`` tuple of bytes sent and the sent time. N) isinstancednsmessageMessageto_wirersendtor)rr r!r sent_timenrrrsend_udpSs r+F) rr!rignore_unexpectedone_rr_per_rrsetkeyring request_macignore_trailingraise_on_truncation ignore_errorsqueryr"c  sd} |dt|IdH\} } t|j| ||s0qt} ztjj| |||||d}Wnntjjy}z6| r| dur| |sWYd}~qnWYd}~n&d}~0t y| rYqnYn0| r| dur| |sq|| | fS)ajRead a DNS message from a UDP socket. *sock*, a ``dns.asyncbackend.DatagramSocket``. See :py:func:`dns.query.receive_udp()` for the documentation of the other parameters, and exceptions. Returns a ``(dns.message.Message, float, tuple)`` tuple of the received message, the received time, and the address where the message arrived from. r,N)r/r0r.r1r2) recvfromrrfamilyrr$r% from_wire Truncated is_response Exception)rr!rr-r.r/r0r1r2r3r4wire from_address received_timererrr receive_udpqs@    rA5)qwheretimeoutrsource source_portr-r.r1r2rbackendr3r"c  s$|} t|\}}tj|}t||f|}| r_rrrudps@       rW)rCrDrErrFrGr-r.r1udp_socktcp_sockrHr3r"c stz0t|||||||||d| | | IdH} | dfWStjjynt||||||||| | IdH} | dfYS0dS)aReturn the response to the query, trying UDP first and falling back to TCP if UDP results in a truncated response. *udp_sock*, a ``dns.asyncbackend.DatagramSocket``, 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 the *source*, *source_port*, and *backend* are ignored for the UDP query. *tcp_sock*, a ``dns.asyncbackend.StreamSocket``, or ``None``, the socket to use for the TCP query. If ``None``, the default, a socket is created. Note that if a socket is provided *where*, *source*, *source_port*, and *backend* are ignored for the TCP query. *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``, the default, then dnspython will use the default backend. See :py:func:`dns.query.udp_with_fallback()` for the documentation of the other parameters, exceptions, and return type of this method. TNF)rWr$r%r9tcp)rCrDrErrFrGr-r.r1rXrYrHr3responserrrudp_with_fallbacks>#   r\)rr rr"cs\t|tjjr|jdd}nt|dd|}t}||t ||IdHt||fS)zSend a DNS message to the specified TCP socket. *sock*, a ``dns.asyncbackend.StreamSocket``. See :py:func:`dns.query.send_tcp()` for the documentation of the other parameters, exceptions, and return type of this method. T)Zprepend_lengthZbigN) r#r$r%r&r'lento_bytesrsendallr)rr rtcpmsgr)rrrsend_tcp4s rbcsHd}|dkrD||t|IdH}|dkr.t|t|}||}q|S)z|Read the specified number of bytes from stream. Keep trying until we either get the desired amount, or we hit EOF. r,rN)ZrecvrEOFErrorr^)rcountrrUr*rrr _read_exactlyMs  re)rrr.r/r0r1r"c sXt|d|IdH}td|\}t|||IdH}t} tjj|||||d} | | fS)zRead a DNS message from a TCP socket. *sock*, a ``dns.asyncbackend.StreamSocket``. See :py:func:`dns.query.receive_tcp()` for the documentation of the other parameters, exceptions, and return type of this method. r]N!Hr/r0r.r1)restructunpackrr$r%r8) rrr.r/r0r1ldatalr<r>r?rrr receive_tcp[srl) rCrDrErrFrGr.r1rrHr"c  s|} t|\} } |r0|IdHt|} nJtj|}t|||}||f}| s^tj } | |t j d|||IdH} | 4IdHd}t || | IdHt|| ||j|j|IdH\}}|| |_||st|WdIdHS1IdHs0YdS)aOReturn the response obtained after sending a query via TCP. *sock*, a ``dns.asyncbacket.StreamSocket``, or ``None``, the socket to use for the query. If ``None``, the default, a socket is created. Note that if a socket is provided *where*, *port*, *source*, *source_port*, and *backend* are ignored. *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``, the default, then dnspython will use the default backend. See :py:func:`dns.query.tcp()` for the documentation of the other parameters, exceptions, and return type of this method. Nr)r'r Z getpeernamerr$rIrJrrLrMrNr SOCK_STREAMrbrlr/rPrr:r)rCrDrErrFrGr.r1rrHr<rQrrRrrSrTrUr?r>rrrrZys,        rZUT)rCrDrErrFrGr.r1rrH ssl_contextserver_hostnameverifyr"c  st|\} }|rt|}n`| dur,t| | } tj|}t|||}||f}| sZtj} | |t j d|||| | IdH}|4IdHT}t |}t |||||||||| IdH}t}|| |_|WdIdHS1IdHs0YdS)aReturn the response obtained after sending a query via TLS. *sock*, an ``asyncbackend.StreamSocket``, 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 connected SSL stream socket, and *where*, *port*, *source*, *source_port*, *backend*, *ssl_context*, and *server_hostname* are ignored. *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``, the default, then dnspython will use the default backend. See :py:func:`dns.query.tls()` for the documentation of the other parameters, exceptions, and return type of this method. Nr)r rr r$rIrJrrLrMrNrrmrrZr)rCrDrErrFrGr.r1rrHrorprqrQrrRrrSrTrUr[Zend_timerrrtlssJ         rriz /dns-queryzhttpx.AsyncClientzdns.asyncresolver.Resolver)rCrDrErrFrGr.r1clientpathpostrqbootstrap_addressresolverr7r"c s&tst|r t|tjs td|}ztj |}WntyNd}Yn0d}ddi}|durtj |r|t j krd ||| }q|t jkrd ||| }n|}tj}|durd}d}n|}|}||dd| || | |d }|rt|}ntjdd| |d }|4IdH}| rT|dtt|d ||j|||d |IdH}n:t|d }|}||j||d|id|IdH}WdIdHq1IdHs0Y|jdks|jdkrtd ||j|jtjj |j|j!|j"||d}|j#$|_%|&|s"t'|S)aReturn the response obtained after sending a query via DNS-over-HTTPS. *client*, a ``httpx.AsyncClient``. If provided, the client to use for the query. Unlike the other dnspython async functions, a backend cannot be provided in this function because httpx always auto-detects the async backend. See :py:func:`dns.query.https()` for the documentation of the other parameters, exceptions, and return type of this method. z.session parameter must be an httpx.AsyncClientNZacceptzapplication/dns-messagezhttps://{}:{}{}zhttps://[{}]:{}{}rT) local_addresshttp1http2rq local_portrvrwr7)ryrzrq transport)z content-typezcontent-length)headerscontent=r$)r}paramsi+z4{} responded with status code {} Response body: {!r}rg)(rr r#httpxZ AsyncClient ValueErrorr'r$rIrJZ is_addressrrformatrrLrMZget_transport_classrupdatestrr^wait_forrubase64Zurlsafe_b64encoderstripdecodegetZ status_coder~r%r8r/r0elapsedZ total_secondsrr:r)rCrDrErrFrGr.r1rsrtrurqrvrwr7r<rr|r}urlrHrxr{rRZ the_clientr[Ztwirer?rrrhttpss         8   r) rD txn_managerr4rrElifetimerFrGudp_moderHr"c # s|durtj|\}} n tj|} |jdj} | tjjk} |} | }tj |}t |||}||f}t |\}}d}|rd}| r|tjkrtj}d}n tj}d}| stj} | ||d||t|IdH}|4IdH|r|||t|IdHn&tdt||}|||IdHtj|| | |x}d}d}|st |\}}|dus||dur||kr|}|rt||f|}t|}|d|IdH\}}t|||drqqn2t |d|IdH} t!d| \}!t ||!|IdH}| tjjk} tj"j#||j$|j%d| || | d}"z|&|"}WnDtjj'y~|sXJ|tj(krfd}d}tj}YqLYn0|"j)}qL|s|j$r|"j*stj+,d Wdn1s0YWdIdHq~1IdHs0Yq~dS) amConduct an inbound transfer and apply it via a transaction from the txn_manager. *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``, the default, then dnspython will use the default backend. See :py:func:`dns.query.inbound_xfr()` for the documentation of the other parameters, exceptions, and return type of this method. NrTFrfr5r])r/r0xfrorigintsig_ctxZmultir.z missing TSIG)-r$rZ make_queryZextract_serial_from_queryZquestionrdtypeZ rdatatypeZIXFRZfrom_wire_originr'rIrJrr r NEVERrrOrmrLrMrNrr(rhpackr^r`ZInboundrKr6rrerir%r8r/rPZprocess_messageZUseTCPZONLYrZhad_tsig exceptionZ FormError)#rDrr4rrErrFrGrrHserialrZis_ixfrrr<rrSrTrVrZretryZ sock_typeZis_udprUraZinboundZdonerZ mexpirationr!Zrwirer=rjrkr?rrr inbound_xfrls                 r) rCrDrErrFrGr.r1 connectionrqrHrpr"c  stjjstdd|_|} |r8tjj} tjj}|}ntj| \} }| 4IdH}||| | d4IdH}|s|||||}t |\}}| |IdH}|4IdH>| | dIdH| t |IdH} WdIdHq1IdHs0Yt}WdIdHq81IdHs.0Ytjj| |j|j||d}WdIdHq1IdHsv0Yt||d|_||st|S)aiReturn the response obtained after sending an asynchronous query via DNS-over-QUIC. *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``, the default, then dnspython will use the default backend. See :py:func:`dns.query.quic()` for the documentation of the other parameters, exceptions, and return type of this method. zDNS-over-QUIC is not available.rN)Z verify_modeZ server_nameTrgg)r$quicZ have_quicr idr'Z null_factoryZfactories_for_backendZconnectr Z make_streamsendZreceiverrr%r8r/r0rr:r)rCrDrErrFrGr.r1rrqrHrpr<ZcfactoryZmfactoryZthe_connectioncontextZ the_managerstartrstreamZfinishr?rrrrsB @64 r)N)N) NNFFNr,FFFN) NrBNrFFFFNNF) NrBNrFFFNNNF)N)NFNr,F)NrBNrFFNN) NrnNrFFNNNNT) NrnNrFFNTNN)K__doc__r contextlibrrhrtypingrrrrrZdns.asyncbackendr$Z dns.exceptionZdns.inetZ dns.messageZdns.nameZdns.quicZ dns.rcodeZdns.rdataclassZ dns.rdatatypeZdns.transactionZdns._asyncbackendrZ dns.queryrr r r r r rrrrrrIZlow_level_address_tuplerKrrrLZDatagramSocketr%r&bytesfloatintr+boolnameNameZtsigZKeyrArZBackendrWZ StreamSocketr\rbrerlrZZ SSLContextrrZ AF_UNSPECrrZ transactionZTransactionManagerrrZAsyncQuicConnectionrrrrs 0     @   E    G  !   ;    I  x   h