/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext
Edit: /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyo (63381B)
4]c @ s d Z d d l 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 Z
e j d
Z d e j f d YZ d e f d YZ d e f d YZ d e f d YZ d e e f d YZ d e f d YZ d e f d YZ d e f d YZ e j d Z d e f d YZ d! e f d" YZ d S(# s Contain the ``AssociationProxy`` class.
The ``AssociationProxy`` is a Python property object which provides
transparent proxied access to the endpoint of an association object.
See the example ``examples/association/proxied_association.py``.
iNi ( t exc( t inspect( t orm( t util( t collections( t
interfaces( t or_( t ColumnOperatorsc K s t | | | S( s Return a Python property implementing a view of a target
attribute which references an attribute on members of the
target.
The returned value is an instance of :class:`.AssociationProxy`.
Implements a Python property representing a relationship as a collection
of simpler values, or a scalar value. The proxied property will mimic
the collection type of the target (list, dict or set), or, in the case of
a one to one relationship, a simple scalar value.
:param target_collection: Name of the attribute we'll proxy to.
This attribute is typically mapped by
:func:`~sqlalchemy.orm.relationship` to link to a target collection, but
can also be a many-to-one or non-scalar relationship.
:param attr: Attribute on the associated instance or instances we'll
proxy for.
For example, given a target collection of [obj1, obj2], a list created
by this proxy property would look like [getattr(obj1, *attr*),
getattr(obj2, *attr*)]
If the relationship is one-to-one or otherwise uselist=False, then
simply: getattr(obj, *attr*)
:param creator: optional.
When new items are added to this proxied collection, new instances of
the class collected by the target collection will be created. For list
and set collections, the target class constructor will be called with
the 'value' for the new instance. For dict types, two arguments are
passed: key and value.
If you want to construct instances differently, supply a *creator*
function that takes arguments as above and returns instances.
For scalar relationships, creator() will be called if the target is None.
If the target is present, set operations are proxied to setattr() on the
associated object.
If you have an associated object with multiple attributes, you may set
up multiple association proxies mapping to different attributes. See
the unit tests for examples, and for examples of how creator() functions
can be used to construct the scalar relationship on-demand in this
situation.
:param \*\*kw: Passes along any other keyword arguments to
:class:`.AssociationProxy`.
( t AssociationProxy( t target_collectiont attrt kw( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt association_proxy s 4t ASSOCIATION_PROXYR c B s e Z d Z e Z e Z d
d
d
d
d
e d Z d Z
d Z d Z d
d Z
d Z d Z d Z d Z RS( sD A descriptor that presents a read/write view of an object attribute.c C sz | | _ | | _ | | _ | | _ | | _ | | _ | | _ d t | j | t | f | _
| rv | | _ n d S( s Construct a new :class:`.AssociationProxy`.
The :func:`.association_proxy` function is provided as the usual
entrypoint here, though :class:`.AssociationProxy` can be instantiated
and/or subclassed directly.
:param target_collection: Name of the collection we'll proxy to,
usually created with :func:`.relationship`.
:param attr: Attribute on the collected instances we'll proxy
for. For example, given a target collection of [obj1, obj2], a
list created by this proxy property would look like
[getattr(obj1, attr), getattr(obj2, attr)]
:param creator: Optional. When new items are added to this proxied
collection, new instances of the class collected by the target
collection will be created. For list and set collections, the
target class constructor will be called with the 'value' for the
new instance. For dict types, two arguments are passed:
key and value.
If you want to construct instances differently, supply a 'creator'
function that takes arguments as above and returns instances.
:param cascade_scalar_deletes: when True, indicates that setting
the proxied value to ``None``, or deleting it via ``del``, should
also remove the source object. Only applies to scalar attributes.
Normally, removing the proxied target will not remove the proxy
source, as this object may have other state that is still to be
kept.
.. versionadded:: 1.3
.. seealso::
:ref:`cascade_scalar_deletes` - complete usage example
:param getset_factory: Optional. Proxied attribute access is
automatically handled by routines that get and set values based on
the `attr` argument for this proxy.
If you would like to customize this behavior, you may supply a
`getset_factory` callable that produces a tuple of `getter` and
`setter` functions. The factory is called with two arguments, the
abstract type of the underlying collection and this proxy instance.
:param proxy_factory: Optional. The type of collection to emulate is
determined by sniffing the target collection. If your collection
type can't be determined by duck typing or you'd like to use a
different collection implementation, you may supply a factory
function to produce those collections. Only applicable to
non-scalar relationships.
:param proxy_bulk_set: Optional, use with proxy_factory. See
the _set() method for details.
:param info: optional, will be assigned to
:attr:`.AssociationProxy.info` if present.
.. versionadded:: 1.0.9
s _%s_%s_%sN( R t
value_attrt creatort getset_factoryt
proxy_factoryt proxy_bulk_sett cascade_scalar_deletest typet __name__t idt keyt info( t selfR R
R R R R R R ( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt __init__c s I c C s9 | d k r | S| j | | } | r5 | j | S| S( N( t Nonet _as_instancet get( R t objt class_t inst( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt __get__ s
c C s( t | } | j | | j | | S( N( R R t set( R R t valuesR ( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt __set__ s c C s% t | } | j | | j | S( N( R R t delete( R R R ( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt
__delete__ s c C s | j | | S( s Return the internal state local to a specific mapped class.
E.g., given a class ``User``::
class User(Base):
# ...
keywords = association_proxy('kws', 'keyword')
If we access this :class:`.AssociationProxy` from
:attr:`.Mapper.all_orm_descriptors`, and we want to view the
target class for this proxy as mapped by ``User``::
inspect(User).all_orm_descriptors["keywords"].for_class(User).target_class
This returns an instance of :class:`.AssociationProxyInstance` that
is specific to the ``User`` class. The :class:`.AssociationProxy`
object remains agnostic of its parent class.
:param class\_: the class that we are returning state for.
:param obj: optional, an instance of the class that is required
if the attribute refers to a polymorphic target, e.g. where we have
to look at the type of the actual destination object to get the
complete path.
.. versionadded:: 1.3 - :class:`.AssociationProxy` no longer stores
any state specific to a particular parent class; the state is now
stored in per-class :class:`.AssociationProxyInstance` objects.
( R ( R R R ( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt for_class s !c C s y | j | j d } Wna t k
r{ | j | } | d k rr t j | | | } t | | j d | q| d } n X| d k r | j r | j | S| Sd S( Nt _inst(
t __dict__R t KeyErrort _calc_ownerR t AssociationProxyInstancet for_proxyt setattrt
_is_canonicalt _non_canonical_get_for_object( R R R R t owner( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyR s
c C s9 y t | } Wn t j k
r' d SX| j j j Sd S( N( R R t NoInspectionAvailableR t mappert
class_managerR ( R t
target_clst insp( ( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyR+ s
c s^ | j t j f d } | t k rE f d } n f d } | | f S( Nc s | d k r | Sd S( N( R ( t target( t _getter( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt getter s c s t | | d S( N( R. ( t ot kt v( R
( sR /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/associationproxy.pyt setter s c s t | | d S( N( R. ( R: R<