
    ed                         d Z ddlZddlZddlmZ ej
                  dk  rddlmZ nddlmZ dZ	dZ
g dZd	 Zd
 Zd ZddZd Zy)z$ Tools for working with collections     N)warn)   r   )IterablezVince Reuterzvreuter@virginia.edu)is_collection_likepowersetasciify_dictmerge_dictsc                 H    | j                         }|j                  |       |S )z
    Merge dictionaries

    :param Mapping x: dict to merge
    :param Mapping y: dict to merge
    :return Mapping: merged dict
    )copyupdate)xyzs      3lib/python3.12/site-packages/ubiquerg/collection.pyr	   r	      s     	
AHHQKH    c                 H    t        | t              xr t        | t               S )z

    Determine whether an object is collection-like.

    :param object c: Object to test as collection
    :return bool: Whether the argument is a (non-string) collection
    )
isinstancer   str)cs    r   r   r       s      a"=:a+='==r   c                 n    t               }| D cg c]  }||vs|j                  |      r| c}S c c}w )z
    Return only unique items in a sequence, preserving order

    :param list seq: List of items to uniqify
    :return list[object]: Original list with duplicates removed
    )setadd)seqseenr   s      r   uniqifyr   +   s/     5D@!atmDHHQKA@@@s   	222c           	          ||rdnd}nUt        |t              s$t        dj                  |t	        |                  |r|dk  rt        dj                  |            t                t               }|dk(  s||k  rg S |rt               dz   n
t               }t        t        j                  j                   fdt        ||      D                    S )a  
    Build the powerset of a collection of items.

    :param Iterable[object] items: "Pool" of all items, the population for
        which to build the power set.
    :param int min_items: Minimum number of individuals from the population
        to allow in any given subset.
    :param bool include_full_pop: Whether to include the full population in
        the powerset (default True to accord with genuine definition)
    :param bool nonempty: force each subset returned to be nonempty
    :return list[object]: Sequence of subsets of the population, in
        nondecreasing size order
    :raise TypeError: if minimum item count is specified but is not an integer
    :raise ValueError: if minimum item count is insufficient to guarantee
        nonempty subsets
       r   z9Min items count for each subset isn't an integer: {} ({})zEWhen minimum item count is {}, nonempty subsets cannot be guaranteed.c              3   J   K   | ]  }t        j                  |        y w)N)	itertoolscombinations).0kitemss     r   	<genexpr>zpowerset.<locals>.<genexpr>]   s#      &
12I""5!,&
s    #)r   int	TypeErrorformattype
ValueErrorlistlenr   chainfrom_iterablerange)r#   	min_itemsinclude_full_popnonemptyn	max_itemss   `     r   r   r   7   s    " !Aq	)S) &DO<  	A((.y(9  KEE
AAvY	"2E
QE
I%% &
6;Iy6Q&
 	
 r   c                    fdt         j                  d   dk\  rt        dt               | S i }| j	                         D ]  \  }}t        |t              r|j                  d      }t        |t              r|j                  d      }n4t        |t              r	 |      }nt        |t              rt        |      }|||<    |S )z/https://gist.github.com/chris-hailstorm/4989643c                     g }| D ]i  }t        |t              r|j                  d      }n4t        |t              r	 |      }nt        |t              rt        |      }|j                  |       k |S )Nutf-8)r   unicodeencoder*   dictr   append)lstretitem_asciify_lists      r   r>   z#asciify_dict.<locals>._asciify_listf   sj     	D$({{7+D$'$T*D$'#D)JJt	 
r   r   r   z+This operation is supported only in Python2r6   )sysversion_infor   UserWarning	iteritemsr   r7   r8   r*   r9   r   )datar<   keyvaluer>   s       @r   r   r   c   s    
 a:KH
Cnn& 	
Uc7#**W%CeW%LL)Et$!%(Et$ 'EC	 Jr   )NTF)__doc__r   r?   warningsr   r@   collectionsr   collections.abc
__author__	__email____all__r	   r   r   r   r    r   r   <module>rN      sR    *  
 f$(
"	 L
>	A)Xr   