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


Python collection.internally_instrumented方法代碼示例

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


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

示例1: internally_instrumented

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

        This tag will prevent any decoration from being applied to the
        method. Use this if you are orchestrating your own calls to
        :func:`.collection_adapter` in one of the basic SQLAlchemy
        interface methods, or to prevent an automatic ABC method
        decoration from wrapping your implementation::

            # normally an 'extend' method on a list-like class would be
            # automatically intercepted and re-implemented in terms of
            # SQLAlchemy events and append().  your implementation will
            # never be called, unless:
            @collection.internally_instrumented
            def extend(self, items): ...

        """
        fn._sa_instrumented = True
        return fn 
開發者ID:jpush,項目名稱:jbox,代碼行數:21,代碼來源:collections.py

示例2: remove

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import internally_instrumented [as 別名]
def remove(self, value, _sa_initiator=None):
        """Remove an item by value, consulting the keyfunc for the key."""

        key = self.keyfunc(value)
        # Let self[key] raise if key is not in this collection
        # testlib.pragma exempt:__ne__
        if self[key] != value:
            raise sa_exc.InvalidRequestError(
                "Can not remove '%s': collection holds '%s' for key '%s'. "
                "Possible cause: is the MappedCollection key function "
                "based on mutable properties or properties that only obtain "
                "values after flush?" % (value, self[key], key)
            )
        self.__delitem__(key, _sa_initiator)


# ensure instrumentation is associated with
# these built-in classes; if a user-defined class
# subclasses these and uses @internally_instrumented,
# the superclass is otherwise not instrumented.
# see [ticket:2406]. 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:23,代碼來源:collections.py

示例3: test_dict_subclass

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import internally_instrumented [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

示例4: _convert

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import internally_instrumented [as 別名]
def _convert(self, dictlike):
        """Validate and convert a dict-like object into values for set()ing.

        This is called behind the scenes when a MappedCollection is replaced
        entirely by another collection, as in::

          myobj.mappedcollection = {'a':obj1, 'b': obj2} # ...

        Raises a TypeError if the key in any (key, value) pair in the dictlike
        object does not match the key that this collection's keyfunc would
        have assigned for that value.

        """
        for incoming_key, value in util.dictlike_iteritems(dictlike):
            new_key = self.keyfunc(value)
            if incoming_key != new_key:
                raise TypeError(
                    "Found incompatible key %r for value %r; this "
                    "collection's "
                    "keying function requires a key of %r for this value." % (
                        incoming_key, value, new_key))
            yield value

# ensure instrumentation is associated with
# these built-in classes; if a user-defined class
# subclasses these and uses @internally_instrumented,
# the superclass is otherwise not instrumented.
# see [ticket:2406]. 
開發者ID:jpush,項目名稱:jbox,代碼行數:30,代碼來源:collections.py

示例5: _convert

# 需要導入模塊: from sqlalchemy.orm.collections import collection [as 別名]
# 或者: from sqlalchemy.orm.collections.collection import internally_instrumented [as 別名]
def _convert(self, dictlike):
        """Validate and convert a dict-like object into values for set()ing.

        This is called behind the scenes when a MappedCollection is replaced
        entirely by another collection, as in::

          myobj.mappedcollection = {'a':obj1, 'b': obj2} # ...

        Raises a TypeError if the key in any (key, value) pair in the dictlike
        object does not match the key that this collection's keyfunc would
        have assigned for that value.

        """
        for incoming_key, value in util.dictlike_iteritems(dictlike):
            new_key = self.keyfunc(value)
            if incoming_key != new_key:
                raise TypeError(
                    "Found incompatible key %r for value %r; this "
                    "collection's "
                    "keying function requires a key of %r for this value." % (
                    incoming_key, value, new_key))
            yield value

# ensure instrumentation is associated with
# these built-in classes; if a user-defined class
# subclasses these and uses @internally_instrumented,
# the superclass is otherwise not instrumented.
# see [ticket:2406]. 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:30,代碼來源:collections.py


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