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


Python Mutable.coerce方法代碼示例

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


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

示例1: coerce

# 需要導入模塊: from sqlalchemy.ext.mutable import Mutable [as 別名]
# 或者: from sqlalchemy.ext.mutable.Mutable import coerce [as 別名]
def coerce(cls, key, value):
        """Given a value, coerce it into the target type.

        Can be overridden by custom subclasses to coerce incoming
        data into a particular type.

        By default, raises ``ValueError``.

        This method is called in different scenarios depending on if
        the parent class is of type :class:`.Mutable` or of type
        :class:`.MutableComposite`.  In the case of the former, it is called
        for both attribute-set operations as well as during ORM loading
        operations.  For the latter, it is only called during attribute-set
        operations; the mechanics of the :func:`.composite` construct
        handle coercion during load operations.


        :param key: string name of the ORM-mapped attribute being set.
        :param value: the incoming value.
        :return: the method should return the coerced value, or raise
         ``ValueError`` if the coercion cannot be completed.

        """
        if value is None:
            return None
        msg = "Attribute '%s' does not accept objects of type %s"
        raise ValueError(msg % (key, type(value))) 
開發者ID:jpush,項目名稱:jbox,代碼行數:29,代碼來源:mutable.py

示例2: coerce

# 需要導入模塊: from sqlalchemy.ext.mutable import Mutable [as 別名]
# 或者: from sqlalchemy.ext.mutable.Mutable import coerce [as 別名]
def coerce(cls, key, value):
        "Convert plain dictionaries to MutableDict."
        if not isinstance(value, MutableDict):
            if isinstance(value, dict):
                return MutableDict(value)

            # this call will raise ValueError
            return Mutable.coerce(key, value)

        return value 
開發者ID:getsentry,項目名稱:freight,代碼行數:12,代碼來源:json.py

示例3: coerce

# 需要導入模塊: from sqlalchemy.ext.mutable import Mutable [as 別名]
# 或者: from sqlalchemy.ext.mutable.Mutable import coerce [as 別名]
def coerce(cls, index, value):
            """Convert plain list to instance of this class."""
            if not isinstance(value, cls):
                if isinstance(value, list):
                    return cls(value)
                return Mutable.coerce(index, value)
            else:
                return value 
開發者ID:cmdmnt,項目名稱:commandment,代碼行數:10,代碼來源:mutablelist.py

示例4: coerce

# 需要導入模塊: from sqlalchemy.ext.mutable import Mutable [as 別名]
# 或者: from sqlalchemy.ext.mutable.Mutable import coerce [as 別名]
def coerce(cls, key, value):
        "Convert plain dictionaries to MutableDict."
        if not isinstance(value, MutableDict):
            if isinstance(value, dict):
                return MutableDict(value)

            # this call will raise ValueError
            return Mutable.coerce(key, value)

        else:
            return value 
開發者ID:getsentry,項目名稱:zeus,代碼行數:13,代碼來源:json.py


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