ó
[³XMc           @   sl   d  d l  Z  d  d l Z d  d l m Z d d d „  ƒ  YZ d Z d Z d Z d Z d d	 d
 d d g Z	 d S(   iÿÿÿÿN(   t   DBErrort	   Reflectorc           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 d „  Z d „  Z d d g  d d „ Z d „  Z d „  Z d „  Z RS(   s]   
    DEPRECATED.

    Base class for enterprise reflectors. This implements row caching.
    i    c         C   sH   t  j d d t d d ƒt j ƒ  |  _ | |  _ i  |  _ |  j ƒ  d S(   sš   
        Initialize me against a database.

        @param rowClasses: a list of row class objects that describe the
            database schema.
        s<   twisted.enterprise.reflector is deprecated since Twisted 8.0t   categoryt
   stackleveli   N(	   t   warningst   warnt   DeprecationWarningt   weakreft   WeakValueDictionaryt   rowCachet
   rowClassest   schemat	   _populate(   t   selfR
   (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   __init__   s    		c         C   s   |  j  j ƒ  } | d =| S(   NR	   (   t   __dict__t   copy(   R   t   d(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   __getstate__!   s    c         C   s&   | |  _  t j ƒ  |  _ |  j ƒ  d  S(   N(   R   R   R   R	   R   (   R   t   state(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   __setstate__&   s    	c         C   s   t  d ƒ ‚ d S(   sG   Implement me to populate schema information for the reflector.
        s   not implementedN(   R    (   R   (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyR   +   s    c         C   sZ   | |  j  | j <xC | j D]8 \ } } } } } |  j  | j | | | j | | ƒ q Wd S(   s   This is called once for each registered rowClass to add it
        and its foreign key relationships for that rowClass to the
        schema.N(   R   t   rowTableNamet   rowForeignKeyst   addForeignKeyt   rowClass(   R   t	   tableInfot   foreignTableNamet   childColumnst   parentColumnst   containerMethodt   autoLoad(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   populateSchemaFor0   s
    	c         C   sC   y |  j  | j SWn* t k
 r> t d | j |  f ƒ ‚ n Xd S(   s  Get a TableInfo record about a particular instance.

        This record contains various information about the instance's
        class as registered with this reflector.

        @param rowObject: a L{RowObject} instance of a class previously
            registered with me.
        @raises twisted.enterprise.row.DBError: raised if this class was not
            previously registered.
        s#   class %s was not registered with %sN(   R   R   t   KeyErrorR    t	   __class__(   R   t	   rowObject(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   getTableInfo=   s
    c         C   sh   g  } x[ t  d t | j ƒ ƒ D]A } t | | j | d ƒ } | j | j | d t | g ƒ q W| S(   s^   util method used by reflectors. builds a where clause to link a row to another table.
        i    (   t   ranget   lenR   t   getattrR   t   appendt   EQUAL(   R   t   relationshipt   rowt   whereClauset   it   value(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   buildWhereClauseN   s
    %c         C   sú   |  j  | ƒ } | j | ƒ } | s@ t d | j | f ƒ ‚ n  | j s› t | d ƒ rŽ x< | D]( } | | j k r_ | j j | ƒ q_ q_ Wn	 | | _ d St | | j ƒ sÉ t d | | j f ƒ ‚ n  t | | j ƒ } x | D] } | | ƒ qâ Wd S(   sÁ   util method used by reflectors. adds these rows to the parent row object.
        If a rowClass does not have a containerMethod, then a list attribute "childRows"
        will be used.
        s   no relationship from %s to %st	   childRowsNs2   parent row (%s) doesnt have container method <%s>!(	   R#   t   getRelationshipForR    R   R   t   hasattrR/   R'   R&   (   R   t	   parentRowt   rowst	   tableNamet
   parentInfoR)   R*   t   meth(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   addToParentW   s     		c         C   s   | |  j  | j ƒ  <d S(   sG   NOTE: Should this be recursive?! requires better container knowledge...N(   R	   t   getKeyTuple(   R   R"   (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt
   addToCaches   s    c         C   s]   g  } | j  | j ƒ x( | j D] \ } } | j  | | ƒ q  Wt | ƒ } |  j j | ƒ S(   N(   R'   R   t   rowKeyColumnst   tupleR	   t   get(   R   R   t   kwt   keyst   keyNamet   keyTypet   keyTuple(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   findInCachew   s    c         C   s/   | j  ƒ  } |  j j | ƒ r+ |  j | =n  d S(   s!   NOTE: should this be recursive!??N(   R8   R	   t   has_key(   R   R"   t   key(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   removeFromCache   s    i   c         C   s   t  d ƒ ‚ d S(   s  Implement me to load objects from the database.

        @param whereClause: a list of tuples of (columnName, conditional, value)
            so it can be parsed by all types of reflectors. eg.::
              whereClause = [("name", EQUALS, "fred"), ("age", GREATERTHAN, 18)]
        s   not implementedN(   R    (   R   R4   t   parentt   dataR+   t   loadChildren(    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   loadObjectsFrom‡   s    c         C   s   t  d ƒ ‚ d S(   s/   update this rowObject to the database.
        s   not implementedN(   R    (   R   R"   (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt	   updateRow‘   s    c         C   s   t  d ƒ ‚ d S(   s3   insert a new row for this object instance.
        s   not implementedN(   R    (   R   R"   (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt	   insertRow–   s    c         C   s   t  d ƒ ‚ d S(   s:   delete the row for this object from the database.
        s   not implementedN(   R    (   R   R"   (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt	   deleteRow›   s    N(   t   __name__t
   __module__t   __doc__t	   populatedR   R   R   R   R   R#   R.   R7   R9   RB   RE   t   NoneRI   RJ   RK   RL   (    (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyR   
   s$   															i    i   i   i   R(   t   LESSTHANt   GREATERTHANt   LIKE(    (
   R   R   t   twisted.enterprise.utilR    R   R(   RR   RS   RT   t   __all__(    (    (    s@   /usr/lib/python2.7/dist-packages/twisted/enterprise/reflector.pyt   <module>   s   —