本文整理汇总了Python中valideer.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_parsing_required_properties
def test_parsing_required_properties(self):
get_schema = lambda: {
"foo": V.Nullable("number"),
"?nested": [V.Nullable({
"baz": "string"
})]
}
valid = [{"foo": 3, "nested": [None]}]
missing_properties = [{}, {"foo": 3, "nested": [{}]}]
for _ in xrange(3):
with V.parsing(required_properties=False):
self._testValidation(get_schema(),
valid=valid + missing_properties)
with V.parsing(required_properties=True):
self._testValidation(get_schema(),
valid=valid, invalid=missing_properties)
# gotcha: calling parse() with required_properties=True is not
# equivalent to the above call because the V.Nullable() calls in
# get_schema have already called implicitly parse() without parameters.
if V.Object.REQUIRED_PROPERTIES:
self._testValidation(V.parse(get_schema(), required_properties=True),
invalid=[missing_properties[1]])
else:
self._testValidation(V.parse(get_schema(), required_properties=True),
valid=[missing_properties[1]])
开发者ID:apriltuesday,项目名称:valideer,代码行数:27,代码来源:test_validators.py
示例2: test_ignore_optional_property_errors_parse_parameter
def test_ignore_optional_property_errors_parse_parameter(self):
schema = {
"+foo": "number",
"?bar": "boolean",
"?nested": [{
"+baz": "string",
"?zoo": "number",
}]
}
invalid_required = [
{"foo": "2", "bar": True},
]
invalid_optional = [
{"foo": 3, "bar": "nan"},
{"foo": 3.1, "nested": [{"baz": "x", "zoo": "12"}]},
{"foo": 0, "nested": [{"baz": 1, "zoo": 2}]},
]
adapted = [
{"foo": 3},
{"foo": 3.1, "nested": [{"baz": "x"}]},
{"foo": 0},
]
for _ in xrange(3):
self._testValidation(V.parse(schema, ignore_optional_property_errors=False),
invalid=invalid_required + invalid_optional)
self._testValidation(V.parse(schema, ignore_optional_property_errors=True),
invalid=invalid_required,
adapted=zip(invalid_optional, adapted))
开发者ID:apriltuesday,项目名称:valideer,代码行数:28,代码来源:test_validators.py
示例3: test_where_arrangement
def test_where_arrangement(self):
q = Query()
q.select("a")
q.where("a", "a > 10")
q.where("b", "b > 20")
q.where("c", "c > 30")
q.tables("from t")
q.into(False)
# no column `d`
self.assertRaises(valideer.ValidationError, q, valideer.parse({"where": "where"}).validate({"where": "(d|b)&c"}))
self.assertEqual(q(valideer.parse({"where": "where"}).validate({"where": "(a|b)&c"})),
"select a from t where ((a > 10 or b > 20) and c > 30)")
开发者ID:stevepeak,项目名称:inquiry,代码行数:14,代码来源:test_query.py
示例4: test_required_properties_parse_parameter
def test_required_properties_parse_parameter(self):
schema = {
"foo": "number",
"?bar": "boolean",
"?nested": [{
"baz": "string"
}]
}
missing_properties = [{}, {"bar": True}, {"foo": 3, "nested": [{}]}]
for _ in xrange(3):
self._testValidation(V.parse(schema, required_properties=True),
invalid=missing_properties)
self._testValidation(V.parse(schema, required_properties=False),
valid=missing_properties)
开发者ID:apriltuesday,项目名称:valideer,代码行数:14,代码来源:test_validators.py
示例5: test_where_multi_arg
def test_where_multi_arg(self):
q = Query()
q.select("a")
q.where("a", "a=1")
q.where("b", "b=2")
q.where("b", "b=3")
q.tables("from t")
q.into(False)
# no column `col_1`
self.assertRaises(valideer.ValidationError, q, valideer.parse({"where": "where"}).validate({"where": "a|b|c"}))
self.assertEqual(q(valideer.parse({"where": "where"}).validate({"where": "a|b"})),
"select a from t where (a=1 or (b=2 and b=3))")
开发者ID:stevepeak,项目名称:inquiry,代码行数:14,代码来源:test_query.py
示例6: validated
def validated(arguments=None, body=None, extra_arguments=True, extra_body=False):
if type(body) in (dict, str):
body = parse(body, additional_properties=extra_body)
elif body not in (None, False):
raise ValueError('body must be type None, False, or dict')
if type(arguments) is dict:
arguments = parse(arguments, additional_properties=extra_arguments)
elif arguments not in (None, False):
raise ValueError('arguments must be type None, False, or dict')
def wrapper(method):
@wraps(method)
def validate(self, *args, **kwargs):
# ------------------
# Validate Body Data
# ------------------
if body:
try:
_body = json_decode(self.request.body) if self.request.body else {}
except:
# ex. key1=value2&key2=value2
try:
_body = dict([(k, v[0] if len(v) == 1 else v) for k, v in parse_qs(self.request.body, strict_parsing=True).items()])
except:
raise HTTPError(400, "body was not able to be decoded")
kwargs['body'] = body.validate(_body, adapt=True)
elif body is False and self.request.body:
raise HTTPError(400, reason='No body arguments allowed')
# -------------------
# Validate URL Params
# -------------------
if arguments:
# include url arguments
if self.request.query_arguments:
_arguments = dict([(k, v[0] if len(v) == 1 else v) for k, v in self.request.query_arguments.items() if v != [''] and k[0] != '_'])
else:
_arguments = {}
kwargs["arguments"] = arguments.validate(_arguments)
elif arguments is False and self.request.query_arguments and not any(map(lambda a: a[0] == '_', self.request.query_arguments)):
raise HTTPError(400, reason='No url arguments allowed')
return method(self, *args, **kwargs)
return validate
return wrapper
开发者ID:stevepeak,项目名称:tornwrap,代码行数:49,代码来源:validated.py
示例7: test_branch
def test_branch(self):
schema = valideer.parse({"branch": "branch"})
for x in ('master', 'stable', 'something/thisoem', '-aples', '.dev', 'builds,/[email protected]#$%&*'):
assert schema.validate(dict(branch=x))
for x in (False, None):
self.assertRaises(valideer.ValidationError, schema.validate, dict(branch=x))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:7,代码来源:test_validators.py
示例8: test_file
def test_file(self):
schema = valideer.parse({"value": "file"})
for handler in ('app/base.py', 'codecov.sh'):
assert schema.validate(dict(value=handler))
for invalid in ('not/a/path', '**#^@', '../black'):
self.assertRaises(valideer.ValidationError, schema.validate, dict(value=invalid))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:7,代码来源:test_validators.py
示例9: test_email
def test_email(self):
schema = valideer.parse({"email": "email"})
for email in ('def post(self, @example.com', '[email protected]', '[email protected]'):
self.assertEqual(schema.validate(dict(email=email))['email'], email.lower())
for email in ('needsanat', '[email protected]'):
self.assertRaises(error, schema.validate, dict(email=email))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:7,代码来源:test_validators.py
示例10: test_ref
def test_ref(self):
schema = valideer.parse({"value": "ref"})
self.assertEqual(schema.validate(dict(value="a"*40))['value'], "a"*40)
self.assertEqual(schema.validate(dict(value="apples"))['value'], "apples")
for x in (None, object(), int, -50):
self.assertRaises(error, schema.validate, dict(value=x))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:8,代码来源:test_validators.py
示例11: test_id
def test_id(self):
schema = valideer.parse({"value": "id"})
self.assertEqual(schema.validate(dict(value=1))['value'], 1)
self.assertEqual(schema.validate(dict(value="50"))['value'], 50)
for x in ('not', None, 'random', object(), int, -50, "19.123"):
self.assertRaises(error, schema.validate, dict(value=x))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:8,代码来源:test_validators.py
示例12: test_timezone
def test_timezone(self):
schema = valideer.parse({"value": "timezone"})
for key, value in timezone.timezones.items():
self.assertEqual(schema.validate(dict(value=key))['value'], value)
for x in ('not', None, 'random', object(), int):
self.assertRaises(error, schema.validate, dict(value=x))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:8,代码来源:test_validators.py
示例13: test_handler
def test_handler(self):
schema = valideer.parse({"value": "handler"})
for handler in ('valid-handler', 'someothername', '__hello.world-ok'):
assert schema.validate(dict(value=handler))
for invalid in "[email protected]#{$%^&*(),<>?/'\";:[]{}\\|~`+":
self.assertRaises(valideer.ValidationError, schema.validate, dict(value='characters'+invalid))
self.assertRaises(valideer.ValidationError, schema.validate, dict(value=None))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:8,代码来源:test_validators.py
示例14: test_version
def test_version(self):
schema = valideer.parse({"value": "version"})
for version in ('0.0.1', '0.0.10', '0.2.10', '1.2.1'):
assert schema.validate(dict(value=version))
self.assertRaises(valideer.ValidationError, schema.validate, dict(value='-124.12.51'))
self.assertRaises(valideer.ValidationError, schema.validate, dict(value='_something-odd'))
self.assertRaises(valideer.ValidationError, schema.validate, dict(value=None))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:8,代码来源:test_validators.py
示例15: test_day
def test_day(self):
schema = valideer.parse({"day": "day"})
for (d, v) in ((0, "sun"), (1, "mon"), (2, "tue"), (3, "wed"), (4, "thu"), (5, "fri"), (6, "sat")):
self.assertEqual(schema.validate(dict(day=d))['day'], d)
self.assertEqual(schema.validate(dict(day=v))['day'], d)
for day in ('needsanat', 'nodom'):
self.assertRaises(error, schema.validate, dict(day=day))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:8,代码来源:test_validators.py
示例16: test_additional_properties_parse_parameter
def test_additional_properties_parse_parameter(self):
schema = {
"?bar": "boolean",
"?nested": [{
"?baz": "integer"
}]
}
values = [{"x1": "yes"},
{"bar":True, "nested": [{"x1": "yes"}]}]
for _ in xrange(3):
self._testValidation(V.parse(schema, additional_properties=True),
valid=values)
self._testValidation(V.parse(schema, additional_properties=False),
invalid=values)
self._testValidation(V.parse(schema, additional_properties="string"),
valid=values,
invalid=[{"x1": 42},
{"bar":True, "nested": [{"x1": 42}]}])
开发者ID:ebachle,项目名称:valideer,代码行数:18,代码来源:test_validators.py
示例17: leave_groups
def leave_groups(self, user, data):
try:
groups = V.parse([V.AdaptTo(uuid.UUID)]).validate(data)
except V.ValidationError as ex:
raise ValidationError(str(ex))
self.log.info('leave groups',
audit=True, data=data, user=userinfo_for_log(user))
userid = user['userid']
for groupid in groups:
self.session.del_group_member(groupid, userid)
开发者ID:feideconnect,项目名称:core-apis,代码行数:10,代码来源:controller.py
示例18: test_commit
def test_commit(self):
schema = valideer.parse({"value": "commit"})
for commit in ('d5eb3baabe1149158817640f9e27e6b947aef043',
'd5eb3baabe1149158817640f9e27e6b947aef043',
'1341:233tmgpeqmgpqm',
'2f540b1af5fb5f432be686a77ed5206b589a7b52'):
assert schema.validate(dict(value=commit))
self.assertRaises(valideer.ValidationError, schema.validate, dict(value='_something odd'))
self.assertRaises(valideer.ValidationError, schema.validate, dict(value=None))
开发者ID:stevepeak,项目名称:tornwrap,代码行数:10,代码来源:test_validators.py
示例19: validate
def validate(self, item):
validator = V.parse(self.schema, additional_properties=False)
try:
adapted = validator.validate(item)
except V.ValidationError as ex:
raise ValidationError(str(ex))
for key in self.schema:
if not key.startswith('+') and key not in adapted:
adapted[key] = None
return adapted
开发者ID:feideconnect,项目名称:core-apis,代码行数:10,代码来源:crud_base.py
示例20: test_it_should_accept_and_enforce_choices
def test_it_should_accept_and_enforce_choices(self):
from nonobvious import fields
field = fields.Field(key='foo', validator='string', choices=('bar', 'baz'))
validator = V.parse(dict([field.validation_spec]))
ensure(validator.validate).called_with({'foo': 'bar'}).equals({'foo': 'bar'})
ensure(validator.validate).called_with({'foo': 'baz'}).equals({'foo': 'baz'})
ensure(validator.validate).called_with({'foo': 'boo'}).raises(V.ValidationError)
开发者ID:eykd,项目名称:nonobvious,代码行数:10,代码来源:test_entity_fields.py
注:本文中的valideer.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论