
    9h@                    L   S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	J
r
Jr  SSKJrJr  SSKJrJrJrJrJrJr  / SQr\
" S	5      rS
S.         S-S jjrS.S jr\R2                  " S5      rS/S jr\R2                  " S5      rS0S jr\R2                  " S5      r\R2                  " S5      rS0S jr \R2                  " S5      r!\R2                  " S5      r"S1S jr#          S2S jr$        S3S jr%S4S jr&\R2                  " S5      r'        S5S jr(S6S jr)        S7S jr*        S8S jr+S9S  jr,\,r-      S:S! jr.S;S" jr/\/r0        S<S# jr1S=S$ jr2\2r3S>S% jr4\4r5S?S& jr6S@S' jr7\R2                  " S(5      r8S0S) jr9SAS* jr:SBS+ jr;SCS, jr<g)D    )annotationsN)Sequence)CallableTypeVarcast   )InvalidHeaderFormatInvalidHeaderValue)ConnectionOptionExtensionHeaderExtensionNameExtensionParameterSubprotocolUpgradeProtocol)
build_hostparse_connectionparse_upgradeparse_extensionbuild_extensionparse_subprotocolbuild_subprotocolvalidate_subprotocolsbuild_www_authenticate_basicparse_authorization_basicbuild_authorization_basicTF)always_include_portc                    [         R                  " U 5      nUR                  S:X  a  SU  S3n U(       d  X(       a  SOS:w  a  U  SU 3n U $ ! [         a     N*f = f)z
Build a ``Host`` header.

   []i  P   :)	ipaddress
ip_addressversion
ValueError)hostportsecurer   addresss        WC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\websockets/headers.pyr   r   '   si    &&t, ??atfA;Ddfs"=qK  s   A 
AAc                ,    U[        U 5      :X  a  S$ X   $ )z
Return the next character from ``header`` at the given position.

Return :obj:`None` at the end of ``header``.

We never need to peek more than one character ahead.

N)len)headerposs     r,   
peek_aheadr1   I   s     #f+%466;6    z[\t ]*c                V    [         R                  X5      nUc   eUR                  5       $ )z
Parse optional whitespace from ``header`` at the given position.

Return the new position.

