σ
H`ΎTc           @@  sͺ   d  Z  d d l m Z d d l m Z m Z d d l m Z d d l m Z d d l m	 Z	 d d	 l
 m Z m Z d
 d d d d g Z e j d
 e f d     Y Z d S(   sz   MapperProperty implementations.

This is a private module which defines the behavior of invidual ORM-
mapped attributes.

i    (   t   absolute_importi   (   t   utilt   log(   t
   expressioni   (   t
   attributes(   t   _orm_full_deannotate(   t   PropComparatort   StrategizedPropertyt   ColumnPropertyt   CompositePropertyt   SynonymPropertyt   ComparablePropertyt   RelationshipPropertyc           B@  s~   e  Z d  Z d Z d   Z e d    Z d   Z d   Z d   Z	 e
 j d  Z d   Z d	 e f d
     YZ d   Z RS(   s   Describes an object attribute that corresponds to a table column.

    Public constructor is the :func:`.orm.column_property` function.

    t   columnc         O@  s   g  | D] } t  j |  ^ q |  _ g  | D] } t  j t |   ^ q, |  _ | j d d  |  _ | j d t  |  _	 | j d t
  |  _ | j d |  j j  |  _ | j d d  |  _ | j d d  |  _ | j d t  |  _ | j d t
  |  _ d	 | k r| j d	  |  _ n  d
 | k r@| j d
  |  _ nN xK t |  j  D]1 } t | d
 d  } | d k	 rP| |  _ PqPqPWd |  _ | rΘt d |  j j d j t | j     f   n  t j |   |  j d |  j	 f d |  j f  |  _ d S(   s!  Provide a column-level property for use with a Mapper.

        Column-based properties can normally be applied to the mapper's
        ``properties`` dictionary using the :class:`.Column` element directly.
        Use this function when the given column is not directly present within
        the mapper's selectable; examples include SQL expressions, functions,
        and scalar SELECT queries.

        Columns that aren't present in the mapper's selectable won't be
        persisted by the mapper and are effectively "read-only" attributes.

        :param \*cols:
              list of Column objects to be mapped.

        :param active_history=False:
          When ``True``, indicates that the "previous" value for a
          scalar attribute should be loaded when replaced, if not
          already loaded. Normally, history tracking logic for
          simple non-primary-key scalar values only needs to be
          aware of the "new" value in order to perform a flush. This
          flag is available for applications that make use of
          :func:`.attributes.get_history` or :meth:`.Session.is_modified`
          which also need to know
          the "previous" value of the attribute.

          .. versionadded:: 0.6.6

        :param comparator_factory: a class which extends
           :class:`.ColumnProperty.Comparator` which provides custom SQL
           clause generation for comparison operations.

        :param group:
            a group name for this property when marked as deferred.

        :param deferred:
              when True, the column property is "deferred", meaning that
              it does not load immediately, and is instead loaded when the
              attribute is first accessed on an instance.  See also
              :func:`~sqlalchemy.orm.deferred`.

        :param doc:
              optional string that will be applied as the doc on the
              class-bound descriptor.

        :param expire_on_flush=True:
            Disable expiry on flush.   A column_property() which refers
            to a SQL expression (and not a single table-bound column)
            is considered to be a "read only" property; populating it
            has no effect on the state of data, and it can only return
            database state.   For this reason a column_property()'s value
            is expired whenever the parent object is involved in a
            flush, that is, has any kind of "dirty" state within a flush.
            Setting this parameter to ``False`` will have the effect of
            leaving any existing value present after the flush proceeds.
            Note however that the :class:`.Session` with default expiration
            settings still expires
            all attributes after a :meth:`.Session.commit` call, however.

            .. versionadded:: 0.7.3

        :param info: Optional data dictionary which will be populated into the
            :attr:`.MapperProperty.info` attribute of this object.

            .. versionadded:: 0.8

        :param extension:
            an
            :class:`.AttributeExtension`
            instance, or list of extensions, which will be prepended
            to the list of attribute listeners for the resulting
            descriptor placed on the class.
            **Deprecated.** Please see :class:`.AttributeEvents`.

        t   groupt   deferredt   _instrumentt   comparator_factoryt
   descriptort	   extensiont   active_historyt   expire_on_flusht   infot   docs.   %s received unexpected keyword argument(s): %ss   , t
   instrumentN(    R   t   _labeledt   _orig_columnsR   t   columnst   popt   NoneR   t   FalseR   t   TrueR   t	   __class__t
   ComparatorR   R   R   R   R   R   R   t   reversedt   getattrt	   TypeErrort   __name__t   joint   sortedt   keysR   t   set_creation_ordert   _strategy_lookupt   strategy_class(   t   selfR   t   kwargst   ct   colR   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   __init__%   s>    K%(				%c         C@  s   |  j  d S(   sJ   Return the primary column or expression for this ColumnProperty.

        i    (   R   (   R,   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR      s    c      	   C@  sH   |  j  s d  St j | j |  j d |  j |  |  d | d |  j d  S(   Nt
   comparatort   parententityR   (   R   R   t   register_descriptort   class_t   keyR   R   (   R,   t   mapper(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   instrument_class   s    		c         C@  s~   t  t |   j   t |  j  d k rz t |  j j  j |  j  rz t	 j
 d |  j |  j d |  j d |  j f  n  d  S(   Ni   sΌ   On mapper %s, primary key column '%s' is being combined with distinct primary key column '%s' in attribute '%s'.  Use explicit properties to give each column its own mapped attribute name.i    (   t   superR   t   do_initt   lenR   t   sett   parentt   primary_keyt
   issupersetR   t   warnR5   (   R,   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR9   «   s    c         C@  s(   t  d |  j d |  j d |  j |  j  S(   NR   R   R   (   R   R   R   R   R   (   R,   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   copyΆ   s
    		c         C@  s"   | j  |  j  j | | d | S(   Nt   passive(   t   get_implR5   t   get_committed_value(   R,   t   statet   dict_R   RA   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   _getcommitted½   s    c   
      C@  s   |  j  s d  S|  j | k rj | |  j } | s? | | |  j <q | j |  j  }	 |	 j | | | d   n1 | j r |  j | k r | j | |  j g  n  d  S(   N(   R   R5   RB   R;   R   t   has_identityt   _expire_attributes(
   R,   t   sessiont   source_statet   source_dictt
   dest_statet	   dest_dictt   loadt
   _recursivet   valuet   impl(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   mergeΒ   s    	R!   c           B@  sM   e  Z d  Z e j d    Z e j d    Z d   Z d   Z	 d   Z
 RS(   sm  Produce boolean, comparison, and other operators for
        :class:`.ColumnProperty` attributes.

        See the documentation for :class:`.PropComparator` for a brief
        overview.

        See also:

        :class:`.PropComparator`

        :class:`.ColumnOperators`

        :ref:`types_operators`

        :attr:`.TypeEngine.comparator_factory`

        c         C@  sO   |  j  r  |  j  |  j j d  S|  j j d j i |  j d 6|  j d 6 Sd  S(   Ni    R2   t   parentmapper(   t   adaptert   propR   t	   _annotatet   _parentmapper(   R,   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   __clause_element__γ   s
    	
c         C@  s6   |  j    } y | j SWn t k
 r1 |  j j SXd  S(   N(   RX   R   t   AttributeErrorRU   (   R,   t   ce(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR   μ   s
    c         C@  s   t  |  j   |  S(   s   proxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            (   R#   RX   (   R,   R5   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   __getattr__τ   s    c         O@  s   | |  j    | |  S(   N(   RX   (   R,   t   opt   otherR-   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   operateϋ   s    c         K@  s(   |  j    } | | j | |  | |  S(   N(   RX   t   _bind_param(   R,   R\   R]   R-   R/   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   reverse_operateώ   s    (   R%   t
   __module__t   __doc__R   t   memoized_instancemethodRX   t   memoized_propertyR   R[   R^   R`   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR!   Ρ   s   			c         C@  s   t  |  j j j  d |  j S(   Nt   .(   t   strR<   R4   R%   R5   (   R,   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   __str__  s    (   R%   Ra   Rb   t   strategy_wildcard_keyR0   t   propertyR   R7   R9   R@   R   t   PASSIVE_OFFRF   RR   R   R!   Rg   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR      s   	s				1N(   Rb   t
   __future__R    t    R   R   t   sqlR   R   R   t
   interfacesR   R   t   __all__t   class_loggerR   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   <module>   s   		