Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
ó
‹EYc	@sÃdZddlmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZmZddlmZddlmZd	d
lZddlmZmZmZmZdd
lmZd„Zd„Zde fd„ƒYZ!e"d„Z#d„Z$de	j%e&fd„ƒYZ'de'fd„ƒYZ(d
d
d
e*ded
e!d„Z+d„Z,de*fd„ƒYZ-de-fd„ƒYZ.de*fd „ƒYZ/d
S(!s1Public API functions and helpers for declarative.i(tTabletMetaDatatColumn(tsynonymtcomparable_propertyt
interfacest
propertiest
attributes(tpolymorphic_union(t_mapper_or_none(tOrderedDictthybridmethodthybridproperty(tutil(texciÿÿÿÿNi(t_as_declarativet_declarative_constructort_DeferredMapperConfigt_add_attribute(t_class_resolvercCsQd|jkr%tjd|ƒ‚n||_||_t||j|jƒdS(s‹Given a class, configure the class declaratively,
    using the given registry, which can be any dictionary, and
    MetaData object.

    t_decl_class_registrys4Class %r already has been instrumented declarativelyN(t__dict__RtInvalidRequestErrorRtmetadataRt__name__(tclstregistryR((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytinstrument_declaratives
		cCs8x1|jdD]"}t|ddƒdk	rtSqWtS(sKGiven a class, return True if any of the classes it inherits from has a
    mapped table, otherwise return False.

    This is used in declarative mixins to build attributes that behave
    differently for the base class vs. a subclass in an inheritance
    hierarchy.

    .. seealso::

        :ref:`decl_mixin_inheritance`

    it	__table__N(t__mro__tgetattrtNonetTruetFalse(Rtclass_((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pythas_inherited_table*s
tDeclarativeMetacBseZd„Zd„ZRS(cCs?d|jkr%t|||jƒntj||||ƒdS(NR(RRttypet__init__(Rt	classnametbasestdict_((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR&>scCst|||ƒdS(N(R(Rtkeytvalue((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt__setattr__Cs(Rt
__module__R&R,(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR$=s	cs‡‡fd†}|S(s&Decorator, make a Python @property a query synonym for a column.

    A decorator version of :func:`~sqlalchemy.orm.synonym`. The function being
    decorated is the 'descriptor', otherwise passes its arguments through to
    synonym()::

      @synonym_for('col')
      @property
      def prop(self):
          return 'special sauce'

    The regular ``synonym()`` is also usable directly in a declarative setting
    and may be convenient for read/write properties::

      prop = synonym('col', descriptor=property(_read_prop, _write_prop))

    cstˆdˆd|ƒS(Nt
map_columnt
descriptor(t_orm_synonym(tfn(R.tname(sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytdecorateYs((R2R.R3((R.R2sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytsynonym_forGscs‡fd†}|S(s(Decorator, allow a Python @property to be used in query criteria.

    This is a  decorator front end to
    :func:`~sqlalchemy.orm.comparable_property` that passes
    through the comparator_factory and the function being decorated::

      @comparable_using(MyComparatorType)
      @property
      def prop(self):
          return 'special sauce'

    The regular ``comparable_property()`` is also usable directly in a
    declarative setting and may be convenient for read/write properties::

      prop = comparable_property(MyComparatorType)

    cs
tˆ|ƒS(N(R(R1(tcomparator_factory(sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR3ps((R5R3((R5sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytcomparable_using^st
declared_attrcBsAeZdZed„Zd„Zed„ƒZed„ƒZ	RS(sJMark a class-level method as representing the definition of
    a mapped property or special declarative member name.

    @declared_attr turns the attribute into a scalar-like
    property that can be invoked from the uninstantiated class.
    Declarative treats attributes specifically marked with
    @declared_attr as returning a construct that is specific
    to mapping or declarative table configuration.  The name
    of the attribute is that of what the non-dynamic version
    of the attribute would be.

    @declared_attr is more often than not applicable to mixins,
    to define relationships that are to be applied to different
    implementors of the class::

        class ProvidesUser(object):
            "A mixin that adds a 'user' relationship to classes."

            @declared_attr
            def user(self):
                return relationship("User")

    It also can be applied to mapped classes, such as to provide
    a "polymorphic" scheme for inheritance::

        class Employee(Base):
            id = Column(Integer, primary_key=True)
            type = Column(String(50), nullable=False)

            @declared_attr
            def __tablename__(cls):
                return cls.__name__.lower()

            @declared_attr
            def __mapper_args__(cls):
                if cls.__name__ == 'Employee':
                    return {
                            "polymorphic_on":cls.type,
                            "polymorphic_identity":"Employee"
                    }
                else:
                    return {"polymorphic_identity":cls.__name__}

    .. versionchanged:: 0.8 :class:`.declared_attr` can be used with
       non-ORM or extension attributes, such as user-defined attributes
       or :func:`.association_proxy` objects, which will be assigned
       to the class at class construction time.


    cCs/tt|ƒj|ƒ|j|_||_dS(N(tsuperR7R&t__doc__t
_cascading(tselftfgett	cascading((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR&©scCsŸ|jjddƒ}|dkrltj|ƒ}|dkr_tjd|jj|jfƒn|j|ƒS||kr€||S|j|ƒ||<}|SdS(Nt_sa_declared_attr_regsEUnmanaged access of declarative attribute %s from non-mapped class %s(	RtgetRRtmanager_of_classR
twarnR<R(tdescR;Rtregtmanagertobj((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt__get__®s
cKs
t|S(N(t_stateful_declared_attr(Rtkw((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt	_stateful¾scCs|jdtƒS(sÌMark a :class:`.declared_attr` as cascading.

        This is a special-use modifier which indicates that a column
        or MapperProperty-based declared attribute should be configured
        distinctly per mapped subclass, within a mapped-inheritance scenario.

        Below, both MyClass as well as MySubClass will have a distinct
        ``id`` Column object established::

            class HasIdMixin(object):
                @declared_attr.cascading
                def id(cls):
                    if has_inherited_table(cls):
                        return Column(ForeignKey('myclass.id'), primary_key=True)
                    else:
                        return Column(Integer, primary_key=True)

            class MyClass(HasIdMixin, Base):
                __tablename__ = 'myclass'
                # ...

            class MySubClass(MyClass):
                ""
                # ...

        The behavior of the above configuration is that ``MySubClass``
        will refer to both its own ``id`` column as well as that of
        ``MyClass`` underneath the attribute named ``some_id``.

        .. seealso::

            :ref:`declarative_inheritance`

            :ref:`mixin_inheritance_columns`


        R=(RIR (R((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR=Âs'(
RR-R9R!R&RFRRIRR=(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR7us
2	RGcBs#eZd„Zd„Zd„ZRS(cKs
||_dS(N(RH(R;RH((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR&íscKs&|jjƒ}|j|ƒt|S(N(RHtcopytupdateRG(R;RHtnew_kw((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyRIðs
cCst||jS(N(R7RH(R;R1((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt__call__õs(RR-R&RIRM(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyRGìs		tBasecCs¦|ptƒ}|r!||_n|dkr<tjƒ}nt|tƒrU|fpX|}	td|d|ƒ}
|rƒ||
d<n|r–||
d<n|||	|
ƒS(sœ	Construct a base class for declarative class definitions.

    The new base class will be given a metaclass that produces
    appropriate :class:`~sqlalchemy.schema.Table` objects and makes
    the appropriate :func:`~sqlalchemy.orm.mapper` calls based on the
    information provided declaratively in the class and any subclasses
    of the class.

    :param bind: An optional
      :class:`~sqlalchemy.engine.Connectable`, will be assigned
      the ``bind`` attribute on the :class:`~sqlalchemy.schema.MetaData`
      instance.

    :param metadata:
      An optional :class:`~sqlalchemy.schema.MetaData` instance.  All
      :class:`~sqlalchemy.schema.Table` objects implicitly declared by
      subclasses of the base will share this MetaData.  A MetaData instance
      will be created if none is provided.  The
      :class:`~sqlalchemy.schema.MetaData` instance will be available via the
      `metadata` attribute of the generated declarative base class.

    :param mapper:
      An optional callable, defaults to :func:`~sqlalchemy.orm.mapper`. Will
      be used to map subclasses to their Tables.

    :param cls:
      Defaults to :class:`object`. A type to use as the base for the generated
      declarative base class. May be a class or tuple of classes.

    :param name:
      Defaults to ``Base``.  The display name for the generated
      class.  Customizing this is not required, but can improve clarity in
      tracebacks and debugging.

    :param constructor:
      Defaults to
      :func:`~sqlalchemy.ext.declarative.base._declarative_constructor`, an
      __init__ implementation that assigns \**kwargs for declared
      fields and relationships to an instance.  If ``None`` is supplied,
      no __init__ will be provided and construction will fall back to
      cls.__init__ by way of the normal Python semantics.

    :param class_registry: optional dictionary that will serve as the
      registry of class names-> mapped classes when string names
      are used to identify classes inside of :func:`.relationship`
      and others.  Allows two or more declarative base classes
      to share the same registry of class names for simplified
      inter-base relationships.

    :param metaclass:
      Defaults to :class:`.DeclarativeMeta`.  A metaclass or __metaclass__
      compatible callable to use as the meta type of the generated
      declarative base class.

    .. seealso::

        :func:`.as_declarative`

    RRR&t__mapper_cls__N(RtbindRtweakreftWeakValueDictionaryt
isinstancettupletdict(RPRtmapperRR2tconstructortclass_registryt	metaclasstlcl_metadataR(t
class_dict((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytdeclarative_baseùs?	

cs‡fd†}|S(sø
    Class decorator for :func:`.declarative_base`.

    Provides a syntactical shortcut to the ``cls`` argument
    sent to :func:`.declarative_base`, allowing the base class
    to be converted in-place to a "declarative" base::

        from sqlalchemy.ext.declarative import as_declarative

        @as_declarative()
        class Base(object):
            @declared_attr
            def __tablename__(cls):
                return cls.__name__.lower()
            id = Column(Integer, primary_key=True)

        class MyMappedClass(Base):
            # ...

    All keyword arguments passed to :func:`.as_declarative` are passed
    along to :func:`.declarative_base`.

    .. versionadded:: 0.8.3

    .. seealso::

        :func:`.declarative_base`

    cs!|ˆd<|jˆd<tˆS(NRR2(RR\(R(RH(sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR3is

((RHR3((RHsS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytas_declarativeKstConcreteBasecBs,eZdZed„ƒZed„ƒZRS(soA helper class for 'concrete' declarative mappings.

    :class:`.ConcreteBase` will use the :func:`.polymorphic_union`
    function automatically, against all tables mapped as a subclass
    to this class.   The function is called via the
    ``__declare_last__()`` function, which is essentially
    a hook for the :meth:`.after_configured` event.

    :class:`.ConcreteBase` produces a mapped
    table for the class itself.  Compare to :class:`.AbstractConcreteBase`,
    which does not.

    Example::

        from sqlalchemy.ext.declarative import ConcreteBase

        class Employee(ConcreteBase, Base):
            __tablename__ = 'employee'
            employee_id = Column(Integer, primary_key=True)
            name = Column(String(50))
            __mapper_args__ = {
                            'polymorphic_identity':'employee',
                            'concrete':True}

        class Manager(Employee):
            __tablename__ = 'manager'
            employee_id = Column(Integer, primary_key=True)
            name = Column(String(50))
            manager_data = Column(String(40))
            __mapper_args__ = {
                            'polymorphic_identity':'manager',
                            'concrete':True}

    .. seealso::

        :class:`.AbstractConcreteBase`

        :ref:`concrete_inheritance`

        :ref:`inheritance_concrete_helpers`


    cCs ttd„|DƒƒddƒS(Ncss!|]}|j|jfVqdS(N(tpolymorphic_identitytlocal_table(t.0tmp((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pys	<genexpr>¡sR%tpjoin(RR
(Rtmappers((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt_create_polymorphic_unionžs
cCs^|j}|jrdSt|jƒ}|j|ƒ}|jd|fƒ|j|jjƒdS(Nt*(	t
__mapper__twith_polymorphictlisttself_and_descendantsRet_set_with_polymorphict_set_polymorphic_ontcR%(RtmRdRc((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt__declare_first__¥s		(RR-R9tclassmethodReRo(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR^qs+tAbstractConcreteBasecBs2eZdZeZed„ƒZed„ƒZRS(sòA helper class for 'concrete' declarative mappings.

    :class:`.AbstractConcreteBase` will use the :func:`.polymorphic_union`
    function automatically, against all tables mapped as a subclass
    to this class.   The function is called via the
    ``__declare_last__()`` function, which is essentially
    a hook for the :meth:`.after_configured` event.

    :class:`.AbstractConcreteBase` does produce a mapped class
    for the base class, however it is not persisted to any table; it
    is instead mapped directly to the "polymorphic" selectable directly
    and is only used for selecting.  Compare to :class:`.ConcreteBase`,
    which does create a persisted table for the base class.

    Example::

        from sqlalchemy.ext.declarative import AbstractConcreteBase

        class Employee(AbstractConcreteBase, Base):
            pass

        class Manager(Employee):
            __tablename__ = 'manager'
            employee_id = Column(Integer, primary_key=True)
            name = Column(String(50))
            manager_data = Column(String(40))

            __mapper_args__ = {
                'polymorphic_identity':'manager',
                'concrete':True}

    The abstract base class is handled by declarative in a special way;
    at class configuration time, it behaves like a declarative mixin
    or an ``__abstract__`` base class.   Once classes are configured
    and mappings are produced, it then gets mapped itself, but
    after all of its decscendants.  This is a very unique system of mapping
    not found in any other SQLAlchemy system.

    Using this approach, we can specify columns and properties
    that will take place on mapped subclasses, in the way that
    we normally do as in :ref:`declarative_mixins`::

        class Company(Base):
            __tablename__ = 'company'
            id = Column(Integer, primary_key=True)

        class Employee(AbstractConcreteBase, Base):
            employee_id = Column(Integer, primary_key=True)

            @declared_attr
            def company_id(cls):
                return Column(ForeignKey('company.id'))

            @declared_attr
            def company(cls):
                return relationship("Company")

        class Manager(Employee):
            __tablename__ = 'manager'

            name = Column(String(50))
            manager_data = Column(String(40))

            __mapper_args__ = {
                'polymorphic_identity':'manager',
                'concrete':True}

    When we make use of our mappings however, both ``Manager`` and
    ``Employee`` will have an independently usable ``.company`` attribute::

        session.query(Employee).filter(Employee.company.has(id=5))

    .. versionchanged:: 1.0.0 - The mechanics of :class:`.AbstractConcreteBase`
       have been reworked to support relationships established directly
       on the abstract base, without any special configurational steps.

    .. seealso::

        :class:`.ConcreteBase`

        :ref:`concrete_inheritance`

        :ref:`inheritance_concrete_helpers`

    cCs|jƒdS(N(t_sa_decl_prepare_nocascade(R((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyRo
sc
st|ddƒrdStj|ƒ}g}t|jƒƒ}xQ|r|jƒ}|j|jƒƒt|ƒ}|dk	r@|j	|ƒq@q@W|j
|ƒ‰t|jƒ}xIt|j
jƒƒD]2\}}||krňj|j|j
|<qÅqÅWˆ|_|jpt‰‡‡fd†}	|	|_|jƒ}
xN|jƒD]@}t|ƒ}|rG|jrG||jkrG|j|
ƒqGqGWdS(NRgcsˆƒ}ˆjj|d<|S(Ntpolymorphic_on(RmR%(targs(tm_argsRc(sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytmapper_args2s	(RRRtconfig_for_clsRit__subclasses__tpoptextendR	tappendRetsettdeclared_columnsRtitemsRmR*R`tmapper_args_fnRUtmaptconcretet	__bases__t_set_concrete_base(
Rtto_mapRdtstacktklasstmnt
declared_colstktvRvRntsclstsm((RuRcsS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyRrs2	"		(RR-R9R t__no_table__RpRoRr(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyRq±sUtDeferredReflectioncBsJeZdZed„ƒZed„ƒZed„ƒZed„ƒZRS(s¯	A helper class for construction of mappings based on
    a deferred reflection step.

    Normally, declarative can be used with reflection by
    setting a :class:`.Table` object using autoload=True
    as the ``__table__`` attribute on a declarative class.
    The caveat is that the :class:`.Table` must be fully
    reflected, or at the very least have a primary key column,
    at the point at which a normal declarative mapping is
    constructed, meaning the :class:`.Engine` must be available
    at class declaration time.

    The :class:`.DeferredReflection` mixin moves the construction
    of mappers to be at a later point, after a specific
    method is called which first reflects all :class:`.Table`
    objects created so far.   Classes can define it as such::

        from sqlalchemy.ext.declarative import declarative_base
        from sqlalchemy.ext.declarative import DeferredReflection
        Base = declarative_base()

        class MyClass(DeferredReflection, Base):
            __tablename__ = 'mytable'

    Above, ``MyClass`` is not yet mapped.   After a series of
    classes have been defined in the above fashion, all tables
    can be reflected and mappings created using
    :meth:`.prepare`::

        engine = create_engine("someengine://...")
        DeferredReflection.prepare(engine)

    The :class:`.DeferredReflection` mixin can be applied to individual
    classes, used as the base for the declarative base itself,
    or used in a custom abstract class.   Using an abstract base
    allows that only a subset of classes to be prepared for a
    particular prepare step, which is necessary for applications
    that use more than one engine.  For example, if an application
    has two engines, you might use two bases, and prepare each
    separately, e.g.::

        class ReflectedOne(DeferredReflection, Base):
            __abstract__ = True

        class ReflectedTwo(DeferredReflection, Base):
            __abstract__ = True

        class MyClass(ReflectedOne):
            __tablename__ = 'mytable'

        class MyOtherClass(ReflectedOne):
            __tablename__ = 'myothertable'

        class YetAnotherClass(ReflectedTwo):
            __tablename__ = 'yetanothertable'

        # ... etc.

    Above, the class hierarchies for ``ReflectedOne`` and
    ``ReflectedTwo`` can be configured separately::

        ReflectedOne.prepare(engine_one)
        ReflectedTwo.prepare(engine_two)

    .. versionadded:: 0.8

    cCsõtj|ƒ}xß|D]×}|j|j|ƒ|jƒ|jj}|jj}x™|j	j
ƒD]ˆ}t|tj
ƒra|jdk	rat|jtƒr°|j|j|ƒqét|jtƒré|jj|j||ƒf7_qéqaqaWqWdS(scReflect all :class:`.Table` objects for all current
        :class:`.DeferredReflection` subclassesN(Rtclasses_for_baset_sa_decl_prepareR`R€RRgR"Rt_propstvaluesRSRtRelationshipPropertyt	secondaryRRt_reflect_tableRt
_resolverst_sa_deferred_table_resolver(RtengineR„tthingyRVRtrel((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pytprepare„s


cs‡‡‡fd†}|S(Ncs#t|ˆƒ}ˆj|ˆƒ|S(N(RR•(R*tt1(RR˜R(sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt_resolve›s((RR˜RR((RR˜RsS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR—™scCs#|dk	r|j||ƒndS(N(RR•(RR`R˜((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR¡sc
Cs8t|j|jdtdtdtd|d|jƒdS(Ntextend_existingtautoload_replacetautoloadt
autoload_withtschema(RR2RR R!R¢(RttableR˜((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyR•ªs		(RR-R9RpR›R—RR•(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyRŽ@s
C	(0R9R¢RRRtormRR0RRRRtorm.utilRtorm.baseR	R
R
RRtRRQtbaseRRRRtclsregistryRRR#R%R$R!R4R6t_MappedAttributetpropertyR7RGRtobjectR\R]R^RqRŽ(((sS/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyt<module>s2("		
	w
O	&@