
    8jM                    L    d Z ddlmZ ddlmZ ddlmZ eZ G d d          Z	d	S )
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
    )annotations   )ServiceNameAlreadyRegistered   )ServiceInfoc                  v    e Zd ZdZdZd!dZd"dZd#d
Zd"dZd$dZ	d%dZ
d&dZd'dZd(dZd)dZd"dZd*dZd S )+ServiceRegistryzA registry to keep track of services.

    The registry must only be accessed from
    the event loop as it is not thread safe.
    )	_serviceshas_entriesserverstypesreturnNonec                >    i | _         i | _        i | _        d| _        dS )z!Create the ServiceRegistry class.FN)r
   r   r   r   selfs    Q/home/user/adhan/venv/lib/python3.11/site-packages/zeroconf/_services/registry.py__init__zServiceRegistry.__init__(   s'     24&(
(*!&    infor   c                0    |                      |           dS )z"Add a new service to the registry.N)_addr   r   s     r   	async_addzServiceRegistry.async_add1   s    		$r   list[ServiceInfo] | ServiceInfoc                `    |                      t          |t                    r|n|g           dS )z'Remove a new service from the registry.N)_remove
isinstancelistr   s     r   async_removezServiceRegistry.async_remove5   s/    Zd33?TT$@@@@@r   c                \    |                      |g           |                     |           dS )z#Update new service in the registry.N)r   r   r   s     r   async_updatezServiceRegistry.async_update9   s)    dV		$r   list[ServiceInfo]c                N    t          | j                                                  S )zReturn all ServiceInfo.)r   r
   valuesr   s    r   async_get_service_infosz'ServiceRegistry.async_get_service_infos>   s    DN))++,,,r   namestrServiceInfo | Nonec                6    | j                             |          S )z$Return all ServiceInfo for the name.)r
   get)r   r'   s     r   async_get_info_namez#ServiceRegistry.async_get_info_nameB   s    ~!!$'''r   	list[str]c                *    t          | j                  S )zReturn all types.)r   r   r   s    r   async_get_typeszServiceRegistry.async_get_typesF   s    DJr   type_c                8    |                      | j        |          S )z%Return all ServiceInfo matching type.)_async_get_by_indexr   )r   r0   s     r   async_get_infos_typez$ServiceRegistry.async_get_infos_typeJ   s    ''
E:::r   serverc                8    |                      | j        |          S )z'Return all ServiceInfo matching server.)r2   r   )r   r4   s     r   async_get_infos_serverz&ServiceRegistry.async_get_infos_serverN   s    ''f===r   recordsdict[str, list]key_strc                R     |                     |          }|g S  fd|D             S )z*Return all ServiceInfo matching the index.Nc                *    g | ]}j         |         S  )r
   ).0r'   r   s     r   
<listcomp>z7ServiceRegistry._async_get_by_index.<locals>.<listcomp>W   s     ===t$===r   )r+   )r   r7   r9   record_lists   `   r   r2   z#ServiceRegistry._async_get_by_indexR   s9    kk#&&I========r   c                   |j         
J d            |j        | j        v rt          |                                 || j        |j        <   | j                            |j                                        g           	                    |j                   | j
                            |j         g           	                    |j                   d| _        dS )z!Add a new service under the lock.NzServiceInfo must have a serverT)
server_keyr9   r
   r   async_clear_cacher   
setdefaulttypelowerappendr   r   r   s     r   r   zServiceRegistry._addY   s    **,L***8t~%%..   #'tx 
dioo//44;;DHEEE44;;DHEEEr   infosc                ~   |D ]}| j                             |j                  }|$|j        J | j        |j                                                                     |j                   | j        |j                                     |j                   | j         |j        = t          | j                   | _
        dS )z!Remove a services under the lock.N)r
   r+   r9   rB   r   rE   rF   remover   boolr   )r   rH   r   old_service_infos       r   r   zServiceRegistry._removee   s     	) 	)D#~11$(;;'#.:::J',22445<<TXFFFL)45<<TXFFFtx((//r   N)r   r   )r   r   r   r   )r   r   r   r   )r   r#   )r'   r(   r   r)   )r   r-   )r0   r(   r   r#   )r4   r(   r   r#   )r7   r8   r9   r:   r   r#   )rH   r#   r   r   )__name__
__module____qualname____doc__	__slots__r   r   r    r"   r&   r,   r/   r3   r6   r2   r   r   r=   r   r   r	   r	      s         AI' ' ' '   A A A A   
- - - -( ( ( (       ; ; ; ;> > > >> > > >
  
  
  
 0 0 0 0 0 0r   r	   N)
rP   
__future__r   _exceptionsr   r   r   r(   r:   r	   r=   r   r   <module>rT      s    , # " " " " " 6 6 6 6 6 6      
Q0 Q0 Q0 Q0 Q0 Q0 Q0 Q0 Q0 Q0r   