
    8jk                        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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)	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)stricttype_strr   boolreturnc          	        t          |           dk    rt          d|  d          |                                 }|                    t          t
          f          rP| dt          t                                                  d          }| t          t                     d         }d}n|r#t          d|  dt           d	t
           d
          |                    t                    rS| dt          t                                                  d          }| t          t                     dz   d         }d}nt          d|  dt           d
          |s|r\|                                }|st          d          t          |          dk    r,t          |d                   dk    rt          d|  d          |d         dk    rt          d| d          |dd         }|r&t          |          dk    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          }|
                    |          st          |rd|r|nd ddz   nd          nd}|r[|d         dk    rO|                                 t          |          dk    st          |d                   dk    rt          d          t          |          dk    rd                    |          g}|rzt          |d                             d                     }	|	d!k    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   lowerendswithr   r   splitr   popr   searchr	   r
   joinencoder   )
r   r   
type_lower	remainingtrailerhas_protocolservice_nametest_service_nameallowed_characters_relengths
             J/home/user/adhan/venv/lib/python3.11/site-packages/zeroconf/_utils/name.pyservice_type_namer1   '   s   V 5zzC$%O5%O%O%OPPP J79WXYY Y=S!<====>DDSII	8999;;<	 
Y$UU U U+U U3QU U U
 
 	
 
		^	,	, Y0S0000177<<	^,,,q0223$%We%W%Wn%W%W%WXXX ) ) }} 	B()@AAAy>>Q3y|#4#4#9#9()R%)R)R)RSSS?c!!()],)])])]^^^(, 	dc+,,r11()b:K)b)b)bccc$$$()d:K)d)d)deee$Q'):2)>???()l:K)l)l)lmmm!"344 	(b!2bbb  
 ,2]''7] 	 %++,=>> 	(  .f!D!2!2" . . .0DE E   	  IYr]f,,y>>Q#il"3"3q"8"8()GHHH
9~~XXi(()	 Yq\((1122B;;()Fy|)F)F)FGGG#*9Q<88 	(Y)TU,YYY   '!!    nameset[str]c                8   |                      d          }t          |          }t                      }t          |          D ]W}|||z
  dz
  d         }|d                             d          s n)|                    d                    |                     X|S )z>Build a set of all possible types from a fully qualified name.r      Nr   r   )r#   r    setrange
startswithaddr&   )r3   labelslabel_counttypescountpartss         r0   possible_typesr@      s    ZZ__Ff++KEEE{## # #{U*Q.001Qx""3'' 	E		#((5//""""Lr2   r   N)r   r   r   r   r   r   )r3   r   r   r4   )__doc__
__future__r   	functoolsr   _exceptionsr   constr   r   r	   r
   r   r   r   r1   r@   cached_possible_types r2   r0   <module>rH      s   , # " " " " "       0 0 0 0 0 0                  348 }" }" }" }" }" }"@
 
 
 
 /		#...~>>   r2   