ó
è¾bc           @   sô   d  Z  d d l Z d d l m Z m Z m Z m Z m Z m Z m	 Z	 m
 Z
 d d l m Z m Z d d l m Z e e f Z d d d d	 d
 d d d d d d d g Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d
 e j f d „  ƒ  YZ d S(   s{   Weak reference support for Python.

This module is an implementation of PEP 205:

http://www.python.org/dev/peps/pep-0205/
iÿÿÿÿN(   t   getweakrefcountt   getweakrefst   reft   proxyt   CallableProxyTypet	   ProxyTypet   ReferenceTypet   _remove_dead_weakref(   t   WeakSett   _IterationGuard(   t   ReferenceErrorR   R   R    R   t   WeakKeyDictionaryR
   R   R   R   t
   ProxyTypest   WeakValueDictionaryR   c           B   sï   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z e Z d „  Z d d „ Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   s›   Mapping class that references values weakly.

    Entries in the dictionary will be discarded when no strong
    reference to the value exists anymore
    c          O   s¡   |  s t  d ƒ ‚ n  |  d } |  d }  t |  ƒ d k rT t  d t |  ƒ ƒ ‚ n  t | ƒ t d „ } | | _ g  | _ t ƒ  | _ t j j	 | |  | Ž d  S(   NsG   descriptor '__init__' of 'WeakValueDictionary' object needs an argumenti    i   s$   expected at most 1 arguments, got %dc         S   sN   | ƒ  } | d  k	 rJ | j r4 | j j |  j ƒ qJ | | j |  j ƒ n  d  S(   N(   t   Nonet
   _iteratingt   _pending_removalst   appendt   keyt   data(   t   wrt   selfreft   _atomic_removalt   self(    (    s   /usr/lib/python2.7/weakref.pyt   remove8   s
    		(
   t	   TypeErrort   lenR   R   t   _removeR   t   setR   t   UserDictt   __init__(   t   argst   kwR   R   (    (    s   /usr/lib/python2.7/weakref.pyR   0   s    

			c         C   s<   |  j  } |  j } x# | r7 | j ƒ  } t | | ƒ q Wd  S(   N(   R   R   t   popR   (   R   t   lt   dR   (    (    s   /usr/lib/python2.7/weakref.pyt   _commit_removalsG   s
    			c         C   sF   |  j  r |  j ƒ  n  |  j | ƒ  } | d  k r> t | ‚ n | Sd  S(   N(   R   R$   R   R   t   KeyError(   R   R   t   o(    (    s   /usr/lib/python2.7/weakref.pyt   __getitem__P   s    	c         C   s$   |  j  r |  j ƒ  n  |  j | =d  S(   N(   R   R$   R   (   R   R   (    (    s   /usr/lib/python2.7/weakref.pyt   __delitem__Y   s    	c         C   sI   |  j  r |  j ƒ  n  y |  j | ƒ  } Wn t k
 r> t SX| d  k	 S(   N(   R   R$   R   R%   t   FalseR   (   R   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyt   __contains__^   s    	c         C   sI   |  j  r |  j ƒ  n  y |  j | ƒ  } Wn t k
 r> t SX| d  k	 S(   N(   R   R$   R   R%   R)   R   (   R   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyt   has_keyg   s    	c         C   s   d t  |  ƒ S(   Ns   <WeakValueDictionary at %s>(   t   id(   R   (    (    s   /usr/lib/python2.7/weakref.pyt   __repr__p   s    c         C   s6   |  j  r |  j ƒ  n  t | |  j | ƒ |  j | <d  S(   N(   R   R$   t   KeyedRefR   R   (   R   R   t   value(    (    s   /usr/lib/python2.7/weakref.pyt   __setitem__s   s    	c         C   s'   |  j  r |  j ƒ  n  |  j j ƒ  d  S(   N(   R   R$   R   t   clear(   R   (    (    s   /usr/lib/python2.7/weakref.pyR1   x   s    	c         C   se   |  j  r |  j ƒ  n  t ƒ  } x? |  j j ƒ  D]. \ } } | ƒ  } | d  k	 r/ | | | <q/ q/ W| S(   N(   R   R$   R   R   t   itemsR   (   R   t   newR   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyt   copy}   s    			c         C   s   d d l  m } |  j r& |  j ƒ  n  |  j ƒ  } xH |  j j ƒ  D]7 \ } } | ƒ  } | d  k	 rB | | | | | ƒ <qB qB W| S(   Niÿÿÿÿ(   t   deepcopy(   R4   R5   R   R$   t	   __class__R   R2   R   (   R   t   memoR5   R3   R   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyt   __deepcopy__‰   s    		c         C   s]   |  j  r |  j ƒ  n  y |  j | } Wn t k
 r; | SX| ƒ  } | d  k rU | S| Sd  S(   N(   R   R$   R   R%   R   (   R   R   t   defaultR   R&   (    (    s   /usr/lib/python2.7/weakref.pyt   get”   s    		c         C   sk   |  j  r |  j ƒ  n  g  } xH |  j j ƒ  D]7 \ } } | ƒ  } | d  k	 r, | j | | f ƒ q, q, W| S(   N(   R   R$   R   R2   R   R   (   R   t   LR   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyR2   £   s    		c         c   sm   |  j  r |  j ƒ  n  t |  ƒ E x= |  j j ƒ  D], } | ƒ  } | d  k	 r3 | j | f Vq3 q3 WWd  QXd  S(   N(   R   R$   R	   R   t
   itervaluesR   R   (   R   R   R/   (    (    s   /usr/lib/python2.7/weakref.pyt	   iteritems­   s    		c         c   sL   |  j  r |  j ƒ  n  t |  ƒ $ x |  j j ƒ  D] } | Vq3 WWd  QXd  S(   N(   R   R$   R	   R   t   iterkeys(   R   t   k(    (    s   /usr/lib/python2.7/weakref.pyR>   ¶   s
    	c         c   sL   |  j  r |  j ƒ  n  t |  ƒ $ x |  j j ƒ  D] } | Vq3 WWd QXd S(   s  Return an iterator that yields the weak references to the values.

        The references are not guaranteed to be 'live' at the time
        they are used, so the result of calling the references needs
        to be checked before being used.  This can be used to avoid
        creating references that will cause the garbage collector to
        keep the values around longer than needed.

        N(   R   R$   R	   R   R<   (   R   R   (    (    s   /usr/lib/python2.7/weakref.pyt   itervaluerefs¿   s
    
	c         c   sd   |  j  r |  j ƒ  n  t |  ƒ < x4 |  j j ƒ  D]# } | ƒ  } | d  k	 r3 | Vq3 q3 WWd  QXd  S(   N(   R   R$   R	   R   R<   R   (   R   R   t   obj(    (    s   /usr/lib/python2.7/weakref.pyR<   Ï   s    		c         C   sU   |  j  r |  j ƒ  n  x8 |  j j ƒ  \ } } | ƒ  } | d  k	 r | | f Sq Wd  S(   N(   R   R$   R   t   popitemR   (   R   R   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyRB   Ø   s    		c         G   sw   |  j  r |  j ƒ  n  y |  j j | ƒ ƒ  } Wn t k
 rH d  } n X| d  k ro | rc | d St | ‚ n | Sd  S(   Ni    (   R   R$   R   R!   R%   R   (   R   R   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyR!   á   s    	
c         C   sx   |  j  r |  j ƒ  n  y |  j | ƒ  } Wn t k
 rC d  } n X| d  k rp t | |  j | ƒ |  j | <| S| Sd  S(   N(   R   R$   R   R%   R   R.   R   (   R   R   R9   R&   (    (    s   /usr/lib/python2.7/weakref.pyt
   setdefaultð   s    	
c          O   s  |  s t  d ƒ ‚ n  |  d } |  d }  t |  ƒ d k rT t  d t |  ƒ ƒ ‚ n  |  rd |  d n d  } | j r€ | j ƒ  n  | j } | d  k	 rò t | d ƒ s¹ t i  ƒ | ƒ } n  x6 | j ƒ  D]% \ } } t	 | | j
 | ƒ | | <qÆ Wn  t | ƒ r| j | ƒ n  d  S(   NsE   descriptor 'update' of 'WeakValueDictionary' object needs an argumenti    i   s$   expected at most 1 arguments, got %dR2   (   R   R   R   R   R$   R   t   hasattrt   typeR2   R.   R   t   update(   R   t   kwargsR   t   dictR#   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyRF   ý   s"    

		 c         C   s#   |  j  r |  j ƒ  n  |  j j ƒ  S(   s~  Return a list of weak references to the values.

        The references are not guaranteed to be 'live' at the time
        they are used, so the result of calling the references needs
        to be checked before being used.  This can be used to avoid
        creating references that will cause the garbage collector to
        keep the values around longer than needed.

        (   R   R$   R   t   values(   R   (    (    s   /usr/lib/python2.7/weakref.pyt	   valuerefs  s    
	c         C   s_   |  j  r |  j ƒ  n  g  } x< |  j j ƒ  D]+ } | ƒ  } | d  k	 r, | j | ƒ q, q, W| S(   N(   R   R$   R   RI   R   R   (   R   R;   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyRI     s    		N(   t   __name__t
   __module__t   __doc__R   R$   R'   R(   R*   R+   R-   R0   R1   R4   t   __copy__R8   R   R:   R2   R=   R>   t   __iter__R@   R<   RB   R!   RC   RF   RJ   RI   (    (    (    s   /usr/lib/python2.7/weakref.pyR   $   s4   														
		
											R.   c           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   s[  Specialized reference that includes a key corresponding to the value.

    This is used in the WeakValueDictionary to avoid having to create
    a function object for each key stored in the mapping.  A shared
    callback object can use the 'key' attribute of a KeyedRef instead
    of getting a reference to the key from an enclosing scope.

    R   c         C   s"   t  j |  | | ƒ } | | _ | S(   N(   R   t   __new__R   (   RE   t   obt   callbackR   R   (    (    s   /usr/lib/python2.7/weakref.pyRP   6  s    	c         C   s   t  t |  ƒ j | | ƒ d  S(   N(   t   superR.   R   (   R   RQ   RR   R   (    (    s   /usr/lib/python2.7/weakref.pyR   ;  s    (   R   (   RK   RL   RM   t	   __slots__RP   R   (    (    (    s   /usr/lib/python2.7/weakref.pyR.   *  s   	c           B   sì   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e
 Z d „  Z d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z RS(   s‰   Mapping class that references keys weakly.

    Entries in the dictionary will be discarded when there is no
    longer a strong reference to the key. This can be used to
    associate additional data with an object owned by other parts of
    an application without adding attributes to those objects. This
    can be especially useful with objects that override attribute
    accesses.
    c         C   sY   i  |  _  t |  ƒ d „ } | |  _ g  |  _ t ƒ  |  _ | d  k	 rU |  j | ƒ n  d  S(   Nc         S   sB   | ƒ  } | d  k	 r> | j r1 | j j |  ƒ q> | j |  =n  d  S(   N(   R   R   R   R   R   (   R?   R   R   (    (    s   /usr/lib/python2.7/weakref.pyR   L  s
    		(   R   R   R   R   R   R   R   RF   (   R   RH   R   (    (    s   /usr/lib/python2.7/weakref.pyR   J  s    			c         C   sH   |  j  } |  j } x/ | rC y | | j ƒ  =Wq t k
 r? q Xq Wd  S(   N(   R   R   R!   R%   (   R   R"   R#   (    (    s   /usr/lib/python2.7/weakref.pyR$   Z  s    			c         C   s   |  j  t | ƒ =d  S(   N(   R   R   (   R   R   (    (    s   /usr/lib/python2.7/weakref.pyR(   g  s    c         C   s   |  j  t | ƒ S(   N(   R   R   (   R   R   (    (    s   /usr/lib/python2.7/weakref.pyR'   j  s    c         C   s   d t  |  ƒ S(   Ns   <WeakKeyDictionary at %s>(   R,   (   R   (    (    s   /usr/lib/python2.7/weakref.pyR-   m  s    c         C   s   | |  j  t | |  j ƒ <d  S(   N(   R   R   R   (   R   R   R/   (    (    s   /usr/lib/python2.7/weakref.pyR0   p  s    c         C   sO   t  ƒ  } x? |  j j ƒ  D]. \ } } | ƒ  } | d  k	 r | | | <q q W| S(   N(   R   R   R2   R   (   R   R3   R   R/   R&   (    (    s   /usr/lib/python2.7/weakref.pyR4   s  s    		c         C   sk   d d l  m } |  j ƒ  } xH |  j j ƒ  D]7 \ } } | ƒ  } | d  k	 r, | | | ƒ | | <q, q, W| S(   Niÿÿÿÿ(   R5   (   R4   R5   R6   R   R2   R   (   R   R7   R5   R3   R   R/   R&   (    (    s   /usr/lib/python2.7/weakref.pyR8   }  s    	c         C   s   |  j  j t | ƒ | ƒ S(   N(   R   R:   R   (   R   R   R9   (    (    s   /usr/lib/python2.7/weakref.pyR:   †  s    c         C   s2   y t  | ƒ } Wn t k
 r$ d SX| |  j k S(   Ni    (   R   R   R   (   R   R   R   (    (    s   /usr/lib/python2.7/weakref.pyR+   ‰  s
    c         C   s2   y t  | ƒ } Wn t k
 r$ d SX| |  j k S(   Ni    (   R   R   R   (   R   R   R   (    (    s   /usr/lib/python2.7/weakref.pyR*     s
    c         C   sU   g  } xH |  j  j ƒ  D]7 \ } } | ƒ  } | d  k	 r | j | | f ƒ q q W| S(   N(   R   R2   R   R   (   R   R;   R   R/   R&   (    (    s   /usr/lib/python2.7/weakref.pyR2   —  s    	c         c   sZ   t  |  ƒ H x@ |  j j ƒ  D]/ \ } } | ƒ  } | d  k	 r | | f Vq q WWd  QXd  S(   N(   R	   R   R=   R   (   R   R   R/   R   (    (    s   /usr/lib/python2.7/weakref.pyR=   Ÿ  s
    	c         c   s6   t  |  ƒ $ x |  j j ƒ  D] } | Vq WWd QXd S(   sŒ  Return an iterator that yields the weak references to the keys.

        The references are not guaranteed to be 'live' at the time
        they are used, so the result of calling the references needs
        to be checked before being used.  This can be used to avoid
        creating references that will cause the garbage collector to
        keep the keys around longer than needed.

        N(   R	   R   R>   (   R   R   (    (    s   /usr/lib/python2.7/weakref.pyt   iterkeyrefs¦  s    
c         c   sN   t  |  ƒ < x4 |  j j ƒ  D]# } | ƒ  } | d  k	 r | Vq q WWd  QXd  S(   N(   R	   R   R>   R   (   R   R   RA   (    (    s   /usr/lib/python2.7/weakref.pyR>   ´  s
    	c         c   s6   t  |  ƒ $ x |  j j ƒ  D] } | Vq WWd  QXd  S(   N(   R	   R   R<   (   R   R/   (    (    s   /usr/lib/python2.7/weakref.pyR<   ½  s    c         C   s   |  j  j ƒ  S(   sz  Return a list of weak references to the keys.

        The references are not guaranteed to be 'live' at the time
        they are used, so the result of calling the references needs
        to be checked before being used.  This can be used to avoid
        creating references that will cause the garbage collector to
        keep the keys around longer than needed.

        (   R   t   keys(   R   (    (    s   /usr/lib/python2.7/weakref.pyt   keyrefsÂ  s    
c         C   sI   g  } x< |  j  j ƒ  D]+ } | ƒ  } | d  k	 r | j | ƒ q q W| S(   N(   R   RV   R   R   (   R   R;   R   R&   (    (    s   /usr/lib/python2.7/weakref.pyRV   Î  s    	c         C   s?   x8 |  j  j ƒ  \ } } | ƒ  } | d  k	 r | | f Sq Wd  S(   N(   R   RB   R   (   R   R   R/   R&   (    (    s   /usr/lib/python2.7/weakref.pyRB   Ö  s
    	c         G   s   |  j  j t | ƒ | Œ S(   N(   R   R!   R   (   R   R   R   (    (    s   /usr/lib/python2.7/weakref.pyR!   Ý  s    c         C   s   |  j  j t | |  j ƒ | ƒ S(   N(   R   RC   R   R   (   R   R   R9   (    (    s   /usr/lib/python2.7/weakref.pyRC   à  s    c         K   s   |  j  } | d  k	 ro t | d ƒ s9 t i  ƒ | ƒ } n  x3 | j ƒ  D]" \ } } | | t | |  j ƒ <qF Wn  t | ƒ r‹ |  j | ƒ n  d  S(   NR2   (	   R   R   RD   RE   R2   R   R   R   RF   (   R   RH   RG   R#   R   R/   (    (    s   /usr/lib/python2.7/weakref.pyRF   ã  s    	N(   RK   RL   RM   R   R   R$   R(   R'   R-   R0   R4   RN   R8   R:   R+   R*   R2   R=   RU   R>   RO   R<   RW   RV   RB   R!   RC   RF   (    (    (    s   /usr/lib/python2.7/weakref.pyR   ?  s2   																				(   RM   R   t   _weakrefR    R   R   R   R   R   R   R   t   _weakrefsetR   R	   t
   exceptionsR
   R   t   __all__R   R.   R   (    (    (    s   /usr/lib/python2.7/weakref.pyt   <module>   s   :
ÿ 