The whitespace itself isn't returned because it isn't significant.

)_OWS_rematchend)r/   r0   r5   s      r,   	parse_OWSr7   X   s*     MM&&E99;r2   z[-!#$%&\'*+.^_`|~0-9a-zA-Z]+c                    [         R                  X5      nUc  [        USX5      eUR                  5       UR	                  5       4$ )z
Parse a token from ``header`` at the given position.

Return the token value and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

zexpected token)	_token_rer5   r	   groupr6   r/   r0   header_namer5   s       r,   parse_tokenr=   j   s>     OOF(E}!+/?MM;;=%))+%%r2   zC"(?:[\x09\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x09\x20-\x7e\x80-\xff])*"z\\([\x09\x20-\x7e\x80-\xff])c                    [         R                  X5      nUc  [        USX5      e[        R	                  SUR                  5       SS 5      UR                  5       4$ )z
Parse a quoted string from ``header`` at the given position.

Return the unquoted value and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

zexpected quoted stringz\1r   )_quoted_string_rer5   r	   _unquote_resubr:   r6   r;   s       r,   parse_quoted_stringrC      sR     ##F0E}!+/GUU??5%++-""56		CCr2   z[\x09\x20-\x7e\x80-\xff]*z([\x22\x5c])c                    [         R                  U 5      nUc  [        S5      eS[        R	                  SU 5      -   S-   $ )z\
Format ``value`` as a quoted string.

This is the reverse of :func:`parse_quoted_string`.

z-invalid characters for quoted-string encoding"z\\\1)_quotable_re	fullmatchr'   	_quote_rerB   )valuer5   s     r,   build_quoted_stringrJ      s@     ""5)E}HIIw..44r2   c                   [        X5      S:X  a  [        XS-   5      n[        X5      S:X  a  M  / n U " XU5      u  pRUR                  U5        [        X5      nU[        U5      :X  a  Ok[        X5      S:X  a  [        XS-   5      nO[	        USX5      e[        X5      S:X  a  [        XS-   5      n[        X5      S:X  a  M  U[        U5      :X  a  OM  U[        U5      :X  d   eU$ )a  
Parse a comma-separated list from ``header`` at the given position.

This is appropriate for parsing values with the following grammar:

    1#item

``parse_item`` parses one item.

``header`` is assumed not to start or end with whitespace.

(This function is designed for parsing an entire header value and
:func:`~websockets.http.read_headers` strips whitespace from values.)

Return a list of items.

Raises:
    InvalidHeaderFormat: On invalid inputs.

,r   zexpected comma)r1   r7   appendr.   r	   )
parse_itemr/   r0   r<   itemsitems         r,   
parse_listrQ      s    > V
!S
(a( V
!S
( E
vK8	T$ #f+ f"c)F!G,C%k3CVQQ %,F!G,C %, #f+- 4 #f+Lr2   c                B    [        XU5      u  p1[        [        U5      U4$ )z
Parse a Connection option from ``header`` at the given position.

Return the protocol value and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

)r=   r   r   r/   r0   r<   rP   s       r,   parse_connection_optionrT      s%     F5ID $',,r2   c                &    [        [        U SS5      $ )z
Parse a ``Connection`` header.

Return a list of HTTP connection options.

Args
    header: value of the ``Connection`` header.

Raises:
    InvalidHeaderFormat: On invalid inputs.

r   
Connection)rQ   rT   r/   s    r,   r   r      s     -vq,GGr2   z>[-!#$%&\'*+.^_`|~0-9a-zA-Z]+(?:/[-!#$%&\'*+.^_`|~0-9a-zA-Z]+)?c                    [         R                  X5      nUc  [        USX5      e[        [        UR                  5       5      UR                  5       4$ )z
Parse an Upgrade protocol from ``header`` at the given position.

Return the protocol value and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

zexpected protocol)_protocol_rer5   r	   r   r   r:   r6   r;   s       r,   parse_upgrade_protocolrZ     sG     v+E}!+/BFPP/<<r2   c                &    [        [        U SS5      $ )z
Parse an ``Upgrade`` header.

Return a list of HTTP protocols.

Args:
    header: Value of the ``Upgrade`` header.

Raises:
    InvalidHeaderFormat: On invalid inputs.

r   Upgrade)rQ   rZ   rW   s    r,   r   r     s     ,faCCr2   c                4   [        XU5      u  p1[        X5      nSn[        X5      S:X  aj  [        XS-   5      n[        X5      S:X  a4  Un[        XU5      u  pA[        R                  U5      c  [        USX5      eO[        XU5      u  pA[        X5      nX44U4$ )z
Parse a single extension parameter from ``header`` at the given position.

Return a ``(name, value)`` pair and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

N=r   rE   zinvalid quoted header content)r=   r7   r1   rC   r9   rG   r	   )r/   r0   r<   namerI   
pos_befores         r,   parse_extension_item_paramra   .  s     F5ID
F
 CE&#%a(f"c)J,V+FJE ""5)1)!@&  2
 %V+>JE$=#r2   c                    [        XU5      u  p1[        X5      n/ n[        X5      S:X  a>  [        XS-   5      n[        XU5      u  pQUR	                  U5        [        X5      S:X  a  M>  [        [        U5      U4U4$ )z
Parse an extension definition from ``header`` at the given position.

Return an ``(extension name, parameters)`` pair, where ``parameters`` is a
list of ``(name, value)`` pairs, and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

;r   )r=   r7   r1   ra   rM   r   r   )r/   r0   r<   r_   
parameters	parameters         r,   parse_extension_itemrf   R  s     F5ID
F
 CJ
V
!S
(a(3FM	)$ V
!S
( %z2C77r2   c                &    [        [        U SS5      $ )a  
Parse a ``Sec-WebSocket-Extensions`` header.

Return a list of WebSocket extensions and their parameters in this format::

    [
        (
            'extension name',
            [
                ('parameter name', 'parameter value'),
                ....
            ]
        ),
        ...
    ]

Parameter values are :obj:`None` when no value is provided.

Raises:
    InvalidHeaderFormat: On invalid inputs.

r   zSec-WebSocket-Extensions)rQ   rf   rW   s    r,   r   r   k  s    . *FA7QRRr2   c           
         SR                  [        [        U 5      /U V Vs/ s H  u  pUc  U OU  SU 3PM     snn -   5      $ s  snn f )zW
Build an extension definition.

This is the reverse of :func:`parse_extension_item`.

z; r^   )joinr   str)r_   rd   rI   s      r,   build_extension_itemrk     s`     99	c4  *
  * MD$q'88)
	
 
s   Ac                2    SR                  S U  5       5      $ )z`
Build a ``Sec-WebSocket-Extensions`` header.

This is the reverse of :func:`parse_extension`.

, c              3  <   #    U  H  u  p[        X5      v   M     g 7f)N)rk   ).0r_   rd   s      r,   	<genexpr>"build_extension.<locals>.<genexpr>  s      GQ3C4T..zs   ri   )
extensionss    r,   r   r     s"     99 GQ  r2   c                B    [        XU5      u  p1[        [        U5      U4$ )z
Parse a subprotocol from ``header`` at the given position.

Return the subprotocol value and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

)r=   r   r   rS   s       r,   parse_subprotocol_itemru     s$     F5IDT"C''r2   c                &    [        [        U SS5      $ )z
Parse a ``Sec-WebSocket-Protocol`` header.

Return a list of WebSocket subprotocols.

Raises:
    InvalidHeaderFormat: On invalid inputs.

r   zSec-WebSocket-Protocol)rQ   ru   rW   s    r,   r   r     s     ,fa9QRRr2   c                $    SR                  U 5      $ )z`
Build a ``Sec-WebSocket-Protocol`` header.

This is the reverse of :func:`parse_subprotocol`.

rm   rr   )subprotocolss    r,   r   r     s     99\""r2   c                    [        U [        5      (       d  [        S5      e[        U [        5      (       a  [        S5      eU  H+  n[        R                  U5      (       a  M  [        SU 35      e   g)zL
Validate that ``subprotocols`` is suitable for :func:`build_subprotocol`.

zsubprotocols must be a listz&subprotocols must be a list, not a strzinvalid subprotocol: N)
isinstancer   	TypeErrorrj   r9   rG   r'   )rx   subprotocols     r,   r   r     sd    
 lH--566,$$@AA#"";//4[MBCC $r2   c                >    [        U 5      n [        S5      nSU  SU 3$ )zq
Build a ``WWW-Authenticate`` header for HTTP Basic Auth.

Args:
    realm: Identifier of the protection space.

zUTF-8zBasic realm=z
, charset=)rJ   )realmcharsets     r,   r   r     s+      &E!'*G%
7)44r2   z[A-Za-z0-9-._~+/]+=*c                    [         R                  X5      nUc  [        USX5      eUR                  5       UR	                  5       4$ )z
Parse a token68 from ``header`` at the given position.

Return the token value and the new position.

Raises:
    InvalidHeaderFormat: On invalid inputs.

zexpected token68)_token68_rer5   r	   r:   r6   r;   s       r,   parse_token68r     s@     f*E}!+/A6OO;;=%))+%%r2   c                <    U[        U 5      :  a  [        USX5      eg)z0
Check that parsing reached the end of header.

ztrailing dataN)r.   r	   )r/   r0   r<   s      r,   	parse_endr     s$    
 S[!+LL r2   c                   [        U SS5      u  pUR                  5       S:w  a  [        SSU 35      e[        X5      S:w  a  [	        SSX5      eUS-  n[        XS5      u  p2[        XS5         [        R                  " UR                  5       5      R                  5       n UR                  S
S5      u  pVXV4$ ! [        R                   a    [        SS5      S	ef = f! [         a    [        SS5      S	ef = f)a  
Parse an ``Authorization`` header for HTTP Basic Auth.

Return a ``(username, password)`` tuple.

Args:
    header: Value of the ``Authorization`` header.

Raises:
    InvalidHeaderFormat: On invalid inputs.
    InvalidHeaderValue: On unsupported inputs.

r   Authorizationbasiczunsupported scheme:  zexpected space after schemer   z#expected base64-encoded credentialsNr#   z&expected username:password credentials)r=   lowerr
   r1   r	   r   r   base64	b64decodeencodedecodebinasciiErrorsplitr'   )r/   schemer0   basic_credentials	user_passusernamepasswords          r,   r   r     s%     fa9KF||~  "6(+
 	
 &#%!:F
 	
 1HC*6Hf?+$$%6%=%=%?@GGI	&__S!4  >>  1
 	   4
 	s   /2B9 "C 9"CC6c                    SU ;  d   eU  SU 3n[         R                  " UR                  5       5      R                  5       nSU-   $ )zt
Build an ``Authorization`` header for HTTP Basic Auth.

This is the reverse of :func:`parse_authorization_basic`.

r#   zBasic )r   	b64encoder   r   )r   r   r   r   s       r,   r   r   ?  sQ     h*AhZ(I(()9)9);<CCE'''r2   )
r(   rj   r)   intr*   boolr   r   returnrj   )r/   rj   r0   r   r   z
str | None)r/   rj   r0   r   r   r   )r/   rj   r0   r   r<   rj   r   ztuple[str, int])rI   rj   r   rj   )
rN   z(Callable[[str, int, str], tuple[T, int]]r/   rj   r0   r   r<   rj   r   zlist[T])r/   rj   r0   r   r<   rj   r   ztuple[ConnectionOption, int])r/   rj   r   zlist[ConnectionOption])r/   rj   r0   r   r<   rj   r   ztuple[UpgradeProtocol, int])r/   rj   r   zlist[UpgradeProtocol])r/   rj   r0   r   r<   rj   r   ztuple[ExtensionParameter, int])r/   rj   r0   r   r<   rj   r   ztuple[ExtensionHeader, int])r/   rj   r   zlist[ExtensionHeader])r_   r   rd   zSequence[ExtensionParameter]r   rj   )rs   zSequence[ExtensionHeader]r   rj   )r/   rj   r0   r   r<   rj   r   ztuple[Subprotocol, int])r/   rj   r   zlist[Subprotocol])rx   Sequence[Subprotocol]r   rj   )rx   r   r   None)r~   rj   r   rj   )r/   rj   r0   r   r<   rj   r   r   )r/   rj   r   ztuple[str, str])r   rj   r   rj   r   rj   )=
__future__r   r   r   r$   recollections.abcr   typingr   r   r   
exceptionsr	   r
   r   r   r   r   r   r   __all__r   r   r1   compiler4   r7   r9   r=   r@   rA   rC   rF   rH   rJ   rQ   rT   r   rY   rZ   r   ra   rf   r   parse_extension_listrk   r   build_extension_listru   r   parse_subprotocol_listr   build_subprotocol_listr   r   r   r   r   r   r    r2   r,   <module>r      s   "    	 $ * * ?  CL !&

 
  	D	7 **Y
 JJ67	&  JJJ 
 jj89D  zz67 JJ'	
5?8?? 
? 	?
 ?D---(+-!- H  zzE
===(+= =$D !!!(+!#!H888(+8 82S4 ' 
%A&	 ' ((((+(( 
S + # + D5 jj01& M-`(r2   