
    |;i                       d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZ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!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA e.j                  j                  ZDe.j                  j                  ZFdZGe=hZHe<hZIe<e=hZJeKZLeMZNeOZPeQZRej                  ZTej                  ZVej                  ZWerddlXmYZY d!d"dZZ G d de      Z[ G d de[      Z\ G d de[      Z] G d de[      Z^ G d d e[      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)TYPE_CHECKINGcast   )DNSCache)
DNSAddressDNSNsec
DNSPointerDNSQuestionDNSQuestionType	DNSRecord
DNSServiceDNSText)BadTypeInNameException)QuestionHistory)log)DNSOutgoing)RecordUpdate)RecordUpdateListener)_resolve_all_futures_to_noneget_running_looprun_coro_with_timeoutwait_for_future_set_or_timeout)ZeroconfIPv4AddressZeroconfIPv6Addresscached_ip_addresses!get_ip_address_object_from_recordip_bytes_and_scope_to_addressstr_without_scope_id)service_type_name)	IPVersion_encode_address)current_time_millis)_ADDRESS_RECORD_TYPES	_CLASS_IN_CLASS_IN_UNIQUE_DNS_HOST_TTL_DNS_OTHER_TTL_DUPLICATE_QUESTION_INTERVAL_FLAGS_QR_QUERY_LISTENER_TIME
_MDNS_PORT_TYPE_A
_TYPE_AAAA
_TYPE_NSEC	_TYPE_PTR	_TYPE_SRV	_TYPE_TXT)   x   )ZeroconfServiceInfoc                    t        | j                  |      }| j                  j                  |      st        | j                  dt        |       dz
   S )z1Calculate the instance name from the ServiceInfo.strictN   )r    nametypeendswithr   len)infor9   service_names      J/home/ubuntu/myenv/lib/python3.12/site-packages/zeroconf/_services/info.pyinstance_name_from_service_inforB   o   sK     %TYYv>L99l+$$99-L))A-..    c                  P   e Zd ZdZdZdddddeefdddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7dZed8d       Z	e	j                  d9d	       Z	ed:d
       Zej                  d;d       Zed<d       Zed=d       Zd>dZd?d@dZdAdZ	 	 	 	 dBdZ	 	 	 	 dCdZej(                  fdDdZej(                  fdDdZdEdZdFdZd>dZd>dZd8dZ	 	 	 	 	 	 	 	 dGdZdHdZdHdZdIdZdJdZ dej(                  f	 	 	 	 	 dKdZ!	 	 	 	 	 	 dKd Z"d?dLd!Z#dLd"Z$d?dMd#Z%dMd$Z&d?dNd%Z'dNd&Z(d?dOd'Z)dOd(Z*d?dPd)Z+dPd*Z,dQd+Z-d>d,Z.d?dRd-Z/dSd.Z0edTd/       Z1dde2f	 	 	 	 	 	 	 	 	 	 	 dUd0Z3dVd1Z4dWd2Z5dde2f	 	 	 	 	 	 	 	 	 	 	 dUd3Z6	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dXd4Z7	 	 	 	 	 	 	 	 dYd5Z8d8d6Z9y)Zr6   a  Service information.

    Constructor parameters are as follows:

    * `type_`: fully qualified service type name
    * `name`: fully qualified service name
    * `port`: port that the service runs on
    * `weight`: weight of the service
    * `priority`: priority of the service
    * `properties`: dictionary of properties (or a bytes object holding the contents of the `text` field).
      converted to str and then encoded to bytes using UTF-8. Keys with `None` values are converted to
      value-less attributes.
    * `server`: fully qualified name for service host (defaults to name)
    * `host_ttl`: ttl used for A/SRV records
    * `other_ttl`: ttl used for PTR/TXT records
    * `addresses` and `parsed_addresses`: List of IP addresses (either as bytes, network byte order,
      or in parsed form as text; at most one of those parameters can be provided)
    * interface_index: scope_id or zone_id for IPv6 link-local addresses i.e. an identifier of the interface
      where the peer is connected to
    )_decoded_properties_dns_address_cache_dns_pointer_cache_dns_service_cache_dns_text_cache#_get_address_and_nsec_records_cache_ipv4_addresses_ipv6_addresses_name_new_records_futures_properties_query_record_typeshost_ttlinterface_indexkey	other_ttlportpriorityserver
server_keytextr<   weightNr   rC   )	addressesparsed_addressesrR   c
                  |
|t        d      |j                  t        |d            st        || _        d| _        || _        || _        |j                         | _	        g | _
        g | _        |
|
| _        n ||D cg c]  }t        |       c}| _        || _        || _        || _        |r|nd | _        |r|j                         nd | _        d | _        d | _        t+        |t,              r| j/                  |       n| j1                  |       || _        |	| _        d | _        d | _        d | _        d | _        d | _        d | _         tB        tD        tF        tH        h| _%        y c c}w )Nz:addresses and parsed_addresses cannot be provided togetherFr8   rC   )&	TypeErrorr=   r    r   rR   rY   r<   rM   lowerrS   rK   rL   r[   r"   rU   rZ   rV   rW   rX   rO   rE   
isinstancebytes	_set_text_set_propertiesrQ   rT   rN   rF   rG   rH   rI   rJ   r1   r2   r-   r.   rP   )selftype_r;   rU   rZ   rV   
propertiesrW   rQ   rT   r[   r\   rR   as                 rA   __init__zServiceInfo.__init__   sT   "  %5%AXYY~~/UCD((.		
::<:<:< &DN):JKQoa0KDN	  &fD,2&,,.=AAE j%(NN:&  , "@D!;?5959/3JN0$-y':#N ) Ls   E)c                    | j                   S )zThe name of the service.)rM   rd   s    rA   r;   zServiceInfo.name   s     zzrC   c                f    || _         |j                         | _        d| _        d| _        d| _        y)z#Replace the name and reset the key.N)rM   r_   rS   rH   rG   rI   )rd   r;   s     rA   r;   zServiceInfo.name   s0     
::<"&"&#rC   c                @    | j                  t        j                        S )zIPv4 addresses of this service.

        Only IPv4 addresses are returned for backward compatibility.
        Use :meth:`addresses_by_version` or :meth:`parsed_addresses` to
        include IPv6 addresses as well.
        )addresses_by_versionr!   V4Onlyrj   s    rA   r[   zServiceInfo.addresses   s     (()9)9::rC   c                   | j                   j                          | j                  j                          d| _        d| _        |D ]  }t        |      dk(  r#| j                  t        || j                        }nt        |      }|t        d|d      |j                  dk(  r4t        rt        |t              sJ | j                   j                  |       t        rt        |t              sJ | j                  j                  |        y)zoReplace the addresses list.

        This replaces all currently stored addresses, both IPv4 and IPv6.
        N   zGAddresses must either be IPv4 or IPv6 strings, bytes, or integers; got z6. Hint: convert string addresses with socket.inet_pton   )rK   clearrL   rF   rJ   r>   rR   r   r   r^   versionr   r`   r   appendr   )rd   valueaddressaddrs       rA   r[   zServiceInfo.addresses   s     	""$""$"&370 	2G7|r!d&:&:&F4Wd>R>RS*73|#;&\^  ||q  %d,?@@@$$++D1 %d,?@@@$$++D1#	2rC   c                z    | j                   | j                          t        r| j                   J | j                   S )zReturn properties as bytes.)rO   _unpack_text_into_propertiesr   rj   s    rA   rf   zServiceInfo.properties  s=     #--/##///rC   c                z    | j                   | j                          t        r| j                   J | j                   S )zReturn properties as strings.)rE   _generate_decoded_propertiesr   rj   s    rA   decoded_propertieszServiceInfo.decoded_properties  s=     ##+--/++777'''rC   c                J    d| _         d| _        d| _        d| _        d| _        y)z&Clear the cache for this service info.N)rF   rG   rH   rI   rJ   rj   s    rA   async_clear_cachezServiceInfo.async_clear_cache&  s*    "&"&"&#370rC   c                   K   | j                   st               | _         t        |xs t        j                         | j                   |       d{    y7 w)zHCalling task waits for a given number of milliseconds or until notified.N)rN   setr   asyncior   )rd   timeoutloops      rA   
async_waitzServiceInfo.async_wait.  sF     (((+D%,.G,,.0I0I7
 	
 	
s   AAAAc                   |j                   }|t        k(  rL| j                  D cg c]  }|j                   }}| j                  D cg c]  }|j                   }}g ||S |t
        k(  r$| j                  D cg c]  }|j                   c}S | j                  D cg c]  }|j                   c}S c c}w c c}w c c}w c c}w )a3  List addresses matching IP version.

        Addresses are guaranteed to be returned in LIFO (last in, first out)
        order with IPv4 addresses first and IPv6 addresses second.

        This means the first address will always be the most recently added
        address of the given IP version.
        )ru   _IPVersion_All_valuerK   packedrL   _IPVersion_V4Only_value)rd   rs   version_valuerw   ip_v4_packedip_v6_packeds         rA   rm   z ServiceInfo.addresses_by_version6  s      00484H4HIDDKKILI484H4HIDDKKILI1\1L1133,0,@,@ADDKKAA(,(<(<=== JI B=s   B3B89B=Cc                8    | j                  |j                        S )a<  List ip_address objects matching IP version.

        Addresses are guaranteed to be returned in LIFO (last in, first out)
        order with IPv4 addresses first and IPv6 addresses second.

        This means the first address will always be the most recently added
        address of the given IP version.
        )_ip_addresses_by_version_valueru   )rd   rs   s     rA   ip_addresses_by_versionz#ServiceInfo.ip_addresses_by_versionH  s     227==AArC   c                    |t         k(  rg | j                  | j                  S |t        k(  r| j                  S | j                  S )z9Backend for addresses_by_version that uses the raw value.)r   rK   rL   r   )rd   r   s     rA   r   z*ServiceInfo._ip_addresses_by_version_valueU  sJ     00AT))AD,@,@AA33'''###rC   c                p    | j                  |j                        D cg c]  }t        |       c}S c c}w )a;  List addresses in their parsed string form.

        Addresses are guaranteed to be returned in LIFO (last in, first out)
        order with IPv4 addresses first and IPv6 addresses second.

        This means the first address will always be the most recently added
        address of the given IP version.
        )r   ru   r   rd   rs   rw   s      rA   r\   zServiceInfo.parsed_addresses_  s0     8<7Z7Z[b[h[h7ijt$T*jjj   3c                p    | j                  |j                        D cg c]  }t        |       c}S c c}w )a  Equivalent to parsed_addresses, with the exception that IPv6 Link-Local
        addresses are qualified with %<interface_index> when available

        Addresses are guaranteed to be returned in LIFO (last in, first out)
        order with IPv4 addresses first and IPv6 addresses second.

        This means the first address will always be the most recently added
        address of the given IP version.
        )r   ru   strr   s      rA   parsed_scoped_addressesz#ServiceInfo.parsed_scoped_addressesj  s+     '+&I&I'--&XYdD	YYYr   c           	        g }d}d}|j                         D ]q  \  }}t        |t              r|j                  d      }d}|}|4t        |t              st        |      j                  d      }d}|d|z   z  }|j                  |       s |D ])  }dj                  |t	        t        |      f      |f      }+ |s:t        r-t        t        t        t        dz  f   |      | _        || _        y|| _        || _        y)z7Sets properties and text of this info from a dictionaryFrC   utf-8TN   =)itemsr`   r   encodera   rt   joinr>   r   r   dictrO   rY   )	rd   rf   list_properties_contain_strresultrS   ru   recorditems	            rA   rc   zServiceInfo._set_propertiesv  s   !&$**, 	!JC#s#jj))-&F !%/J--g6E-1*$,&LL 	!  	CDXXvuc$i\':DABF	C% #'UEDL-@(A:#N  	 $. 	rC   c                N    || j                   k(  ry|| _         d| _        d| _        y)z+Sets properties and text given a text fieldN)rY   rO   rE   )rd   rY   s     rA   rb   zServiceInfo._set_text  s(    499	#' rC   c           	         | j                   j                         D ci c],  \  }}|j                  dd      |dn|j                  dd      . c}}| _        yc c}}w )z0Generates decoded properties from the propertiesasciireplaceNr   )rf   r   decoderE   )rd   kvs      rA   r{   z(ServiceInfo._generate_decoded_properties  sW     --/$
