ó
[³XMc           @   sT   d  Z  d d l Z d d l m Z m Z m Z m Z d d d „  ƒ  YZ d g Z d S(   sq   
DEPRECATED.

A (R)elational (O)bject (W)rapper.

This is an extremely thin wrapper.

Maintainer: Dave Peticolas
iÿÿÿÿN(   t   DBErrort   NOQUOTEt   getKeyColumnt	   dbTypeMapt	   RowObjectc           B   sY   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   s  
    I represent a row in a table in a relational database.

    My class is "populated" by a Reflector object. After I am
    populated, instances of me are able to interact with a particular
    database table.

    You should use a class derived from this class for each database
    table.

    reflector.loadObjectsFrom() is used to create sets of
    instance of objects of this class from database tables.

    Once created, the "key column" attributes cannot be changed.


    Class Attributes that users must supply::

       rowKeyColumns     # list of key columns in form: [(columnName, typeName)]
       rowTableName      # name of database table
       rowColumns        # list of the columns in the table with the correct
                         # case.this will be used to create member variables.
       rowFactoryMethod  # method to create an instance of this class.
                         # HACK: must be in a list!!! [factoryMethod] (optional)
       rowForeignKeys    # keys to other tables (optional)
    i    c         C   s   t  j d d t d d ƒd S(   s   
        DEPRECATED.
        s6   twisted.enterprise.row is deprecated since Twisted 8.0t   categoryt
   stackleveli   N(   t   warningst   warnt   DeprecationWarning(   t   self(    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   __init__4   s    c         C   s_   d } x, |  j  D]! \ } } | | k r d } q q W| sN t d | ƒ ‚ n  | |  j | <d S(   s…   Assign to a key attribute.

        This cannot be done through normal means to protect changing
        keys of db objects.
        i    i   s   %s is not a key columns.N(   t   rowKeyColumnsR    t   __dict__(   R
   t   attrNamet   valuet   foundt	   keyColumnt   type(    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   assignKeyAttr;   s    c         C   sS   x< |  j  D]1 \ } } | j ƒ  | j ƒ  k r
 t |  | ƒ Sq
 Wt d | ƒ ‚ d S(   s,   Find an attribute by caseless name.
        s   Unable to find attribute %sN(   t
   rowColumnst   lowert   getattrR    (   R
   R   t   attrR   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   findAttributeI   s    c         C   sƒ   t  |  j | ƒ r+ t d | | f ƒ ‚ n  | |  j k rr | |  j j | d ƒ k rr |  j rr |  j d ƒ qr n  | |  j | <d S(   s;   Special setattr to prevent changing of key values.
        sH   cannot assign value <%s> to key column attribute <%s> of RowObject classi   N(	   R   t	   __class__R    R   R   t   gett   Nonet   dirtyt   setDirty(   R
   t   nameR   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   __setattr__Q   s    %c         C   s¬   x¥ |  j  D]š } t |  j | ƒ r( q
 n  xy |  j D]n \ } } } | j | ƒ | j ƒ  k r2 t j | d ƒ } | t k r t	 |  | d ƒ q  t	 |  | d ƒ q2 q2 Wq
 Wd S(   s…   Populate instance with default attributes.

        This is used when creating a new instance NOT from the
        database.
        i    t    N(
   R   R   R   t	   dbColumnsR   R   R   R   R   t   setattr(   R
   R   t   columnt   ctypet   typeidt   q(    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   createDefaultAttributes^   s    c         C   s   | |  j  d <d S(   s‘   Use this to set the 'dirty' flag.

        (note: this avoids infinite recursion in __setattr__, and
        prevents the 'dirty' flag )
        R   N(   R   (   R
   t   flag(    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyR   o   s    c         C   sP   g  } | j  |  j ƒ x- |  j D]" \ } } | j  t |  | ƒ ƒ q  Wt | ƒ S(   N(   t   appendt   rowTableNameR   R   t   tuple(   R
   t   keyst   keyNamet   keyType(    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   getKeyTuplew   s
    (   t   __name__t
   __module__t   __doc__t	   populatedR   R   R   R   R   R'   R   R/   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyR      s   						(    (	   R2   R   t   twisted.enterprise.utilR    R   R   R   R   t   __all__(    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/enterprise/row.pyt   <module>   s   "j