
    +j                     D    d dl Z d dlZd dlZ G d de j                  ZdS )    Nc                   @     e Zd ZdZd fd	Zd Zed             Z xZS )ArgumentParseral  Custom argument parser for Trame

    In this class, `parse_known_args()` has a custom implementation.

    Normally, this would parse sys.argv[1:] as normal, but it will be different
    under the following conditions:

    1. A `--trame-args` argument is provided. If this is provided, then
       only the arguments supplied to this argument will be used for trame.
       For instance: `--trame-args="-p 8081 --server"` will mean the args
       parsed for trame will be `-p 8081 --server`.
    2. A `TRAME_ARGS` environment variable is set. If this is set, then
       only the arguments supplied to this environment variable will be used
       for trame.
       For instance: `TRAME_ARGS="-p 8081 --server"` will mean the args
       parsed for trame will be `-p 8081 --server`.
    3. The `pytest` module has been loaded. If this is the case, then we
       will automatically ignore `sys.argv` because `pytest` will not
       allow for arguments it does not recognize. If `pytest` has been
       loaded, the only way to specify trame arguments is through the
       `TRAME_ARGS` environment variable mentioned in #2.
    Nc                 r    |                      |          }t                                          ||          S )N)_extract_trame_argssuperparse_known_args)selfargs	namespace	__class__s      \/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trame_server/utils/argument_parser.pyr   zArgumentParser.parse_known_args   s2     ''--ww''i888    c                    ||S | j         rg nt          j        dd         }t          d t          j        dd         D                       ryt	          j                    }|                    d           |                    d t          j        dd         D                       \  }}||j        	                                z  }n5dt          j        v r'|t          j        d         	                                z  }|S )z,Extract the arguments we will parse in trameN   c              3   @   K   | ]}|                     d           V  dS --trame-argsN
startswith.0xs     r   	<genexpr>z5ArgumentParser._extract_trame_args.<locals>.<genexpr>.   s.      BBq||N++BBBBBBr   r   c                     g | ]
}|d k    |S )z-- )r   vs     r   
<listcomp>z6ArgumentParser._extract_trame_args.<locals>.<listcomp>2   s    1W1W1WQRVYY!YYYr   
TRAME_ARGS)_skip_default_parsingsysargvanyargparser   add_argumentr   
trame_argssplitosenviron)r	   r
   
tmp_parserout_s        r   r   z"ArgumentParser._extract_trame_args%   s     K/ArrSXabb\BBSXabb\BBBBB 		5!022J##N333001W1WSXabb\1W1W1WXXFCCN((***DDRZ''BJ|,22444Dr   c                     dt           j        v p8t          d t          j        dd          D                       pdt          j        v S )Nr   c              3   @   K   | ]}|                     d           V  dS r   r   r   s     r   r   z7ArgumentParser._skip_default_parsing.<locals>.<genexpr>C   s.      FFA1<<//FFFFFFr   r   pytest)r'   r(   r"   r    r!   modules)r	   s    r   r   z$ArgumentParser._skip_default_parsing;   sK     BJ& 'FF!""FFFFF'3;&	
r   )NN)	__name__
__module____qualname____doc__r   r   propertyr   __classcell__)r   s   @r   r   r      sq         .9 9 9 9 9 9  , 	
 	
 X	
 	
 	
 	
 	
r   r   )r#   r'   r    r   r   r   r   <module>r6      sW     				 



?
 ?
 ?
 ?
 ?
X, ?
 ?
 ?
 ?
 ?
r   