1 HHWi(!)$'S\A]]$
  $
s   1Ac                    | j                   }t        |      }|dk(  ri | _        yd}i }||k  rC||   }|dz  }||||z    }|j                  d      }|d   }||vr|d   xs d||<   ||z  }||k  rC|| _        y)z&Unpacks the text field into propertiesr   Nr:   r   r   )rY   r>   rO   	partition)	rd   rY   endindexrf   length	key_valuekey_sep_valuerS   s	            rA   ry   z(ServiceInfo._unpack_text_into_properties  s    yy$i!8  "D02
ck%[FQJEUUV^4I%//5M"C*$"/"2":d
3VOE ck &rC   c                x    | j                   dt        | j                         t        | j                        z
  dz
   S )zName accessorNr:   )rM   r>   r<   rj   s    rA   get_namezServiceInfo.get_name  s.    zz@C

Oc$))n<q@AArC   c                    g }| j                  ||      D ]8  }|j                  |      rt        |      }|#||vs(|j                  |       : |j	                          |S )"Set IPv6 addresses from the cache.)'_get_address_records_from_cache_by_type
is_expiredr   rt   reverse)rd   zcnowr<   address_listr   ip_addrs          rA   !_get_ip_addresses_from_cache_lifoz-ServiceInfo._get_ip_addresses_from_cache_lifo  sq     IKBB2tL 	-F  %7?G"wl'B##G,	- 	rC   c                    t         r2t        t        t           | j	                  ||t
                    | _        y| j	                  ||t
              | _        y)r   N)r   r   listr   r   r.   rL   rd   r   r   s      rA   _set_ipv6_addresses_from_cachez*ServiceInfo._set_ipv6_addresses_from_cache  sG    #'()66r3
