
    ?wg
                     R    d dl mZ ddZd ZddZ edddg      Zdd	Zdd
Zd Zy)    )
namedtupleNc                     i }| D ]3  }	 t        ||      }|	 ||      s||v r||xx   |gz  cc<   .|g||<   5 |S # t        $ r t        dj                  ||            w xY w)zConstruct a dictionary out of an iterable, using an attribute name as
    the key. Optionally provide a filter function, to determine what should be
    kept in the dictionary.z({} does not have the keyed attribute: {})getattrAttributeErrorRuntimeErrorformat)iterablekeyfilter_func	generatedelementks         J/var/www/horilla/myenv/lib/python3.12/site-packages/utils/dicts/helpers.pyfrom_keyed_iterabler      s    
 I )	%A +g"6I~!	) 'y	!)   	IPP   	s	   =%A"c                 2    i }| D ]  }||vs| |   ||<    |S )zgiven two dicts, a and b, this function returns c = a - b, where
    a - b is defined as the key difference between a and b.

    e.g.,
    {1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} =
        {3:"yellow", 4:True}

     )dict_adict_bdifference_dictr
   s       r   subtract_by_keyr      s6     O /f#)#;OC /     c                 d    |st        | |      S i }| D ]  }||vs||   | |   k7  s| |   ||<    |S )za stricter form of subtract_by_key(), this version will only remove an
    entry from dict_a if the key is in dict_b *and* the value at that key
    matches)r   )r   r   strictr   r
   s        r   subtractr   -   sU     vv..O /fsvc{ :#)#;OC / r   WinnowedResulthashas_notc                 |    i }i }| D ](  }d}|||v }n
| ||      }|r	| |   ||<   !| |   ||<   * t        ||      S )zoseparates a dict into has-keys and not-has-keys pairs, using either
    a list of keys or a filtering function.F)r   )dctkeysr   r   r   r
   key_passes_checks          r   winnow_by_keysr"   =   sp     CG 
$ "d{$*3/3xCHs8GCL
$ #w''r   c                 N    i }| D ]  }||v s|r| |   ||   k(  s| |   ||<    |S Nr   )r   r   r   intersection_dictr
   s        r   intersectionr&   R   sG     5&=VC[F3K7)/!#&5
 r   c                 >    |D ]  }| j                  |||           | S )zhGiven a target dct and a dict of {key:default value} pairs,
    calls setdefault for all of those pairs.)
setdefault)r   defaultsr
   s      r   setdefaultsr*   ]   s,      +sHSM*+ Jr   r$   )F)NN)T)	collectionsr   r   r   r   r   r"   r&   r*   r   r   r   <module>r,      s:    "0" ,ui.@A(*r   