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


Python validate.Regexp方法代碼示例

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


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

示例1: test_regexp

# 需要導入模塊: from marshmallow import validate [as 別名]
# 或者: from marshmallow.validate import Regexp [as 別名]
def test_regexp():
    ipv4_regex = (
        r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}"
        r"([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
    )

    class TestSchema(Schema):
        ip_address = fields.String(validate=validate.Regexp(ipv4_regex))

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    assert dumped["definitions"]["TestSchema"]["properties"]["ip_address"] == {
        "title": "ip_address",
        "type": "string",
        "pattern": ipv4_regex,
    } 
開發者ID:fuhrysteve,項目名稱:marshmallow-jsonschema,代碼行數:20,代碼來源:test_validation.py

示例2: test_regexp_error

# 需要導入模塊: from marshmallow import validate [as 別名]
# 或者: from marshmallow.validate import Regexp [as 別名]
def test_regexp_error():
    class TestSchema(Schema):
        test_regexp = fields.Int(validate=validate.Regexp(r"\d+"))

    schema = TestSchema()

    with pytest.raises(UnsupportedValueError):
        dumped = validate_and_dump(schema) 
開發者ID:fuhrysteve,項目名稱:marshmallow-jsonschema,代碼行數:10,代碼來源:test_validation.py

示例3: __init__

# 需要導入模塊: from marshmallow import validate [as 別名]
# 或者: from marshmallow.validate import Regexp [as 別名]
def __init__(self, **metadata):
        super().__init__(**metadata)
        self.validators = (
            [validate.Regexp("^#[a-fA-F0-9]{3,6}$")] + list(self.validators)
        ) 
開發者ID:apache,項目名稱:airflow,代碼行數:7,代碼來源:common_schema.py

示例4: key_name_validate

# 需要導入模塊: from marshmallow import validate [as 別名]
# 或者: from marshmallow.validate import Regexp [as 別名]
def key_name_validate(value):
    regex_validate = validate.Regexp(
        r'^(?!^\.+$)\S+$',
        error=u'Key({input}) should not starts with dots or contains CRLF.'
    )
    value = regex_validate(value)
    if not all(0x00 < ord(c) < 0x7F for c in unicode(value)):
        raise ValidationError(
            u'Key({}) contains unicode characters.'.format(value)) 
開發者ID:huskar-org,項目名稱:huskar,代碼行數:11,代碼來源:validates.py

示例5: __init__

# 需要導入模塊: from marshmallow import validate [as 別名]
# 或者: from marshmallow.validate import Regexp [as 別名]
def __init__(self, pattern, nested_field, *args, **kwargs):
        fields.Field.__init__(self, *args, **kwargs)
        self.key_field = fields.Str(validate=validate.Regexp(pattern))
        self.nested_field = nested_field 
開發者ID:podhmo,項目名稱:swagger-marshmallow-codegen,代碼行數:6,代碼來源:fields.py

示例6: dispatch_validator

# 需要導入模塊: from marshmallow import validate [as 別名]
# 或者: from marshmallow.validate import Regexp [as 別名]
def dispatch_validator(self, c, value):
        from marshmallow.validate import Length, Regexp, OneOf
        from .validate import Range, MultipleOf, Unique, ItemsRange

        if isinstance(value, (Regexp)):
            c.import_("re")  # xxx
            c.from_("marshmallow.validate", value.__class__.__name__)
        elif isinstance(value, (Length, OneOf)):
            c.from_("marshmallow.validate", value.__class__.__name__)
        elif isinstance(value, (Range, MultipleOf, Unique, ItemsRange)):
            c.from_("swagger_marshmallow_codegen.validate", value.__class__.__name__)
        return value 
開發者ID:podhmo,項目名稱:swagger-marshmallow-codegen,代碼行數:14,代碼來源:dispatcher.py


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