當前位置: 首頁>>代碼示例>>Python>>正文


Python collection.remover方法代碼示例

本文整理匯總了Python中sqlalchemy.orm.collections.collection.remover方法的典型用法代碼示例。如果您正苦於以下問題:Python collection.remover方法的具體用法?Python collection.remover怎麽用?Python collection.remover使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.orm.collections.collection的用法示例。


在下文中一共展示了collection.remover方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: remover

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def remover(fn):
        """Tag the method as the collection remover.

        The remover method is called with one positional argument: the value
        to remove. The method will be automatically decorated with
        :meth:`removes_return` if not already decorated::

            @collection.remover
            def zap(self, entity): ...

            # or, equivalently
            @collection.remover
            @collection.removes_return()
            def zap(self, ): ...

        If the value to remove is not present in the collection, you may
        raise an exception or return None to ignore the error.

        If the remove method is internally instrumented, you must also
        receive the keyword argument '_sa_initiator' and ensure its
        promulgation to collection events.

        """
        fn._sa_instrument_role = 'remover'
        return fn 
開發者ID:jpush,項目名稱:jbox,代碼行數:27,代碼來源:collections.py

示例2: _assert_required_roles

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def _assert_required_roles(cls, roles, methods):
    """ensure all roles are present, and apply implicit instrumentation if
    needed

    """
    if 'appender' not in roles or not hasattr(cls, roles['appender']):
        raise sa_exc.ArgumentError(
            "Type %s must elect an appender method to be "
            "a collection class" % cls.__name__)
    elif (roles['appender'] not in methods and
          not hasattr(getattr(cls, roles['appender']), '_sa_instrumented')):
        methods[roles['appender']] = ('fire_append_event', 1, None)

    if 'remover' not in roles or not hasattr(cls, roles['remover']):
        raise sa_exc.ArgumentError(
            "Type %s must elect a remover method to be "
            "a collection class" % cls.__name__)
    elif (roles['remover'] not in methods and
          not hasattr(getattr(cls, roles['remover']), '_sa_instrumented')):
        methods[roles['remover']] = ('fire_remove_event', 1, None)

    if 'iterator' not in roles or not hasattr(cls, roles['iterator']):
        raise sa_exc.ArgumentError(
            "Type %s must elect an iterator method to be "
            "a collection class" % cls.__name__) 
開發者ID:eirannejad,項目名稱:pyRevit,代碼行數:27,代碼來源:collections.py

示例3: remover

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def remover(fn):
        """Tag the method as the collection remover.

        The remover method is called with one positional argument: the value
        to remove. The method will be automatically decorated with
        :meth:`removes_return` if not already decorated::

            @collection.remover
            def zap(self, entity): ...

            # or, equivalently
            @collection.remover
            @collection.removes_return()
            def zap(self, ): ...

        If the value to remove is not present in the collection, you may
        raise an exception or return None to ignore the error.

        If the remove method is internally instrumented, you must also
        receive the keyword argument '_sa_initiator' and ensure its
        promulgation to collection events.

        """
        fn._sa_instrument_role = "remover"
        return fn 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:27,代碼來源:collections.py

示例4: test_dict_subclass

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def test_dict_subclass(self):
        class MyDict(dict):
            @collection.appender
            @collection.internally_instrumented
            def set(self, item, _sa_initiator=None):
                self.__setitem__(item.a, item, _sa_initiator=_sa_initiator)

            @collection.remover
            @collection.internally_instrumented
            def _remove(self, item, _sa_initiator=None):
                self.__delitem__(item.a, _sa_initiator=_sa_initiator)

        self._test_adapter(
            MyDict, self.dictable_entity, to_set=lambda c: set(c.values())
        )
        self._test_dict(MyDict)
        self._test_dict_bulk(MyDict)
        self.assert_(getattr(MyDict, "_sa_instrumented") == id(MyDict)) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:20,代碼來源:test_collection.py

示例5: iterator

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def iterator(fn):
        """Tag the method as the collection remover.

        The iterator method is called with no arguments.  It is expected to
        return an iterator over all collection members::

            @collection.iterator
            def __iter__(self): ...

        """
        fn._sa_instrument_role = 'iterator'
        return fn 
開發者ID:jpush,項目名稱:jbox,代碼行數:14,代碼來源:collections.py

示例6: clear_with_event

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def clear_with_event(self, initiator=None):
        """Empty the collection, firing a mutation event for each entity."""

        remover = self._data()._sa_remover
        for item in list(self):
            remover(item, _sa_initiator=initiator) 
開發者ID:jpush,項目名稱:jbox,代碼行數:8,代碼來源:collections.py

示例7: clear_without_event

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def clear_without_event(self):
        """Empty the collection, firing no events."""

        remover = self._data()._sa_remover
        for item in list(self):
            remover(item, _sa_initiator=False) 
開發者ID:jpush,項目名稱:jbox,代碼行數:8,代碼來源:collections.py

示例8: _locate_roles_and_methods

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def _locate_roles_and_methods(cls):
    """search for _sa_instrument_role-decorated methods in
    method resolution order, assign to roles.

    """

    roles = {}
    methods = {}

    for supercls in cls.__mro__:
        for name, method in vars(supercls).items():
            if not util.callable(method):
                continue

            # note role declarations
            if hasattr(method, '_sa_instrument_role'):
                role = method._sa_instrument_role
                assert role in ('appender', 'remover', 'iterator',
                                'linker', 'converter')
                roles.setdefault(role, name)

            # transfer instrumentation requests from decorated function
            # to the combined queue
            before, after = None, None
            if hasattr(method, '_sa_instrument_before'):
                op, argument = method._sa_instrument_before
                assert op in ('fire_append_event', 'fire_remove_event')
                before = op, argument
            if hasattr(method, '_sa_instrument_after'):
                op = method._sa_instrument_after
                assert op in ('fire_append_event', 'fire_remove_event')
                after = op
            if before:
                methods[name] = before + (after, )
            elif after:
                methods[name] = None, None, after
    return roles, methods 
開發者ID:jpush,項目名稱:jbox,代碼行數:39,代碼來源:collections.py

示例9: bulk_replace

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import remover [as 別名]
def bulk_replace(values, existing_adapter, new_adapter):
    """Load a new collection, firing events based on prior like membership.

    Appends instances in ``values`` onto the ``new_adapter``. Events will be
    fired for any instance not present in the ``existing_adapter``.  Any
    instances in ``existing_adapter`` not present in ``values`` will have
    remove events fired upon them.

    :param values: An iterable of collection member instances

    :param existing_adapter: A :class:`.CollectionAdapter` of
     instances to be replaced

    :param new_adapter: An empty :class:`.CollectionAdapter`
     to load with ``values``


    """

    assert isinstance(values, list)

    idset = util.IdentitySet
    existing_idset = idset(existing_adapter or ())
    constants = existing_idset.intersection(values or ())
    additions = idset(values or ()).difference(constants)
    removals = existing_idset.difference(constants)

    appender = new_adapter.bulk_appender()

    for member in values or ():
        if member in additions:
            appender(member)
        elif member in constants:
            appender(member, _sa_initiator=False)

    if existing_adapter:
        remover = existing_adapter.bulk_remover()
        for member in removals:
            remover(member) 
開發者ID:eirannejad,項目名稱:pyRevit,代碼行數:41,代碼來源:collections.py


注:本文中的sqlalchemy.orm.collections.collection.remover方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。