ó
¦–Õ\c           @   sn   d  d l  m Z m Z m Z d d l m Z d  d l Z e j d d d ƒd e f d	 „  ƒ  YZ d
 „  Z	 d S(   iÿÿÿÿ(   t   concatt   uniquet   counti   (   t   MappingNs_   ShareDict has been deprecated in favor of HighLevelGraph and will be removed in future versionst
   stackleveli   t	   ShareDictc           B   sY   e  Z d  Z d d d „ Z d d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sÚ   A Mapping composed of other Mappings

    This is a union of other disjoint mappings.  It allows the combination of
    many dicts into a single dict-like object without creating copies of the
    underlying dicts.  It provides cheap ``update``, ``len`` and ``__iter__``
    operations as well as a fairly cheap ``__getitem__`` operation (linear in
    the number of constituent mappings).

    This class is optimized for Dask's use, and may not be generally useful.
    Users may want to consider the standard ``collections.ChainMap`` data
    structure.

    This class makes the following assumptions:

    1.  Constituent mappings are disjoint.  No key is in more than one mapping.
    2.  Constituent mappings will not be modified

    Note that ShareDict does not enforce these assumptions.  It is up to the
    user to guarantee them.

    Examples
    --------
    >>> a = {'x': 1, 'y': 2}
    >>> b = {'z': 3}
    >>> s = ShareDict()
    >>> s.update(a)
    >>> s.update(b)

    >>> dict(s)  # doctest: +SKIP
    {'x': 1, 'y': 2, 'z': 3}

    These dictionaries are stored within an internal dictionary of dictionaries

    >>> list(s.dicts.values())  # doctest: +SKIP
    [{'x': 1, 'y': 2}, {'z': 3}]

    By default these are named by their object id.  However, you can also
    provide explicit names.

    >>> s = ShareDict()
    >>> s.update_with_key(a, key='a')
    >>> s.update_with_key(b, key='b')
    >>> s.dicts  # doctest: +SKIP
    {'a': {'x': 1, 'y': 2}, 'b': {'z': 3}}
    c         C   sL   | p t  ƒ  |  _ | p t  ƒ  |  _ t |  j ƒ t |  j ƒ k sH t ‚ d  S(   N(   t   dictt   dictst   dependenciest   sett   AssertionError(   t   selfR   R   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   __init__9   s    c         C   sá   t  | ƒ t k r] | d  k s3 | | j k s3 t ‚ |  j j | j ƒ |  j j | j ƒ d  S| d  k rx t | ƒ } n  | r² t | t	 t
 t f ƒ sœ t ‚ t | ƒ |  j | <n  t | t ƒ sÇ t ‚ | rÝ | |  j | <n  d  S(   N(   t   typeR   t   NoneR   R
   t   updateR   t   idt
   isinstancet   tuplet   listR	   R   (   R   t   argt   keyR   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   update_with_key?   s    !c         C   s   |  j  | ƒ d  S(   N(   R   (   R   R   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyR   Q   s    c         C   s>   x+ |  j  j ƒ  D] } | | k r | | Sq Wt | ƒ ‚ d  S(   N(   R   t   valuest   KeyError(   R   R   t   d(    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   __getitem__T   s    c         C   s   t  t |  ƒ ƒ S(   N(   R   t   iter(   R   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   __len__Z   s    c         c   sc   t  ƒ  } xS |  j j ƒ  D]B } x9 | D]1 } | | k r& | j | ƒ | | | f Vq& q& Wq Wd  S(   N(   R	   R   R   t   add(   R   t   seenR   R   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   items]   s    	c         C   s   t  t |  j j ƒ  ƒ ƒ S(   N(   R   R    R   R   (   R   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   __iter__e   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R    (    (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyR      s   -				c          O   s‘   | j  d d  ƒ } | s t ‚ t ƒ  } xL |  D]D } t | t ƒ rf | \ } } | j | d | ƒq/ | j | ƒ q/ W| j j | p‰ i  ƒ | S(   NR   R   (	   t   popR   R
   R   R   R   R   R   R   (   R   t   kwargsR   t   resultR   R   (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   mergei   s    	(
   t   toolzR    R   R   t   compatibilityR   t   warningst   warnR   R'   (    (    (    s-   lib/python2.7/site-packages/dask/sharedict.pyt   <module>   s   ^