當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。