K$D 
 $(#I#I"cS]#^D rC   c                    t         r2t        t        t           | j	                  ||t
                    | _        y| j	                  ||t
              | _        y)z"Set IPv4 addresses from the cache.N)r   r   r   r   r   r-   rK   r   s      rA   _set_ipv4_addresses_from_cachez*ServiceInfo._set_ipv4_addresses_from_cache  sG    #'()66r3H$D 
 $(#I#I"cSZ#[D rC   c                    | j                   }d}|D ]"  }|| j                  ||j                  |      z  }$ |r|rt        |       yyy)zkUpdates service information from a DNS record.

        This method will be run in the event loop.
        FN)rN   _process_record_threadsafenewr   )rd   r   r   recordsnew_records_futuresupdatedrecord_updates          rA   async_update_recordsz ServiceInfo.async_update_records  s[    
 #77$ 	SMt66r=;L;LcRRG	S*()<= +7rC   c                   |j                  |      ry|j                  }t        |      }|t        u rr|| j                  k(  rb|}t
        rt        |t              sJ t        |      }|"t        j                  d||j                         y|j                  dk(  r{t
        rt        |t              sJ | j                  }||vr|j                  d|       y|j                  |d   j                  k7  r#|j!                  |       |j                  d|       yt
        rt        |t"              sJ | j$                  }	|| j$                  vr|	j                  d|       y|j                  | j$                  d   j                  k7  r#|	j!                  |       |	j                  d|       y|| j                  k7  ry|t&        u r6|}
