
    |;il+                       d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddlmZmZmZ ddlmZm Z m!Z! g dZ" G d de      Z# G d de      Z$ G d d      Z%y)a  Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine

This module provides a framework for the use of DNS Service Discovery
using IP multicast.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
    )annotationsN)	Awaitable)TracebackType)Callable   )Zeroconf)DNSQuestionType)NotRunningException)ServiceListener)_ServiceBrowserBase)AsyncServiceInfoServiceInfo)ZeroconfServiceTypes)InterfaceChoiceInterfacesType	IPVersion)_BROWSER_TIME
_MDNS_PORT_SERVICE_TYPE_ENUMERATION_NAME)AsyncServiceBrowserr   AsyncZeroconfAsyncZeroconfServiceTypesc                  |     e Zd ZdZdddeedf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZd	dZ	 	 	 	 	 	 	 	 d
dZ	 xZ
S )r   a  Used to browse for a service for specific type(s).

    Constructor parameters are as follows:

    * `zc`: A Zeroconf instance
    * `type_`: fully qualified service type name
    * `handler`: ServiceListener or Callable that knows how to process ServiceStateChange events
    * `listener`: ServiceListener
    * `addr`: address to send queries (will default to multicast)
    * `port`: port to send queries (will default to mdns 5353)
    * `delay`: The initial delay between answering questions
    * `question_type`: The type of questions to ask (DNSQuestionType.QM or DNSQuestionType.QU)

    The listener object will have its add_service() and
    remove_service() methods called when this browser
    discovers changes in the services availability.
    Nc	           
     R    t         	|   ||||||||       | j                          y N)super__init___async_start)
selfzeroconftype_handlerslisteneraddrportdelayquestion_type	__class__s
            C/home/ubuntu/myenv/lib/python3.12/site-packages/zeroconf/asyncio.pyr   zAsyncServiceBrowser.__init__D   s-     	5(HdD%Q^_    c                ,   K   | j                          yw)zCancel the browser.N)_async_cancelr   s    r)   async_cancelz AsyncServiceBrowser.async_cancelR   s     s   c                   K   | S wr    r-   s    r)   
__aenter__zAsyncServiceBrowser.__aenter__V           c                @   K   | j                          d {    y 7 wr   )r.   r   exc_typeexc_valexc_tbs       r)   	__aexit__zAsyncServiceBrowser.__aexit__Y   s"      !!! 	"   )r    r   r!   z
str | listr"   z2ServiceListener | list[Callable[..., None]] | Noner#   zServiceListener | Noner$   z
str | Noner%   intr&   r;   r'   DNSQuestionType | NonereturnNoner=   r>   )r=   r   r6   ztype[BaseException] | Noner7   zBaseException | Noner8   zTracebackType | Noner=   zbool | None)__name__
__module____qualname____doc__r   r   r   r.   r1   r9   __classcell__)r(   s   @r)   r   r   1   s    , HL+/"04  E	
 )    . 
, & %	
 
