ó
X–Tc           @   sK   d  Z  d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   sÞ   
This magic was taken from
http://code.activestate.com/recipes/81253-weakmethod/#c4

This module provides classes and methods for weakly referencing functions and
bound methods; it turns out this is a non-trivial problem.
iÿÿÿÿNt   WeakMethodBoundc           B   s5   e  Z d  Z d „  Z d „  Z e e ƒ Z d „  Z RS(   s   
    Holds a weak reference to a bound method for an object.

    .. attribute::method

        The function being called.
    c         C   s%   | j  |  _ t j | j ƒ |  _ d  S(   N(   t   im_funct   funct   weakreft   reft   im_selft   weak_object_ref(   t   selfR   (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyt   __init__   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyt   _func   s    c         G   s>   |  j  ƒ  d  k r! t d ƒ ‚ n  t |  j |  j  ƒ  f | ƒ S(   Ns   Method called on dead object(   R   t   Nonet	   TypeErrort   applyR   (   R   t   arg(    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyt   __call__   s    (   t   __name__t
   __module__t   __doc__R   R	   t   propertyt   methodR   (    (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyR       s
   		t   WeakMethodFreec           B   s5   e  Z d  Z d „  Z d „  Z e e ƒ Z d „  Z RS(   sš   
    Holds a weak reference to an unbound function. Included only for
    completeness.

    .. attribute::method

        The function being called.
    c         C   s   t  j | ƒ |  _ d  S(   N(   R   R   R   (   R   R   (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyR   '   s    c         C   s
   |  j  ƒ  S(   N(   R   (   R   (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyR	   )   s    c         G   s4   |  j  ƒ  d  k r! t d ƒ ‚ n  t |  j  ƒ  | ƒ S(   Ns   Function no longer exist(   R   R
   R   R   (   R   R   (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyR   ,   s    (   R   R   R   R   R	   R   R   R   (    (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyR      s
   		c         C   s*   y |  j  Wn t k
 r |  SXt |  ƒ S(   so   
    Attempts to create a weak reference to this function; only bound methods
    require a weakreference.
    (   R   t   AttributeErrorR    (   R   (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyt
   WeakMethod1   s
    (   R   R   t   objectR    R   R   (    (    (    s5   /usr/lib/python2.7/site-packages/spyral/weakmethod.pyt   <module>   s   