t
        rt        |
t&              sJ | j)                  |
j*                         y|t,        u r|}t
        rt        |t,              sJ | j                  }|j.                  | _        |j                  | _        |j2                  | _        |j                  | _        |j4                  | _        |j6                  | _        |j8                  | _        || j                  k7  r$| j;                  ||       | j=                  ||       yy)zVThread safe record updating.

        Returns True if a new record was added.
        Fz3Encountered invalid address while processing %s: %srq   r   T)r   rS   r<   r   rX   r   r`   r   r   warningrv   rs   r   rK   insert
zc_integerremover   rL   r   rb   rY   r   r;   rM   rW   rU   rZ   rV   r   r   )rd   r   r   r   
record_keyrecord_typedns_address_recordr   ipv4_addressesipv6_addressesdns_text_recorddns_service_recordold_server_keys                rA   r   z&ServiceInfo._process_record_threadsafe  s   
 S!ZZ
6l*$t)F!'!"4jAAA78JKGI&&..
 !# %g/BCCC!%!5!5.0"))!W5
 %%):)E)EE"))'2"))!W5!'+>???!11Nd222%%a1
 !!T%9%9!%<%G%GG%%g.%%a1!'!$O!/7;;;NN?//0*$!'!"4jAAA!__N+00DJ)--DH,33DK0;;DO*//DI,33DK.77DM033B<33B<rC   c                &    | j                  ||      S ),Return matching DNSAddress from ServiceInfo.)_dns_addresses)rd   override_ttlrs   s      rA   dns_addresseszServiceInfo.dns_addressesB  s     ""<99rC   c                   |t         j                  u xr |du }| j                  |r| j                  S | j                  xs | j                  }||n| j
                  }t        }|j                  }| j                  |      D cg c]6  }t        ||j                  dk(  rt        nt        |||j                  d      8 }	}|r|	| _        |	S c c}w )r   N           )created)r!   AllrF   rW   rM   rQ   r&   ru   r   r   rs   r.   r-   r   )
rd   r   rs   	cacheabler;   ttlclass_r   r   r   s
             rA   r   zServiceInfo._dns_addressesJ  s     y}},E1E	"".9***{{(djj*6lDMM!  >>}M

  %oo2


 

 &-D#

s   ;C
c                $    | j                  |      S )#Return DNSPointer from ServiceInfo.)_dns_pointerrd   r   s     rA   dns_pointerzServiceInfo.dns_pointerf        ..rC   c                    |du }| j                   |r| j                   S t        | j                  t        t        ||n| j
                  | j                  d      }|r|| _         |S )r   Nr   )rG   r
   r<   r0   r%   rT   rM   rd   r   r   r   s       rA   r   zServiceInfo._dns_pointerj  sg     D(	"".9***II(4L$..JJ
 &,D#rC   c                $    | j                  |      S )#Return DNSService from ServiceInfo.)_dns_servicer   s     rA   dns_servicezServiceInfo.dns_service{  r   rC   c                Z   |du }| j                   |r| j                   S | j                  }t        rt        |t              sJ t        | j                  t        t        ||n| j                  | j                  | j                  || j                  xs | j                  d	      }|r|| _         |S )r   Nr   )rH   rU   r   r`   intr   rM   r1   r&   rQ   rV   rZ   rW   )rd   r   r   rU   r   s        rA   r   zServiceInfo._dns_service  s     D(	"".9***yydC(((JJ(4L$--MMKKKK%4::

 &,D#rC   c                $    | j                  |      S ) Return DNSText from ServiceInfo.)	_dns_textr   s     rA   dns_textzServiceInfo.dns_text  s    ~~l++rC   c                    |du }| j                   |r| j                   S t        | j                  t        t        ||n| j
                  | j                  d      }|r|| _         |S )r   Nr   )rI   r   rM   r2   r&   rT   rY   r   s       rA   r   zServiceInfo._dns_text  sg     D(	+	'''JJ(4L$..II
 #)D rC   c                &    | j                  ||      S ) Return DNSNsec from ServiceInfo.)	_dns_nsecrd   missing_typesr   s      rA   dns_nseczServiceInfo.dns_nsec  s    ~~m\::rC   c           	     x    t        | j                  t        t        ||n| j                  | j                  |d      S )r   r   )r	   rM   r/   r&   rQ   r   s      rA   r   zServiceInfo._dns_nsec  s7    JJ(4L$--JJ
 	
rC   c                $    | j                  |      S )MBuild a set of address records and NSEC records for non-present record types.)_get_address_and_nsec_recordsr   s     rA   get_address_and_nsec_recordsz(ServiceInfo.get_address_and_nsec_records  s    11,??rC   c                   |du }| j                   |r| j                   S t        j                         }t               }| j	                  |t
        j                        D ].  }|j                  |j                         |j                  |       0 |r=| j                  J d       |j                  | j                  t        |      |             |r|| _         |S )r   Nz+Service server must be set for NSEC record.)rJ   r$   copyr   r   r!   r   discardr<   addrW   r   r   )rd   r   r   r   r   dns_addresss         rA   r   z)ServiceInfo._get_address_and_nsec_records  s     D(	33?I;;;"7"<"<">"%%..|Y]]K 	%K!!+"2"23KK$	% ;;*Y,YY*KKtM':LIJ7>D4rC   c                    | j                   g S |j                  }t        r8t        t        t
           |j                  | j                   |t                    }|S |j                  | j                   |t              }|S )z!Get the addresses from the cache.)rX   cacher   r   r   r   get_all_by_detailsr%   )rd   r   _typer  r   s        rA   r   z3ServiceInfo._get_address_records_from_cache_by_type  sk    ??"IZ ((%KG  ..tyQGrC   c                b    | j                   #| j                  | _         | j                  | _        yy)z`Set the server if it is missing.

        This function is for backwards compatibility.
        N)rW   rM   rS   rX   rj   s    rA   set_server_if_missingz!ServiceInfo.set_server_if_missing  s)    
 ;;**DK"hhDO rC   c                >    | j                  ||xs
 t                     S zePopulate the service info from the cache.

        This method is designed to be threadsafe.
        )_load_from_cacher#   r   s      rA   load_from_cachezServiceInfo.load_from_cache  s     
 $$R)E0C0EFFrC   c                   |j                   }| j                  }|j                  | j                  t        t
              }|r| j                  |||       |j                  | j                  t        t
              }|r| j                  |||       || j                  k(  r\| j                  |t              D ]  }| j                  |||        | j                  |t              D ]  }| j                  |||        | j                  S r  )r  rX   get_by_detailsrM   r1   r%   r   r2   r   r-   r.   _is_complete)rd   r   r   r  original_server_keycached_srv_recordcached_txt_recordr   s           rA   r  zServiceInfo._load_from_cache  s    
 "oo!00Y	R++B0A3G!00Y	R++B0A3G$//1 FFr7S A//FC@AFFr:V A//FC@A   rC   c                h    t        | j                  duxr | j                  xs | j                        S ),The ServiceInfo has all expected properties.N)boolrY   rK   rL   rj   s    rA   r  zServiceInfo._is_complete  s.     DIIT)\t/C/C/[tG[G[]]rC   c                   |j                   J d       |j                   j                         sJ d       |j                   t               k(  rt        d      t	        t        | j                  |||||      |j                   |            S )a6  Returns true if the service could be discovered on the
        network, and updates this object with details discovered.

        While it is not expected during normal operation,
        this function may raise EventLoopBlocked if the underlying
        call to `async_request` cannot be completed.

        :param zc: Zeroconf instance
        :param timeout: time in milliseconds to wait for a response
        :param question_type: question type to ask
        :param addr: address to send the request to
        :param port: port to send the request to
        z7Zeroconf instance must have a loop, was it not started?z?Zeroconf instance loop must be running, was it already stopped?z6Use AsyncServiceInfo.async_request from the event loop)r   
is_runningr   RuntimeErrorr  r   async_request)rd   r   r   question_typerw   rU   s         rA   requestzServiceInfo.request
  s    * ww"]$]]"ww!!#f%ff#77&((WXX!""2wtTJ
 	
rC   c                    t         S N)r+   rj   s    rA   _get_initial_delayzServiceInfo._get_initial_delay+  s    rC   c                    t        t         S r!  )randint!_AVOID_SYNC_DELAY_RANDOM_INTERVALrj   s    rA   _get_random_delayzServiceInfo._get_random_delay.  s    9::rC   c                2  K   |j                   s|j                          d{    t               }| j                  ||      ryt        r|j
                  J d}| j                         }|}	||z   }
	 |j                  | d       | j                  s|
|k  r	 |j                  |        y|	|k  ru|xs |rt        nt        }| j                  |||      }d}|j                  r|j                  |||       ||z   }	|	| j                         z  }	|t        u r|t         k  rt         }| j#                  t%        |	|
      |z
  |j
                         d{    t               }| j                  s|j                  |        y7 Z7 0# |j                  |        w xY ww)a  Returns true if the service could be discovered on the
        network, and updates this object with details discovered.

        This method will be run in the event loop.

        Passing addr and port is optional, and will default to the
        mDNS multicast address and port. This is useful for directing
        requests to a specific host that may be able to respond across
        subnets.

        :param zc: Zeroconf instance
        :param timeout: time in milliseconds to wait for a response
        :param question_type: question type to ask
        :param addr: address to send the request to
        :param port: port to send the request to
        NTF)startedasync_wait_for_startr#   r  r   r   r"  async_add_listenerr  async_remove_listenerQU_QUESTIONQM_QUESTION_generate_request_query	questions
async_sendr&  r)   r   min)rd   r   r   r  rw   rU   r   first_requestdelaynext_lastthis_question_typeouts                rA   r  zServiceInfo.async_request1  s    0 zz))+++!#  S)77&&&'')W}	+!!$-''3; 2 $$T*1 C<)6)i-;]h&66r3@RSC$)M}} c46%KET3355E)[8UEa=a !=ooc%&6&<bggFFF)+3 ''6 $$T*[ ,P G $$T*sG    FE<AF2#F F(B&F E?F *F?F FFc
                L   |j                  |||      D 
ch c]  }
|
j                  |      r|
 }}
|	r|ryt        |||      }|rd|_        n'|j	                  |||      ry|j                  |||       |j                  |       |D ]  }
|j                  |
|        yc c}
w )z8Add a question with known answers if its not suppressed.NT)r	  is_staler   unicast
suppressesadd_question_at_timeadd_questionadd_answer_at_time)rd   r7  qu_questionquestion_historyr  r   r;   re   r   skip_if_known_answersanswerknown_answersquestions                rA    _add_question_with_known_answersz,ServiceInfo._add_question_with_known_answersy  s     "'!9!9$v!N
V\VeVefiVjF
 
 !]tUF3#H((3F11(CO"# 	0F""63/	0
s
   B!B!c                4   t        t              }| j                  }| j                  xs |}|j                  }|j
                  }|t        u }	t        | j                  v r!| j                  ||	||||t        t        d	       t        | j                  v r!| j                  ||	||||t        t        d	       t        | j                  v r!| j                  ||	||||t        t        d	       t        | j                  v r!| j                  ||	||||t        t        d	       |S )zGenerate the request query.TF)r   r*   rM   rW   r  r@  r,  r1   rP   rE  r%   r2   r-   r.   )
rd   r   r   r  r7  r;   rW   r  historyr?  s
             rA   r.  z#ServiceInfo._generate_request_query  s    /*zz$%%#{200011['5#tY	SW 00011['5#tY	SW d...11['5#vw	SX 11111['5#vz9V[ 
rC   c                ~     dj                  t               j                  dj                   fddD                    S )zString representationz{}({})z, c              3  @   K   | ]  }| d t        |        yw)=N)getattr).0r;   rd   s     rA   	<genexpr>z'ServiceInfo.__repr__.<locals>.<genexpr>  s,       &'$-01s   )	r<   r;   r[   rU   rZ   rV   rW   rf   rR   )formatr<   __name__r   rj   s   `rA   __repr__zServiceInfo.__repr__  s<    JII 
 
 	
rC   )re   r   r;   r   rU   
int | NonerZ   r   rV   r   rf   zbytes | dictrW   
str | NonerQ   r   rT   r   r[   zlist[bytes] | Noner\   zlist[str] | NonerR   rQ  returnNone)rS  r   )r;   r   rS  rT  )rS  list[bytes])ru   rU  rS  rT  )rS  zdict[bytes, bytes | None])rS  zdict[str, str | None])rS  rT  r!  )r   floatr   z asyncio.AbstractEventLoop | NonerS  rT  )rs   r!   rS  rU  )rs   r!   rS  5list[ZeroconfIPv4Address] | list[ZeroconfIPv6Address])r   int_rS  rW  )rs   r!   rS  z	list[str])rf   z%dict[str | bytes, str | bytes | None]rS  rT  )rY   ra   rS  rT  )r   r5   r   float_r<   rX  rS  z/list[ZeroconfIPv4Address | ZeroconfIPv6Address])r   r5   r   rY  rS  rT  )r   r5   r   rY  r   zlist[RecordUpdate]rS  rT  )r   r5   r   r   r   rY  rS  r  )r   int_ | Noners   r!   rS  list[DNSAddress])r   rZ  rS  r
   )r   rZ  rS  r   )r   rZ  rS  r   )r   z	list[int]r   rZ  rS  r	   )r   rZ  rS  zset[DNSRecord])r   r5   r
  rX  rS  r[  )r   r5   r   zfloat_ | NonerS  r  )r   r5   r   rY  rS  r  rS  r  )r   r5   r   rV  r  zDNSQuestionType | Nonerw   rR  rU   r   rS  r  )rS  rY  )rS  rX  )r7  r   r?  r  r@  r   r  r   r   rY  r;   str_re   rX  r   rX  rA  r  rS  rT  )r   r5   r   rY  r  r   rS  r   ):rO  
__module____qualname____doc__	__slots__r'   r(   rh   propertyr;   setterr[   rf   r|   r~   r   rm   r   r   r!   r   r\   r   rc   rb   r{   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r  r  r  r  r,   r  r"  r&  r  rE  r.  rP   rC   rA   r6   r6   y   s   *I<  #&!%'3O )--1&*3O3O 3O 	3O
 3O 3O !3O 3O 3O 3O &3O +3O $3O 
3Oj   
[[$ $ ; ; 2 2:     ( (8
>$B B	>B$!$	>$ 5>MM 	k <E== 
Z:(
&0B!'/3	8_\
>Sn %)&]]:!: : 
	:!  
	8/"/.,";

@"'G!. ^ ^ 15

 
 .	

 
 
 

B; 15FF F .	F
 F F 
FP00 0 *	0
 0 0 0 0 0  $0 
0:!'8G	8
rC   c                      e Zd ZdZy)AsyncServiceInfoz An async version of ServiceInfo.N)rO  r^  r_  r`  rd  rC   rA   rf  rf    s    *rC   rf  c                  6     e Zd ZdZd fdZedd       Z xZS )AddressResolverz%Resolve a host name to an IP address.c                @    t         |   |||       t        | _        yzInitialize the AddressResolver.)rW   N)superrh   _TYPE_A_AAAA_RECORDSrP   rd   rW   	__class__s     rA   rh   zAddressResolver.__init__  s    7#7 rC   c                Z    t        | j                        xs t        | j                        S r  )r  rK   rL   rj   s    rA   r  zAddressResolver._is_complete  s%     D(()GT$2F2F-GGrC   rW   r   rS  rT  r\  rO  r^  r_  r`  rh   rb  r  __classcell__rn  s   @rA   rh  rh    s!    /8
 H HrC   rh  c                  6     e Zd ZdZd fdZedd       Z xZS )AddressResolverIPv6z'Resolve a host name to an IPv6 address.c                @    t         |   |||       t        | _        yrj  )rk  rh   _TYPE_AAAA_RECORDSrP   rm  s     rA   rh   zAddressResolverIPv6.__init__  s    7#5 rC   c                ,    t        | j                        S rp  )r  rL   rj   s    rA   r  z AddressResolverIPv6._is_complete       D(())rC   rq  r\  rr  rt  s   @rA   rv  rv    s    16
 * *rC   rv  c                  6     e Zd ZdZd fdZedd       Z xZS )AddressResolverIPv4z'Resolve a host name to an IPv4 address.c                @    t         |   |||       t        | _        yrj  )rk  rh   _TYPE_A_RECORDSrP   rm  s     rA   rh   zAddressResolverIPv4.__init__  s    7#2 rC   c                ,    t        | j                        S rp  )r  rK   rj   s    rA   r  z AddressResolverIPv4._is_complete  rz  rC   rq  r\  rr  rt  s   @rA   r|  r|    s    13
 * *rC   r|  )T)r?   r6   r9   r  rS  r   )`r`  
__future__r   r   randomtypingr   r   _cacher   _dnsr   r	   r
   r   r   r   r   r   _exceptionsr   _historyr   _loggerr   _protocol.outgoingr   _record_updater   _updatesr   _utils.asyncior   r   r   r   _utils.ipaddressr   r   r   r   r   r   _utils.namer    
_utils.netr!   r"   _utils.timer#   constr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   ru   r   rn   r   r%  rx  r~  rl  ra   bytes_rV  rY  r   rX  r   r]  QUr,  QMr-  r$  _corer5   rB   r6   rf  rh  rv  r|  rd  rC   rA   <module>r     s<  , #   & 	 	 	 1 &  , ) +   , 3 -    $ !}}** #**00  %. ! \ ), 		

    
.. /K
& K
\+{ +Hk H*+ **+ *rC   