当前位置: 首页>>代码示例>>Python>>正文


Python attributes.manager_of_class函数代码示例

本文整理汇总了Python中sqlalchemy.orm.attributes.manager_of_class函数的典型用法代码示例。如果您正苦于以下问题:Python manager_of_class函数的具体用法?Python manager_of_class怎么用?Python manager_of_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了manager_of_class函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: replicate_attributes

def replicate_attributes(source, target, cache=None):
    '''Replicates common SQLAlchemy attributes from the `source` object to the
    `target` object.'''
    target_manager = manager_of_class(type(target))
    column_attrs = set()
    relationship_attrs = set()
    relationship_columns = set()
    for attr in manager_of_class(type(source)).attributes:
        if attr.key not in target_manager:
            # It's not common attribute
            continue
        target_attr = target_manager[attr.key]
        if isinstance(attr.property, ColumnProperty):
            assert isinstance(target_attr.property, ColumnProperty)
            column_attrs.add(attr)
        elif isinstance(attr.property, RelationshipProperty):
            assert isinstance(target_attr.property, RelationshipProperty)
            relationship_attrs.add(attr)
            if attr.property.direction is MANYTOONE:
                relationship_columns.update(attr.property.local_columns)
    for attr in column_attrs:
        if _column_property_in_registry(attr.property, _excluded):
            continue
        elif (not _column_property_in_registry(attr.property, _included) and
                 all(column in relationship_columns
                     for column in attr.property.columns)):
            continue
        setattr(target, attr.key, getattr(source, attr.key))
    for attr in relationship_attrs:
        target_attr_model = target_manager[attr.key].property.argument
        if not is_relation_replicatable(attr):
            continue
        replicate_relation(source, target, attr, target_manager[attr.key],
                           cache=cache)
开发者ID:Lehych,项目名称:iktomi,代码行数:34,代码来源:replication.py

示例2: test_uninstrument

    def test_uninstrument(self):
        class A(object):pass

        manager = attributes.register_class(A)

        assert attributes.manager_of_class(A) is manager
        attributes.unregister_class(A)
        assert attributes.manager_of_class(A) is None
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:8,代码来源:test_instrumentation.py

示例3: test_null_instrumentation

    def test_null_instrumentation(self):
        class Foo(MyBaseClass):
            pass
        attributes.register_class(Foo)
        attributes.register_attribute(Foo, "name", uselist=False, useobject=False)
        attributes.register_attribute(Foo, "bars", uselist=True, trackparent=True, useobject=True)

        assert Foo.name == attributes.manager_of_class(Foo)['name']
        assert Foo.bars == attributes.manager_of_class(Foo)['bars']
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_extendedattr.py

示例4: test_rebuild_state

    def test_rebuild_state(self):
        """not much of a 'test', but illustrate how to 
        remove instance-level state before pickling.
        
        """
        mapper(User, users)

        u1 = User()
        attributes.manager_of_class(User).teardown_instance(u1)
        assert not u1.__dict__
        u2 = pickle.loads(pickle.dumps(u1))
        attributes.manager_of_class(User).setup_instance(u2)
        assert attributes.instance_state(u2)
开发者ID:gajop,项目名称:springgrid,代码行数:13,代码来源:test_pickled.py

示例5: __new__

        def __new__(cls, schema, id_fields=None, **fields):
            if isinstance(schema, basestring):
                table = metadata.tables.get(schema, None)
                if table is None:
                    raise ValueError("%s is not defined in the metadata" % schema)
                managed_class = managed_class_of_table(table)
            elif isinstance(schema, Table):
                table = schema
                managed_class = managed_class_of_table(table)
            elif isinstance(schema, Mapper):
                table = schema.local_table
                managed_class = schema.class_
            else:
                manager = manager_of_class(schema)
                if manager is not None:
                    managed_class = manager
                    table = manager.mapper.local_table
                else:
                    raise TypeError("schema must be either a table name or a %s instance" % Table.__name__)

            if managed_class is not None:
                assert not issubclass(managed_class, DatumBase)
                _cls = lookup_mixin_class(managed_class)
            else:
                _cls = cls
            newinstance = object.__new__(_cls)
            newinstance._tableau_table = table
            return newinstance
