
    |;i                        d 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mZmZmZ  ed      d	d
dd       ZddZ  e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
    )annotations)	lru_cache   )BadTypeInNameException)_HAS_A_TO_Z_HAS_ASCII_CONTROL_CHARS_HAS_ONLY_A_TO_Z_NUM_HYPHEN&_HAS_ONLY_A_TO_Z_NUM_HYPHEN_UNDERSCORE_LOCAL_TRAILER_NONTCP_PROTOCOL_LOCAL_TRAILER_TCP_PROTOCOL_LOCAL_TRAILERi   )maxsizeT)strictc          	        t        |       dkD  rt        d|  d      | j                  t        t        f      r8| dt        t                j                  d      }| t        t               d }d}n|rt        d|  dt         d	t         d
      | j                  t              r;| dt        t                j                  d      }| t        t               dz   d }d}nt        d|  dt         d
      |s|r|j                         }|st        d      t        |      dk(  r t        |d         dk(  rt        d|  d      |d   dk7  rt        d| d      |dd }|rt        |      dkD  rt        d| d      d|v rt        d| d      d|d   |d   fv rt        d| d      t        j                  |      st        d| d      |rt        nt        }|j                  |      s t        |rd|r|nd ddz         d      d}|rB|d   dk(  r:|j                          t        |      dk(  st        |d         dk(  rt        d      t        |      dkD  rdj                  |      g}|r^t        |d   j                  d             }|d!kD  rt        d"|d    d
      t        j                  |d         rt        d#|d    d
      ||z   S )$a  
    Validate a fully qualified service name, instance or subtype. [rfc6763]

    Returns fully qualified service name.

    Domain names used by mDNS-SD take the following forms:

                   <sn> . <_tcp|_udp> . local.
      <Instance> . <sn> . <_tcp|_udp> . local.
      <sub>._sub . <sn> . <_tcp|_udp> . local.

    1) must end with 'local.'

      This is true because we are implementing mDNS and since the 'm' means
      multi-cast, the 'local.' domain is mandatory.

    2) local is preceded with either '_udp.' or '_tcp.' unless
       strict is False

    3) service name <sn> precedes <_tcp|_udp> unless
       strict is False

      The rules for Service Names [RFC6335] state that they may be no more
      than fifteen characters long (not counting the mandatory underscore),
      consisting of only letters, digits, and hyphens, must begin and end
      with a letter or digit, must not contain consecutive hyphens, and
      must contain at least one letter.

    The instance name <Instance> and sub type <sub> may be up to 63 bytes.

    The portion of the Service Instance Name is a user-
    friendly name consisting of arbitrary Net-Unicode text [RFC5198]. It
    MUST NOT contain ASCII control characters (byte values 0x00-0x1F and
    0x7F) [RFC20] but otherwise is allowed to contain any characters,
    without restriction, including spaces, uppercase, lowercase,
    punctuation -- including dots -- accented characters, non-Roman text,
    and anything else that may be represented using Net-Unicode.

    :param type_: Type, SubType or service name to validate
    :return: fully qualified service name (eg: _http._tcp.local.)
       zFull name (z) must be > 256 bytesN.TzType 'z' must end with 'z' or ''   FzNo Service name foundr   z' must not start with '.'_zService name (z) must start with '_'   z) must be <= 15 bytesz--z) must not contain '--'-z) may not start or end with '-'z.) must contain at least one letter (eg: 'A-Z') zA) must contain only these characters: A-Z, a-z, 0-9, hyphen ('-')z, underscore ('_')_subz_sub requires a subtype namezutf-8?   zToo long: 'z7Ascii control character 0x00-0x1F and 0x7F illegal in ')lenr   endswithr   r   splitr   popr   searchr	   r
   joinencoder   )	type_r   	remainingtrailerhas_protocolservice_nametest_service_nameallowed_characters_relengths	            G/home/ubuntu/myenv/lib/python3.12/site-packages/zeroconf/_utils/name.pyservice_type_namer,   '   ss   V 5zC${5'9N%OPP~~24RST=S!<==>DDSI	899;<	$UG +,F3Q2RRSU
 	
 
	'0S00177<	^,,q023$veW4EnEUUV%WXX }}()@AAy>Q3y|#4#9(6%8Q)RSS?c!(>,G\)]^^(,c+,r1(>:K9LLa)bcc$$(>:K9LLc)dee$Q'):2)>??(>:K9LLk)lmm!!"34( !2 33ab 
 ,2'7] 	 %++,=>(  !f!2" E F. .0DE 
   Yr]f,y>Q#il"3q"8()GHH
9~XXi()	Yq\((12B;(;y|nA)FGG#**9Q<8(I)TU,WXY  '!!    c                    | j                  d      }t        |      }t               }t        |      D ]D  }|||z
  dz
  d }|d   j	                  d      s |S |j                  dj                  |             F |S )z>Build a set of all possible types from a fully qualified name.r      Nr   r   )r   r   setrange
startswithaddr!   )namelabelslabel_counttypescountpartss         r+   possible_typesr:      s    ZZ_Ff+KEE{# #{U*Q.01Qx""3'L 			#((5/"	#
 Lr-   r   N)r#   strr   boolreturnr;   )r4   r;   r=   zset[str])__doc__
__future__r   	functoolsr   _exceptionsr   constr   r   r	   r
   r   r   r   r,   r:   cached_possible_types r-   r+   <module>rE      s\   , #  0   348 {" {"|
 /	#.~> r-   