当前位置: 首页>>代码示例>>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;未经允许,请勿转载。