
    Dh!                         S r SSKJr  SSKJrJr  SS jrS rS rS r	SS	 jr
 " S
 S\5      r " S S\5      r " S S\5      rSS jrS rg)a  
This module contains a collection of utility function for dealing with property
groupings.

Terminology:

For the purpose of grouping and ungrouping, tuples/lists and dictionaries are considered
"composite values" and all other values are considered "scalar values".

A "grouping value" is either composite or scalar.

A "schema" is a grouping value that can be used to encode an expected grouping
structure

   )InvalidCallbackReturnValue)AttributeDictstringify_idNc                    / n/ nUR                   nUR                  nUc  U nO[        X5        U" X45        U(       a  U" 5       u  pg[        U5      nU[        L d	  U[
        L a  [        Xg5       H  u  pU" X45        M     O2U[        L a  U H  nU" Xk   X{   45        M     OUR                  U5        U(       a  M  UR                  5         U$ )a  
Convert a grouping value to a list of scalar values

:param grouping: grouping value to flatten
:param schema: If provided, a grouping value representing the expected structure of
    the input grouping value. If not provided, the grouping value is its own schema.
    A schema is required in order to be able treat tuples and dicts in the input
    grouping as scalar values.

:return: list of the scalar values in the input grouping
)	appendpopvalidate_groupingtypetuplelistzipdictreverse)groupingschemastackresultpushr   groupschtypgeseks               aC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\dash/_grouping.pyflatten_groupingr      s     EF <<D
))C ~(+(	
U
3i%<3$;e/bX *D[eh'(  MM%  % NNM    c                 (   [        U [        [        45      (       a%  [        U  Vs/ s H  n[	        U5      PM     sn5      $ [        U [
        5      (       a3  [        U R                  5        Vs/ s H  n[	        U5      PM     sn5      $ gs  snf s  snf )a=  
Get the length of a grouping. The length equal to the number of scalar values
contained in the grouping, which is equivalent to the length of the list that would
result from calling flatten_grouping on the grouping value.

:param grouping: The grouping value to calculate the length of
:return: non-negative integer
r   )
isinstancer   r   sumgrouping_lenr   values)r   group_els     r   r!   r!   ?   sx     (UDM**8D8xL*8DEE(D!!8??;LM;LxL*;LMNN E Ns   B
-Bc           
      $  ^ U4S jm[        U[        5      (       d  [        S[        U5       35      e[	        [        U 5      5      n[	        U5      U:w  a)  [        SU S[	        U5       S[        U 5       SU 35      eT" U [        U5      5      $ )a  
Make a grouping like the provided grouping schema, with scalar values drawn from a
flat list by index.

Note: Scalar values in schema are not used

:param schema: Grouping value encoding the structure of the grouping to return
:param flat_values: List of values with length matching the grouping_len of schema.
    Elements of flat_values will become the scalar values in the resulting grouping
c           
      J  >^ [        U [        [        45      (       a  [        UU4S j[        U 5       5       5      $ [        U [        5      (       a;  [        U R                  5       5       VVVs0 s H  u  nu  p4UT" UT5      _M     snnn$ TR                  S5      $ s  snnnf )Nc              3   :   >#    U  H  u  pT" UT5      v   M     g 7fN ).0iel_perform_make_grouping_likenext_valuess      r   	<genexpr>Nmake_grouping_by_index.<locals>._perform_make_grouping_like.<locals>.<genexpr>_   s$      -EA ,B<<-s       )r   r   r   	enumerater   itemsr   )valuer-   r*   r   vr,   s    `   r   r,   ;make_grouping_by_index.<locals>._perform_make_grouping_like]   s    eeT]++ &u-  
 eT"" "+5;;=!9!9IAv .q+>>!9 
 q!!s   /Bz@The flat_values argument must be a list. Received value of type z(The specified grouping pattern requires z elements but received z
    Grouping pattern: z
    Values: )r   r   
ValueErrorr
   lenr   repr)r   flat_valuesexpected_lengthr,   s      @r   make_grouping_by_indexr;   Q   s    " k4((&&*;&7%8:
 	

 *623O
;?*66G H%%(%5$6 7%%)&\N 3&-)
 	
 'vtK/@AAr   c                 0   [        U[        [        45      (       a  U Vs/ s H  n[        X5      PM     sn$ [        U[        5      (       a8  [        UR                  5        VVs0 s H  u  p2U[        X5      _M     snn5      $ U " U5      $ s  snf s  snnf )ad  
Map a function over all of the scalar values of a grouping, maintaining the
grouping structure

:param fn: Single-argument function that accepts and returns scalar grouping values
:param grouping: The grouping to map the function over
:return: A new grouping with the same structure as input grouping with scalar
    values updated by the input function.
)r   r   r   map_groupingr   r   r2   )fnr   gr   s       r   r=   r=   ~   s     (UDM**-56XR#X66(D!!AQRAQab!44AQRSSh< 7 Ss   B%B
c                 (   ^^ [        UU4S jU 5      $ )a  
Create a grouping from a schema by using the schema's scalar values to look up
items in the provided source object.

:param schema: A grouping of potential keys in source
:param source: Dict-like object to use to look up scalar grouping value using
    scalar grouping values as keys
:param default: Default scalar value to use if grouping scalar key is not present
    in source
:return: grouping
c                 (   > TR                  U T5      $ r'   )get)sdefaultsources    r   <lambda>&make_grouping_by_key.<locals>.<lambda>   s    &**Q"8r   )r=   )r   rE   rD   s    ``r   make_grouping_by_keyrH      s     8&AAr   c                   8   ^  \ rS rSrU 4S jr\S 5       rSrU =r$ )SchemaTypeValidationError   c                 v   > [         TU ]  SU S[        U5       SU S[        U5       S[        U5       S3S9  g )N
                Schema: 
                Path: z 
                Expected type: z(
                Received value of type :
                    
                msg)super__init__r8   r
   )selfr3   full_schemapathexpected_type	__class__s        r   rT   "SchemaTypeValidationError.__init__   s]    $ &Dzl #  - /((,U} 5%[M " 	 	
r   c                 <    [        X5      (       d  [        XX45      eg r'   )r   rJ   )clsr3   rV   rW   rX   s        r   checkSchemaTypeValidationError.check   s    %//+ETT 0r   r(   	__name__
__module____qualname____firstlineno__rT   classmethodr]   __static_attributes____classcell__rY   s   @r   rJ   rJ          	
 U Ur   rJ   c                   8   ^  \ rS rSrU 4S jr\S 5       rSrU =r$ )SchemaLengthValidationError   c                 v   > [         TU ]  SU S[        U5       SU S[        U5       S[        U5       S3S9  g )NrM   rN   z"
                Expected length: z*
                Received value of length rO   rP   rQ   )rS   rT   r8   r7   )rU   r3   rV   rW   expected_lenrY   s        r   rT   $SchemaLengthValidationError.__init__   s]    $ &Dzl #"". 0**-e* 6%[M " 	 	
r   c                 :    [        U5      U:w  a  [        XX45      eg r'   )r7   rj   )r\   r3   rV   rW   rm   s        r   r]   !SchemaLengthValidationError.check   s     u:%-e$UU &r   r(   r_   rg   s   @r   rj   rj      s    	
 V Vr   rj   c                   8   ^  \ rS rSrU 4S jr\S 5       rSrU =r$ )SchemaKeysValidationError   c                    > [         TU ]  SU S[        U5       SU S[        UR	                  5       5       S[        U5       S3S9  g )NrM   rN   z 
                Expected keys: z*
                Received value with keys rO   rP   rQ   )rS   rT   r8   setkeys)rU   r3   rV   rW   expected_keysrY   s        r   rT   "SchemaKeysValidationError.__init__   se    $ &Dzl #  - /**-ejjl*;)< =%[M " 	 	
r   c                 h    [        UR                  5       5      [        U5      :w  a  [        XX45      eg r'   )ru   rv   rr   )r\   r3   rV   rW   rw   s        r   r]   SchemaKeysValidationError.check   s,    uzz|M 22+ETT 3r   r(   r_   rg   s   @r   rr   rr      rh   r   rr   c                    Uc  Un[        U[        [        45      (       ap  [        R	                  XU[        [        45        [
        R	                  XU[        U5      5        [        [        X5      5       H  u  nu  pV[        XVX#U4-   S9  M     g[        U[        5      (       aX  [        R	                  XU[        5        [        R	                  XU[        U5      5        U H  n[        X   X   X#U4-   S9  M     gg)zl
Validate that the provided grouping conforms to the provided schema.
If not, raise a SchemaValidationError
N)rV   rW   )r   r   r   rJ   r]   rj   r7   r1   r   r	   r   rr   ru   )r   r   rV   rW   r*   r?   rC   r   s           r   r	   r	      s    
 &5$-((!''teT]S#))(s6{S"3x#89IAva!+N :	FD	!	!!''tTJ!''tS[QAVYKaTk 
 	r   c                    [        U [        5      (       ak  [        U S   5      nU SU S    3nU R                  S5      UX1;   [        U S   [        5      (       a  [	        U S   5      OU S   S.nU R                  U5        g g )Nid.propertyr3   )r3   str_id	triggeredr}   )r   r   r   rB   r   update)r?   r   r   prop_id
new_valuess        r   update_args_groupr      s    !Tag&HAa
m_- UU7^ -,6qw,E,E-$(1T7	

 	
 r   r'   )Nr(   )__doc__
exceptionsr   _utilsr   r   r   r!   r;   r=   rH   rJ   rj   rr   r	   r   r(   r   r   <module>r      sf    3 /(V$*BZ&BU : U$V"< V$U : U$2r   