开发者ID:moriyoshi,项目名称:tableau,代码行数:28,代码来源:sqla.py

示例6: _entity_descriptor

def _entity_descriptor(entity, key):
    """Return attribute/property information given an entity and string name.

    Returns a 2-tuple representing InstrumentedAttribute/MapperProperty.

    """
    if isinstance(entity, AliasedClass):
        try:
            desc = getattr(entity, key)
            return desc, desc.property
        except AttributeError:
            raise sa_exc.InvalidRequestError("Entity '%s' has no property '%s'" % (entity, key))
            
    elif isinstance(entity, type):
        try:
            desc = attributes.manager_of_class(entity)[key]
            return desc, desc.property
        except KeyError:
            raise sa_exc.InvalidRequestError("Entity '%s' has no property '%s'" % (entity, key))
            
    else:
        try:
            desc = entity.class_manager[key]
            return desc, desc.property
        except KeyError:
            raise sa_exc.InvalidRequestError("Entity '%s' has no property '%s'" % (entity, key))
开发者ID:clones,项目名称:sqlalchemy,代码行数:26,代码来源:util.py

示例7: test_nativeext_submanager

    def test_nativeext_submanager(self):
        class Mine(attributes.ClassManager): pass
        class A(object):
            __sa_instrumentation_manager__ = Mine

        attributes.register_class(A)
        eq_(type(attributes.manager_of_class(A)), Mine)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:7,代码来源:test_instrumentation.py

示例8: __build_operation_from_file

 def __build_operation_from_file(self, project, operation_file):
     """
     Create Operation entity from metadata file.
     """
     operation_dict = XMLReader(operation_file).read_metadata()
     operation_entity = manager_of_class(model.Operation).new_instance()
     return operation_entity.from_dict(operation_dict, dao, self.user_id, project.gid)
开发者ID:paolavals,项目名称:tvb-framework,代码行数:7,代码来源:import_service.py

示例9: __setstate__

    def __setstate__(self, state):
        self.obj = weakref.ref(state["instance"], self._cleanup)
        self.class_ = state["instance"].__class__
        self.manager = manager = manager_of_class(self.class_)
        if manager is None:
            raise orm_exc.UnmappedInstanceError(
                state["instance"],
                "Cannot deserialize object of type %r - no mapper() has"
                " been configured for this class within the current Python process!" % self.class_,
            )
        elif manager.mapper and not manager.mapper.compiled:
            manager.mapper.compile()

        self.committed_state = state.get("committed_state", {})
        self.pending = state.get("pending", {})
        self.parents = state.get("parents", {})
        self.modified = state.get("modified", False)
        self.expired = state.get("expired", False)
        self.callables = state.get("callables", {})

        if self.modified:
            self._strong_obj = state["instance"]

        self.__dict__.update([(k, state[k]) for k in ("key", "load_options", "mutable_dict") if k in state])

        if "load_path" in state:
            self.load_path = interfaces.deserialize_path(state["load_path"])
开发者ID:jsmiller84,项目名称:CouchPotato,代码行数:27,代码来源:state.py

示例10: _entity_info

def _entity_info(entity, compile=True):
    """Return mapping information given a class, mapper, or AliasedClass.

    Returns 3-tuple of: mapper, mapped selectable, boolean indicating if this
    is an aliased() construct.

    If the given entity is not a mapper, mapped class, or aliased construct,
    returns None, the entity, False.  This is typically used to allow
    unmapped selectables through.

    """
    if isinstance(entity, AliasedClass):
        return entity._AliasedClass__mapper, entity._AliasedClass__alias, True

    if isinstance(entity, mapperlib.Mapper):
        mapper = entity

    elif isinstance(entity, type):
        class_manager = attributes.manager_of_class(entity)

        if class_manager is None:
            return None, entity, False

        mapper = class_manager.mapper
    else:
        return None, entity, False

    if compile:
        mapper = mapper.compile()
    return mapper, mapper._with_polymorphic_selectable, False