r*   r   c                  R    e Zd ZdZeddej                  df	 	 	 	 	 	 	 	 	 dd       Zy)r   z)An async version of ZeroconfServiceTypes.N   c                X  K   |xs t        ||      } |        }t        |j                  t        |      }t	        j
                  |       d{    |j                          d{    ||j                          d{    t        t        |j                              S 7 T7 >7 &w)a  
        Return all of the advertised services on any local networks.

        :param aiozc: AsyncZeroconf() instance.  Pass in if already have an
                instance running or if non-default interfaces are needed
        :param timeout: seconds to wait for any responses
        :param interfaces: interfaces to listen on.
        :param ip_version: IP protocol version to use.
        :return: tuple of service type strings
        )
interfaces
ip_version)r#   N)r   r   r    r   asynciosleepr.   async_closetuplesortedfound_services)clsaiozctimeoutrI   rJ   local_zcr#   async_browsers           r)   
async_findz$AsyncZeroconfServiceTypes.async_findf   s     $ WMZJW5+=

 mmG$$$((*** =&&(((VH33455 	%* )s6   AB*B$B*'B&(B*B(#B*&B*(B*)
rR   zAsyncZeroconf | NonerS   zint | floatrI   r   rJ   IPVersion | Noner=   ztuple[str, ...])rA   rB   rC   rD   classmethodr   AllrV   r0   r*   r)   r   r   c   s[    3 '+ %4%8%8'+ 6# 6  6 #	 6
 % 6 
 6  6r*   r   c                      e Zd ZdZej
                  ddddf	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	ddZ
dd	Z	 	 d	 	 	 	 	 	 	 	 	 dd
ZddZddZddZddZ	 	 	 	 	 	 	 	 ddZy)r   aG  Implementation of Zeroconf Multicast DNS Service Discovery

    Supports registration, unregistration, queries and browsing.

    The async version is currently a wrapper around Zeroconf which
    is now also async. It is expected that an asyncio event loop
    is already running before creating the AsyncZeroconf object.
    FNc                B    |xs t        ||||      | _        i | _        y)a  Creates an instance of the Zeroconf class, establishing
        multicast communications, and listening.

        :param interfaces: :class:`InterfaceChoice` or a list of IP addresses
            (IPv4 and IPv6) and interface indexes (IPv6 only).

            IPv6 notes for non-POSIX systems:
            * `InterfaceChoice.All` is an alias for `InterfaceChoice.Default`
              on Python versions before 3.8.

            Also listening on loopback (``::1``) doesn't work, use a real address.
        :param ip_version: IP versions to support. If `choice` is a list, the default is detected
            from it. Otherwise defaults to V4 only for backward compatibility.
        :param apple_p2p: use AWDL interface (only macOS)
        )rI   unicastrJ   	apple_p2pN)r   r    async_browsers)r   rI   r\   rJ   r]   zcs         r)   r   zAsyncZeroconf.__init__   s/    .  
h!!	
 KMr*   c                \   K   | j                   j                  |||||       d{   S 7 w)a6  Registers service information to the network with a default TTL.
        Zeroconf will then respond to requests for information for that
        service.  The name of the service may be changed if needed to make
        it unique on the network. Additionally multiple cooperating responders
        can register the same service on the network for resilience
        (if you want this behavior set `cooperating_responders` to `True`).

        The service will be broadcast in a task. This task is returned
        and therefore can be awaited if necessary.
        N)r    async_register_service)r   infottlallow_name_changecooperating_respondersstricts         r)   ra   z$AsyncZeroconf.async_register_service   s6     $ ]]99#(*@&
 
 	
 
s   #,*,c                T   K   | j                   j                          d{    y7 w)zUnregister all registered services.

        Unlike async_register_service and async_unregister_service, this
        method does not return a future and is always expected to be
        awaited since its only called at shutdown.
        N)r    async_unregister_all_servicesr-   s    r)   rh   z+AsyncZeroconf.async_unregister_all_services   s      mm99;;;s   (&(c                T   K   | j                   j                  |       d{   S 7 w)zUnregister a service.

        The service will be broadcast in a task. This task is returned
        and therefore can be awaited if necessary.
        N)r    async_unregister_servicer   rb   s     r)   rj   z&AsyncZeroconf.async_unregister_service   s#      ]];;DAAAA   (&(c                T   K   | j                   j                  |       d{   S 7 w)a  Registers service information to the network with a default TTL.
        Zeroconf will then respond to requests for information for that
        service.

        The service will be broadcast in a task. This task is returned
        and therefore can be awaited if necessary.
        N)r    async_update_servicerk   s     r)   rn   z"AsyncZeroconf.async_update_service   s#      ]]77====rl   c                  K   | j                   j                  sFt        j                  t              5  | j                   j                  d       d{    ddd       | j                          d{    | j                          d{    | j                   j                          d{    y7 _# 1 sw Y   ^xY w7 M7 77 w)z^Ends the background threads, and prevent this instance from
        servicing further queries.g      ?)rS   N)	r    done
