
    <g                         d Z ddlZddlZddlmZ ddlmZ  G d dej                        Z ej                  dej                        Z
ded	efd
Zded	eeef   fdZy)z,
Parse scheme, host and port from a string.
    N)Tuple)checkc                   @    e Zd ZU eed<   ej                  eef   ed<   y)
ServerSpecschemeaddressN)__name__
__module____qualname__str__annotations__typingr   int     e/var/www/html/myenv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/net/server_spec.pyr   r      s    K\\#s(##r   r   a  
        ^
        (?:(?P<scheme>\w+)://)?  # scheme is optional
        (?P<host>[^:/]+|\[.+\])  # hostname can be DNS name, IPv4, or IPv6 address.
        (?::(?P<port>\d+))?  #  port is optional
        /?  #  we allow a trailing backslash, but no path
        $
        server_specreturnc                    t         j                  |       }|st        dj                  |             |j	                  d      xs d}|dvrt        dj                  |            |j	                  d      }|j                  d      r|j                  d      r|d	d
 }t        j                  |j                  d            st        dj                  |            |j	                  d      rt        |j	                  d            }n		 ddd|   }t        j                  |      st        dj                  |            t        |||f      S # t        $ r}t        d|       |d}~ww xY w)z
    Parses a server mode specification, e.g.:

        - http://example.com/
        - example.org
        - example.com:443

    Raises:
        ValueError, if the server specification is invalid.
    z Invalid server specification: {}r   https)httpr   socks4socks5socks5hzInvalid server scheme: {}host[]   idnazInvalid hostname: {}portP   i  )r   r   z&You need to specify a port when using NzInvalid port: {})server_spec_rematch
ValueErrorformatgroup
startswithendswithr   is_valid_hostencoder   KeyErroris_valid_portr   )r   mr   r   r!   es         r   parser0      sT    	[)A;BB;OPP WWX)'FEE4;;FCDD776?Dsc 2Abzt{{623/66t<==wwv1776?#	W-f5D t$+224899ftTl++  	WEfXNOUVV	Ws   E 	E*E%%E*modec                 H    | j                  dd      \  } }| t        |      fS )z
    Parse a mitmproxy mode specification, which is usually just (reverse|upstream):server-spec

    Returns:
        A (mode, server_spec) tuple.

    Raises:
        ValueError, if the specification is invalid.
    :r   )maxsplit)splitr0   )r1   r   s     r   parse_with_moder6   E   s+     

3
3D+{###r   )__doc__rer   r   %seleniumwire.thirdparty.mitmproxy.netr   
NamedTupler   compileVERBOSEr#   r   r0   r6   r   r   r   <module>r=      sz    
   7$"" $
  JJ
%,s %,z %,P$# $%Z"8 $r   