开发者ID:AntonNguyen,项目名称:easy_api,代码行数:30,代码来源:util.py

示例11: __setstate__

    def __setstate__(self, state):
        self.obj = weakref.ref(state['instance'], self._cleanup)
        self.class_ = state['instance'].__class__
        self.manager = manager = manager_of_class(self.class_)
        if manager is None:
            raise orm_exc.UnmappedInstanceError(
                        state['instance'],
                        "Cannot deserialize object of type %r - no mapper() has"
                        " been configured for this class within the current Python process!" %
                        self.class_)
        elif manager.is_mapped and not manager.mapper.compiled:
            manager.mapper.compile()

        self.committed_state = state.get('committed_state', {})
        self.pending = state.get('pending', {})
        self.parents = state.get('parents', {})
        self.modified = state.get('modified', False)
        self.expired = state.get('expired', False)
        self.callables = state.get('callables', {})

        if self.modified:
            self._strong_obj = state['instance']

        self.__dict__.update([
            (k, state[k]) for k in (
                'key', 'load_options', 'mutable_dict'
            ) if k in state 
        ])

        if 'load_path' in state:
            self.load_path = interfaces.deserialize_path(state['load_path'])
开发者ID:BwRy,项目名称:rcs-db-ext,代码行数:31,代码来源:state.py

示例12: register

 def register(self, cls, canary):
     original_init = cls.__init__
     attributes.register_class(cls)
     ne_(cls.__init__, original_init)
     manager = attributes.manager_of_class(cls)
     def on_init(state, instance, args, kwargs):
         canary.append((cls, 'on_init', type(instance)))
     manager.events.add_listener('on_init', on_init)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:8,代码来源:test_instrumentation.py

示例13: test_customfinder_pass

    def test_customfinder_pass(self):
        class A(object): pass
        def find(cls):
            return None

        attributes.instrumentation_finders.insert(0, find)
        attributes.register_class(A)
        eq_(type(attributes.manager_of_class(A)), attributes.ClassManager)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:8,代码来源:test_instrumentation.py

示例14: test_collectionclasses

    def test_collectionclasses(self):

        class Foo(object):pass
        attributes.register_class(Foo)

        attributes.register_attribute(Foo, "collection", uselist=True, typecallable=set, useobject=True)
        assert attributes.manager_of_class(Foo).is_instrumented("collection")
        assert isinstance(Foo().collection, set)

        attributes.unregister_attribute(Foo, "collection")
        assert not attributes.manager_of_class(Foo).is_instrumented("collection")
        
        try:
            attributes.register_attribute(Foo, "collection", uselist=True, typecallable=dict, useobject=True)
            assert False
        except sa_exc.ArgumentError, e:
            assert str(e) == "Type InstrumentedDict must elect an appender method to be a collection class"
开发者ID:jrus,项目名称:sqlalchemy,代码行数:17,代码来源:attributes.py

示例15: _is_mapped_class

def _is_mapped_class(cls):
    from sqlalchemy.orm import mapperlib as mapper
    if isinstance(cls, (AliasedClass, mapper.Mapper)):
        return True
    if isinstance(cls, expression.ClauseElement):
        return False
    manager = attributes.manager_of_class(cls)
    return manager and _INSTRUMENTOR in manager.info
开发者ID:AntonNguyen,项目名称:easy_api,代码行数:8,代码来源:util.py


注:本文中的sqlalchemy.orm.attributes.manager_of_class函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。