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


Python exceptions.ConversionError方法代码示例

本文整理汇总了Python中schematics.exceptions.ConversionError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ConversionError方法的具体用法?Python exceptions.ConversionError怎么用?Python exceptions.ConversionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schematics.exceptions的用法示例。


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

示例1: monkeypatch_listtype

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def monkeypatch_listtype():
    """
    Replace ListType list conversion method to avoid errors
    """
    from schematics.transforms import EMPTY_LIST
    from schematics.types.compound import ListType
    from schematics.exceptions import ConversionError

    def _force_list(self, value):
        if value is None or value == EMPTY_LIST:
            return []
        try:
            return list(value)
        except Exception as e:
            raise ConversionError("Invalid list")

    ListType._force_list = _force_list


# Apply monkeypatches 
开发者ID:scrapinghub,项目名称:spidermon,代码行数:22,代码来源:monkeypatches.py

示例2: to_native

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def to_native(self, value, context=None):
        value = super(HashType, self).to_native(value, context)

        if ':' not in value:
            raise ValidationError(self.messages['hash_invalid'])

        hash_type, hash_value = value.split(':', 1)

        if hash_type not in algorithms:
            raise ValidationError(self.messages['hash_invalid'])

        if len(hash_value) != hash_new(hash_type).digest_size * 2:
            raise ValidationError(self.messages['hash_length'])
        try:
            int(hash_value, 16)
        except ValueError:
            raise ConversionError(self.messages['hash_hex'])
        return value 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:20,代码来源:models.py

示例3: to_native

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def to_native(self, value, context=None):
        return self._to_name(value, ConversionError) 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:4,代码来源:types.py

示例4: _apply_precision

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def _apply_precision(self, value):
        try:
            value = Decimal(value).quantize(self.precision, rounding=ROUND_HALF_UP).normalize()
        except (TypeError, InvalidOperation):
            raise ConversionError(self.messages['number_coerce'].format(value))
        return value 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:8,代码来源:models.py

示例5: to_native

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def to_native(self, value, context=None):
        if isinstance(value, (memoryview, bytes)):
            return value

        if isinstance(value, str):
            is_hex = all(c in string.hexdigits for c in value)
            if not is_hex:
                raise ConversionError(self.messages['hash_hex'])
            if len(value) % 2 == 1:
                value = '0' + value
            return to_bin(value) 
开发者ID:fy0,项目名称:slim,代码行数:13,代码来源:schematics_ext.py

示例6: _json_try_convert

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def _json_try_convert(value, err, no_throw=False):
    if isinstance(value, (bytes, str)):
        try:
            return json.loads(value)
        except json.JSONDecodeError:
            if not no_throw:
                raise ConversionError(err)
    return value 
开发者ID:fy0,项目名称:slim,代码行数:10,代码来源:schematics_ext.py

示例7: to_native

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def to_native(self, value, context=None):
        if not value:
            return dict()
        if not isinstance(value, dict):
            try:
                value = json.loads(value)
            except (AttributeError, TypeError, ValueError):
                raise ConversionError(self.messages['convert'].format(value))
        return value 
开发者ID:clearcare,项目名称:cc_dynamodb3,代码行数:11,代码来源:types.py

示例8: load

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ConversionError [as 别名]
def load(self, model, value):
        model = _enforce_type_instance_or_model_class(model)
        try:
            context = get_import_context(oo=True)
            model = self._translate_to_model(model)
            result = model(value, context=context)
            if isinstance(model, ModelType) or not isinstance(model, BaseType):
                result.validate()
            else:
                model.validate(result, context=context)
            return result
        except BaseError as e:
            raise SerializationException(str(e))
        except ConversionError as e:
            raise SerializationException(str(e)) 
开发者ID:toumorokoshi,项目名称:transmute-core,代码行数:17,代码来源:schematics_serializer.py


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