contextlibsuppressr
   async_wait_for_start"async_remove_all_service_listenersrh   _async_closer-   s    r)   rM   zAsyncZeroconf.async_close   s      }}!!$$%89 Fmm888EEEF5577700222mm((*** FF F72*s^   0C B4B2B4C2C 3C
C!C,C-C2B44B=9CCCc                Z   K   | j                   j                  ||||       d{   S 7 w)a  Returns network's service information for a particular
        name and type, or None if no service matches by the timeout,
        which defaults to 3 seconds.

        :param type_: fully qualified service type name
        :param name: the name of the service
        :param timeout: milliseconds to wait for a response
        :param question_type: The type of questions to ask (DNSQuestionType.QM or DNSQuestionType.QU)
        N)r    async_get_service_info)r   r!   namerS   r'   s        r)   rw   z$AsyncZeroconf.async_get_service_info   s*       ]]99%wP]^^^^s   "+)+c                   K   | j                  |       d{    t        | j                  ||      | j                  |<   y7 )w)zAdds a listener for a particular service type.  This object
        will then have its add_service and remove_service methods called when
        services of that type become available and unavailable.N)async_remove_service_listenerr   r    r^   )r   r!   r#   s      r)   async_add_service_listenerz(AsyncZeroconf.async_add_service_listener   s?      00:::(;DMM5RZ([H% 	;s   AA*Ac                   K   || j                   v r3| j                   |   j                          d{    | j                   |= yy7 w)<Removes a listener from the set that is currently listening.N)r^   r.   )r   r#   s     r)   rz   z+AsyncZeroconf.async_remove_service_listener  sG     t***%%h/<<>>>##H- +>s   /AAAc                ~    K   t        j                   fdt         j                        D          d{    y7 w)r}   c              3  @   K   | ]  }j                  |        y wr   )rz   ).0r#   r   s     r)   	<genexpr>zCAsyncZeroconf.async_remove_all_service_listeners.<locals>.<genexpr>  s     exd00:es   N)rK   gatherlistr^   r-   s   `r)   rt   z0AsyncZeroconf.async_remove_all_service_listeners  s1     nne4PTPcPcKde
 	
 	
s   2=;=c                   K   | S wr   r0   r-   s    r)   r1   zAsyncZeroconf.__aenter__  r2   r3   c                @   K   | j                          d {    y 7 wr   )rM   r5   s       r)   r9   zAsyncZeroconf.__aexit__  s"          	!r:   )rI   r   r\   boolrJ   rW   r]   r   r_   zZeroconf | Noner=   r>   )NFFT)rb   r   rc   z
int | Nonerd   r   re   r   rf   r   r=   r   r?   )rb   r   r=   r   )i  N)
r!   strrx   r   rS   r;   r'   r<   r=   zAsyncServiceInfo | None)r!   r   r#   r   r=   r>   )r#   r   r=   r>   )r=   r   r@   )rA   rB   rC   rD   r   rY   r   ra   rh   rj   rn   rM   rw   r{   rz   rt   r1   r9   r0   r*   r)   r   r      sJ    &5%8%8'+"M"M M %	M
 M M 
MD "'',

 
  	

 !%
 
 

,<B>+ 04__ _ 	_
 ._ 
!_$\.
, & %	
 
r*   r   )&rD   
__future__r   rK   rq   collections.abcr   typesr   typingr   _corer   _dnsr	   _exceptionsr
   	_servicesr   _services.browserr   _services.infor   r   _services.typesr   
_utils.netr   r   r   constr   r   r   __all__r   r   r   r0   r*   r)   <module>r      sn   , #   %    ! , & 2 9 1 B B L L/- /d$6 4 $6NS Sr*   