
    f3i[                         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 d dlmZ d dlmZ erd dlmZ  e	d      Z G d	 d
      Zy)    )Sequence)contextmanager)chain)TYPE_CHECKINGAnyTypeVarcastoverload)inverse_groups_from_app)	Parameter)AppVc            
       d   e Zd Zd Zedded   ee   z  deeef   dz  fd       Z	e
defd       Ze
defd	       Ze
ded   fd
       Zededefd       Zedededefd       Zedededz  dedefd       Zeddededz  dedefd       Zddededz  dedz  dedz  fdZe
defd       Zy)AppStackc                 &    |gg| _         i g| _        y N)stackoverrides_stack)selfapps     \/mnt/e/genesis-system/.venvs/voice-bridge/lib/python3.12/site-packages/cyclopts/app_stack.py__init__zAppStack.__init__   s    (+ug
68T    Nappsr   	overridesc              #     K   | j                   |xs i z  }| j                  j                  |xs i        |s 	 d  | j                  j                          y t	        |d   t
              rJt        t        t
           |      }| j                  d   d   j                  |d      \  }}}t        |      }nt        t        d   t        |            }~|s 	 d  | j                  j                          y g }|D ch c]  }t        |       }	}|D ]L  }|j                  3|r1|d   j                  "|j                          |r|d   j                  "|j                  |       |j                  j                  j                  |j                                |j                  j                  j                  |xs i        |}
|
j                  x}
t        |
      |	v r|j                         }|j                  |
       |
j                  j                  j                  |       |
j                  j                  j                  |xs i        |
j                  x}
O 	 d  |D ]  }|j                  j                  j                          |j                  j                  j                          |}
|
j                  x}
\t        |
      |	v r|
j                  j                  j                          |
j                  j                  j                          |
j                  x}
e | j                  j                          y # | j                  j                          w xY w# | j                  j                          w xY wc c}w # |D ]  }|j                  j                  j                          |j                  j                  j                          |}
|
j                  x}
\t        |
      |	v r|
j                  j                  j                          |
j                  j                  j                          |
j                  x}
e | j                  j                          w xY ww)Nr   T)include_parent_metar   )r   r   appendpop
isinstancestrr	   r   r   parse_commandslistid_meta_parent	app_stackcopy_meta)r   r   r   str_apps_
apps_tupleresolved_appsso_farr   app_idsmeta_appmeta_subappss               r   __call__zAppStack.__call__   s     NNio26	##IO4+$$((* d1gs#HSM40H#zz!}Q/>>x]a>bAz1'+J'7M ed4j9M+$$((*&34s2c744  	KC'!8!8!DJJL !8!8!D MM#MM&&v{{}5MM))00bA H'~~-8:h<7*%{{}##H-""((//=""2299)/rJ  (~~-8:	K,	'$ 	=##'')--113#+>>1x>(|w. &&,,002&&66::<	 $,>>1x>	=   $$&s $$((*  $$((* 54 % 	=##'')--113#+>>1x>(|w. &&,,002&&66::<	 $,>>1x>	=   $$&s   5Q+M BQ+M# !Q+9NAQ+A=Q+BQ+Q+ N $AQ+A$Q+'Q+M  Q+#M??Q+AQ(&A$Q(Q((Q+returnc                     i }t        | j                        D ]/  }|j                         D ]  \  }}|	|j                  ||        1 |S r   )reversedr   items
setdefault)r   outoverrides_framekeyvalues        r   r   zAppStack.overrides]   sX    '(<(<= 	/O-335 /
U$NN3./	/ 
r   c                 F   g }t        j                  | j                        D ]g  }|j                  r|j	                  |j
                  j                  D cg c]  }|j                   c}       |j                  |j                         i t        j                  | S c c}w )zhdefault_parameter has special resolution since it needs to include the command groups in the derivation.)r   from_iterabler   r&   extendr'   command_groupsdefault_parameterr   r   combine)r   cparams	child_appgroups       r   r@   zAppStack.default_parameterf   s     ,,TZZ8 	8I%%NNATATAcAcdE33deNN9667		8   '** es   B
c                 D    | j                   st        | j                   d   S )Nr   )r   
ValueError)r   s    r   current_framezAppStack.current_framer   s    zzzz"~r   	attributec                      y r    )r   rH   s     r   resolvezAppStack.resolvey   s    .1r   overridec                      y r   rJ   )r   rH   rL   s      r   rK   zAppStack.resolve|   s    9<r   fallbackc                      y r   rJ   r   rH   rL   rN   s       r   rK   zAppStack.resolve   s    MPr   c                     y r   rJ   rP   s       r   rK   zAppStack.resolve   s    WZr   c                 V   ||S t        | j                        D ]  }||v s||   }||c S  t        t        t        j                  | j
                                    D ]F  }t        ||      }||c S |}|j                  x}&t        ||      }||c S |j                  x}!H |S )z,Resolve an attribute from the App hierarchy.)r5   r   r$   r   r=   r   getattrr&   )	r   rH   rL   rN   r9   r;   r   resultr0   s	            r   rK   zAppStack.resolve   s    O  ((<(<= 	!OO+'	2$ L		! D!4!4TZZ!@AB 
	"CS),F! H'4448A 95%!M  (4448A
	" r   c                     | j                   d   	 | j                   d   }|!	 t        fdt        |      D              d   S g S # t        $ r d }Y 2w xY w# t        $ r |j
                  }Y nw xY w|R2)Nr   c              3   2   K   | ]  }|d    u s|  yw)r   NrJ   ).0xcommand_apps     r   	<genexpr>z*AppStack.command_groups.<locals>.<genexpr>   s     c!qQRtWbObAcs      )rG   
IndexErrornextr   StopIterationr&   )r   current_apprZ   s     @r   r?   zAppStack.command_groups   s    ((,	&*&8&8&<K %7c'>{'Kccdeff 	  	K	 ! 7)667 %s"   A A AAA/.A/r   )NN)__name__
__module____qualname__r   r   r   r"   dictr   r2   propertyr   r   r@   r$   rG   r
   rK   r   r?   rJ   r   r   r   r      sn   : C'Xe_x}< C'cSVhZ^I^ C' C'J 4   	+9 	+ 	+ tE{   111 1<<<a< <PPDPAP!P PZZDZaZTUZ Z D 1t8 _`cg_g 6   r   r   N)collections.abcr   
contextlibr   	itertoolsr   typingr   r   r   r	   r
   cyclopts.group_extractorsr   cyclopts.parameterr   cyclopts.corer   r   r   rJ   r   r   <module>rm      s7    $ %  > > = (! CL] ]r   