mò
íðbFc           @   s6   d  Z  d „  Z d k l Z d e f d „  ƒ  YZ d S(   sb   Objects to describe values with namespaces.

$Id: object.py,v 1.10 2007/06/03 16:48:45 eddy Exp $
c         C   sY   t  |  ƒ oB y |  d ƒ Wn) t j
 o qO t j
 o |  SqO X|  Sn |  d „ S(   sº  Coerces an arbitrary value to a lookup.

    If the value is callable and accepts string arguments, it *is* a lookup,
    though strictly it should never raise any error (given a string argument)
    aside from AttributeError - which isn't checked.  Otherwise, the lookup
    returned borrows attributes from the value given - i.e. returns the result,
    when given any name, of looking for an attribute of that name on the given
    value. t	   __class__c         C   s   t  | |  ƒ S(   N(   t   getattrt   __wt   k(   R   R   (    (    t(   /home/eddy/.sys/py/study/value/object.pyt   <lambda>   s    N(   t   callablet   whomt	   TypeErrort   AttributeError(   R   (    (    R   t   aslookup   s        	(   s   Lazyt   Objectc           B   sk   t  Z d  Z d „  Z d „  Z d „  Z d „  Z f  Z e i	 Z
 d „  Z	 d „  Z d „  Z f  Z d „  Z RS(	   s#  A primitive object variety.

    Provides the following methods:

      copy() -- produces a duplicate object

      also(name=value, ...) -- perform assignment in the object's namespace

      borrow(lookup) -- arranges for object's attribute lookup to try the given
      lookup among others.  If the lookup isn't a callable of the right kind for
      use as a lookup, it is taken to be an object on which attribute lookup
      should be performed to achieve lookup.

    along with a __call__ method which ensures that a Object is a callable of
    the right kind to be used as a lookup - this method just does attribute
    lookup on the object.

    Inherits from Lazy and supports an attribute, dir, which is a copy of the
    object's namespace dictionary, omitting names which start with '_'. c         G   s   t  |  i | |  i ƒ  ƒ S(   N(   t   applyt   selfR    t   argst   _Object__star(   R   R   (    (    R   t   copy6   s    c         C   s
   |  i ƒ  S(   N(   R   R   (   R   t   ignored(    (    R   t   _lazy_get_dir_7   s    c         C   s7   |  i } | |  i i j o t | ƒ } |  _ n | S(   N(   R   t   _lazy_preserve_t   rowR    t   list(   R   R   (    (    R   t   __ephem9   s    	c         K   sA   |  i i | ƒ x |  i D] } d  | | <q W| i ƒ  |  _ d  S(   N(   R   t   __dict__t   updatet   whatR   R   t   Nonet   keys(   R   R   R   (    (    R   t   alsoB   s
    
  c         O   s¢   y | d } Wn t j
 o |  i ƒ  n X| d =|  i d | ƒ t |  i f  | ƒ t | ƒ |  i	 g } | d „ } | |  i d „ } | |  _ | |  _	 d S(   sî  Initialiser for Object()s.

        Arguments in name=value form are used to initialise the new object's
        namespace.  The name 'lazy_aliases', if used, is sacred to Lazy (q.v.).
        Positional arguments (which, if present, must appear before name=value
        ones) should be lookups for use when computing attributes of the object.
        These will only ever be called once for any key; and they will never be
        called for attributes named in self._unborrowable_attributes_ (evaluated
        during initialisation, after setting attributes supplied as name=value
        arguments, but before extending Lazy's attribute mechanisms with
        Object's borrowing mechanisms).

        Positional arguments should be lookups, i.e. callables, accepting one
        argument (the attribute name) and either returning a value (for the
        attribute) or raising AttributeError.  No attempt is made to coerce them
        into this form.  Note that any Object is a lookup.

        The list of lookups may be extended, after initialisation, by passing a
        lookup to the .borrow() method of the object; the new lookup will be
        added after all lookups supplied to initialisation, but before self's
        own lazy infrastructure. t   lazy_aliasesc         C   s   | i d t |  ƒ ƒ d  S(   Niÿÿÿÿ(   t   _rowt   insertR
   t   where(   R    R   (    (    R   t   borrowq   s    c         C   sž   |  | j p8 |  d  d j o8 |  d  d j o |  d j n o | d f } n | } x2 | D]* } y | |  ƒ SWqc t j
 o qc Xqc Wt |  ‚ d  S(   Ni   t   _i   t   __iþÿÿÿiÿÿÿÿ(   t   keyt   _inalienR   R   t   itemR	   (   R$   R   R%   R&   R   (    (    R   t   getitt   s    E   	N(   R   t   aliasest   KeyErrorR   t   _Object__upinitR   R   R   t   lookupst   _lazy_lookup_R   R!   t   _unborrowable_attributes_R'   (   R   R+   R   R!   R   R'   R(   (    (    R   t   __init__K   s       	c         C   s^   | |  i j o |  i ƒ  i | ƒ n y |  i | =Wn" t j
 o t d | ƒ ‚ n Xd  S(   Ns   No such attribute to delete(   R$   R   R   t   _Object__ephemt   removeR   R)   R	   (   R   R$   (    (    R   t   __delattr__‚   s     c         C   se   h  } xX t d „  |  i i ƒ  ƒ D]; } | |  i j p |  i | ƒ p |  i | | | <q" q" W| S(   Nc         C   s   |  d d j S(   Ni    R"   (   R   (   R   (    (    R   R   Œ   s    (   t   bokt   filterR   R   R   R$   t   _borrowed_value_t   _lazy_ephemeral_(   R   R2   R$   (    (    R   t   __starŠ   s      c         C   s   t  |  | ƒ S(   N(   R   R   R$   (   R   R$   (    (    R   t   __call__•   s    (   t   __name__t
   __module__t   __doc__R   R   R/   R   R-   t   LazyR.   R*   R1   R   R4   R7   (    (    (    R   R   !   s    							7		N(   R:   R
   t   study.snake.lazyR;   R   (   R
   R   R;   (    (    R   t   ?   s   	