ó
¿b›]c           @@  s²   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d	 l m
 Z
 d d
 l m Z d d l m Z d g Z e
 j d e f d „  ƒ  Yƒ Z d S(   s|   MapperProperty implementations.

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

i    (   t   absolute_importi   (   t
   attributes(   t   PropComparator(   t   StrategizedProperty(   t   _orm_full_deannotatei   (   t   log(   t   util(   t
   expressiont   ColumnPropertyc           B@  sÀ   e  Z d  Z d Z d# Z e j d	 d$ ƒ d „  ƒ Z e j d d ƒ d „  ƒ Z	 d „  Z
 e d „  ƒ Z d „  Z d „  Z d „  Z e j d „ Z d „  Z d  e j 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   columnt   _orig_columnst   columnst   groupt   deferredt
   instrumentt   comparator_factoryt
   descriptort	   extensiont   active_historyt   expire_on_flusht   infot   doct   strategy_keyt   _creation_ordert   _is_polymorphic_discriminatort   _mapped_by_synonymt   _deferred_column_loaders   0.7sÃ   :class:`.AttributeExtension` is deprecated in favor of the :class:`.AttributeEvents` listener interface.  The :paramref:`.column_property.extension` parameter will be removed in a future release.c         O@  s  t  t |  ƒ j ƒ  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 r2| j d	 ƒ |  _ n  d
 | k rS| j d
 ƒ |  _ nN xK t |  j ƒ D]1 } t | d
 d ƒ } | d k	 rc| |  _ PqcqcWd |  _ | rÛt d |  j j d j t | j ƒ  ƒ ƒ f ƒ ‚ n  t j  |  ƒ d |  j f d |  j f 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.

        :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.

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

        :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.

        R   R   t   _instrumentR   R   R   R   R   R   R   s.   %s received unexpected keyword argument(s): %ss   , R   N("   t   superR   t   __init__R   t   _labeledR
   R   R   t   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_orderR   (   t   selfR   t   kwargst   ct   colR   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR   :   s:    K%+		.s   sqlalchemy.orm.states   sqlalchemy.orm.strategiesc         C@  s+   | j  j |  j j | j |  j ƒ |  j ƒ S(   N(   t   InstanceStatet"   _instance_level_callable_processort   parentt   class_managert   LoadDeferredColumnst   key(   R-   t   statet
   strategies(    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt&   _memoized_attr__deferred_column_loader°   s    		c         C@  s   |  j  S(   ss   Allow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        (   R   (   R-   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   __clause_element__¸   s    c         C@  s   |  j  d S(   sJ   Return the primary column or expression for this ColumnProperty.

        i    (   R   (   R-   (    (    s8   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_R6   R   R   (   R-   t   mapper(    (    s8   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    (   R   R   t   do_initt   lenR   t   setR3   t   primary_keyt
   issupersetR   t   warnR6   (   R-   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyRA   Ò   s    'c         C@  s(   t  d |  j d |  j d |  j |  j Œ S(   NR   R   R   (   R   R   R   R   R   (   R-   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   copyá   s
    		c         C@  s"   | j  |  j ƒ j | | d | ƒS(   Nt   passive(   t   get_implR6   t   get_committed_value(   R-   R7   t   dict_R	   RH   (    (    s8   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  ƒ n7 | j r¡ |  j | k r¡ | j | |  j g d t ƒn  d  S(   Nt	   no_loader(   R   R6   RI   RC   R    t   has_identityt   _expire_attributesR"   (   R-   t   sessiont   source_statet   source_dictt
   dest_statet	   dest_dictt   loadt
   _recursivet   _resolve_conflict_mapt   valuet   impl(    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   mergeð   s    	R$   c           B@  sA   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(	   s€  Produce boolean, comparison, and other operators for
        :class:`.ColumnProperty` attributes.

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

        .. seealso::

            :class:`.PropComparator`

            :class:`.ColumnOperators`

            :ref:`types_operators`

            :attr:`.TypeEngine.comparator_factory`

        R:   R   c         C@  sO   |  j  r  |  j  |  j j d ƒ S|  j j d j i |  j d 6|  j d 6ƒ Sd  S(   Ni    R<   t   parentmapper(   t   adaptert   propR   t	   _annotatet   _parententity(   R-   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt#   _memoized_method___clause_element__  s    	
c         C@  s6   |  j  ƒ  } y | j SWn t k
 r1 |  j j SXd  S(   N(   R:   R   t   AttributeErrorR]   (   R-   t   ce(    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   _memoized_attr_info,  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&   R:   (   R-   R6   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   _fallback_getattr3  s    c         O@  s   | |  j  ƒ  | | Ž S(   N(   R:   (   R-   t   opt   otherR.   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   operate:  s    c         K@  s(   |  j  ƒ  } | | j | | ƒ | |  S(   N(   R:   t   _bind_param(   R-   Re   Rf   R.   R0   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   reverse_operate=  s    (   R:   R   (	   R(   t
   __module__t   __doc__t	   __slots__R`   Rc   Rd   Rg   Ri   (    (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR$   
  s   				c         C@  s   t  |  j j j ƒ d |  j S(   Nt   .(   t   strR3   R>   R(   R6   (   R-   (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   __str__A  s    (   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (   s   0.7sÃ   :class:`.AttributeExtension` is deprecated in favor of the :class:`.AttributeEvents` listener interface.  The :paramref:`.column_property.extension` parameter will be removed in a future release.(   R(   Rj   Rk   t   strategy_wildcard_keyRl   R   t   deprecated_paramsR   t   dependenciesR9   R:   t   propertyR   R@   RA   RG   R   t   PASSIVE_OFFRL   RZ   t   MemoizedSlotsR   R$   Ro   (    (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyR      s@                   	 s						7N(   Rk   t
   __future__R    t    R   t
   interfacesR   R   R   R   R   t   sqlR   t   __all__t   class_loggerR   (    (    (    s8   lib/python2.7/site-packages/sqlalchemy/orm/properties.pyt   <module>   s   		