
    tj                     F    d dl Z d dlZd dlZ G d de j                        Zy)    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.
    c                 F    | j                  |      }t        | 	  ||      S )N)_extract_trame_argssuperparse_known_args)selfargs	namespace	__class__s      O/DATA/.local/lib/python3.12/site-packages/trame_server/utils/argument_parser.pyr   zArgumentParser.parse_known_args   s'     ''-w'i88    c                    ||S | j                   rg nt        j                  dd }t        d t        j                  dd D              r}t	        j
                         }|j                  d       |j                  t        j                  dd D cg c]
  }|dk7  s	| c}      \  }}||j                  j                         z  }|S dt        j                  v r$|t        j                  d   j                         z  }|S c c}w )z,Extract the arguments we will parse in trameN   c              3   >   K   | ]  }|j                  d         yw--trame-argsN
startswith.0xs     r   	<genexpr>z5ArgumentParser._extract_trame_args.<locals>.<genexpr>.   s     B\q||N+\   r   z--
TRAME_ARGS)_skip_default_parsingsysargvanyargparser   add_argumentr   
trame_argssplitosenviron)r	   r
   
tmp_parservout_s         r   r   z"ArgumentParser._extract_trame_args%   s     K//rSXXab\BSXXab\BB!002J##N300SXXab\1W\QRVY!\1WXFCCNN((**D
 	 RZZ'BJJ|,2244D 2Xs   
C>C>c                     dt         j                  v xs7 t        d t        j                  dd  D              xs dt        j
                  v S )Nr   c              3   >   K   | ]  }|j                  d         ywr   r   r   s     r   r   z7ArgumentParser._skip_default_parsing.<locals>.<genexpr>C   s     FA1<</r   r   pytest)r$   r%   r   r   r   modules)r	   s    r   r   z$ArgumentParser._skip_default_parsing;   sC     BJJ& 'F!"FF'3;;&	
r   )NN)	__name__
__module____qualname____doc__r   r   propertyr   __classcell__)r   s   @r   r   r      s&    .9, 	
 	
r   r   )r    r$   r   r    r   r   <module>r5      s      	 
?
X,, ?
r   