本文整理汇总了Python中colander.Length方法的典型用法代码示例。如果您正苦于以下问题:Python colander.Length方法的具体用法?Python colander.Length怎么用?Python colander.Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colander
的用法示例。
在下文中一共展示了colander.Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
resource_type = ResourceType.by_name(value)
if (
resource_type
and (
str(resource_type.id) != request.params.get('id')
or (
str(resource_type.id) == request.params.get('id')
and request.view_name == 'copy'
)
)
):
raise colander.Invalid(
node,
_(u'Resource Type with the same name exists'),
)
return colander.All(colander.Length(max=128), validator,)
示例2: humanize_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def humanize_validator(node, kw):
request = kw.get('request')
def validator(node, value):
resource_type = ResourceType.by_humanize(value)
if (
resource_type
and (
str(resource_type.id) != request.params.get('id')
or (
str(resource_type.id) == request.params.get('id')
and request.view_name == 'copy'
)
)
):
raise colander.Invalid(
node,
_(u'Resource Type with the same humanize exists'),
)
return colander.All(colander.Length(max=128), validator,)
示例3: start_dt_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def start_dt_validator(node, kw):
request = kw.get('request')
def validator(node, value):
campaign_id = request.params.get('id')
if campaign_id:
return
if parse_datetime(value) <= datetime.now():
raise colander.Invalid(
node,
_(u'Check datetime'),
)
return colander.All(colander.Length(max=255), validator,)
示例4: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
service = Service.by_name(value)
if (
service
and str(service.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Service with the same name exists'),
)
return colander.All(colander.Length(max=255), validator,)
示例5: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
account_item = AccountItem.by_name(value)
if (
account_item
and str(account_item.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Account Item with the same name exists'),
)
return colander.All(colander.Length(max=255), validator,)
示例6: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
subaccount = Subaccount.by_name(value)
if (
subaccount
and str(subaccount.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Subaccount with the same name exists'),
)
return colander.All(colander.Length(max=255), validator,)
示例7: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
supplier_type = SupplierType.by_name(value)
if (
supplier_type
and str(supplier_type.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Supplier type with the same name exists'),
)
return colander.All(colander.Length(max=32), validator,)
示例8: iso_code_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def iso_code_validator(node, kw):
request = kw.get('request')
def validator(node, value):
country = Country.by_iso_code(value)
if (
country
and str(country.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Country with the same iso code exists'),
)
return colander.All(colander.Length(min=2, max=2), validator,)
示例9: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
account = Account.by_name(value)
if (
account
and str(account.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Account with the same name exists'),
)
return colander.All(colander.Length(max=255), validator,)
示例10: resource_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def resource_validator(node, kw):
request = kw.get('request')
def validator(node, value):
path = value.split('.')
module, attr = '.'.join(path[:-1]), path[-1]
try:
mod = importlib.import_module(module)
if not hasattr(mod, attr):
raise colander.Invalid(node, _(u"Resource does not exist"))
except ImportError:
raise colander.Invalid(node, _(u"Resource module does not exist"))
except:
raise colander.Invalid(node, _(u"Check module name"))
resource_type = ResourceType.by_resource_name(module, attr)
if (
resource_type
and (
str(resource_type.id) != request.params.get('id')
or (
str(resource_type.id) == request.params.get('id')
and request.view_name == 'copy'
)
)
):
raise colander.Invalid(
node,
_(u'Resource Type with the same resource exists'),
)
return colander.All(colander.Length(max=128), validator,)
示例11: name_validator
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
request = kw.get('request')
def validator(node, value):
mail = Mail.by_name(value)
if (
mail
and str(mail.id) != request.params.get('id')
):
raise colander.Invalid(
node,
_(u'Mail with the same name exists'),
)
return colander.All(colander.Length(max=255), validator,)
示例12: __call__
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def __call__(self, node, value):
""" Returns a ``colander.Function`` validator that uses the context (user)
to validate the password."""
user = get_current()
user_password = getattr(user, 'password', None)
if value['changepassword'] and \
user_password and not user.check_password(value['currentuserpassword']):
raise colander.Invalid(
node.get('currentuserpassword'),
_(' Invalid current password'))
if value['changepassword']:
colander.Length(min=3, max=100)(node.get('password'),
value['password'])
示例13: test_validate_all
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def test_validate_all(self):
node = colander.SchemaNode(colander.String(),
validator=colander.All(
colander.Length(12, 42),
colander.Regex(r'foo*bar')
))
ret = convert(node)
self.assertDictEqual(ret, {
'type': 'string',
'pattern': 'foo*bar',
'maxLength': 42,
'minLength': 12,
})
示例14: test_validate_length
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def test_validate_length(self):
node = colander.SchemaNode(colander.String(),
validator=colander.Length(12, 42))
ret = convert(node)
self.assertDictEqual(ret, {
'type': 'string',
'maxLength': 42,
'minLength': 12,
})
示例15: convert_length_validator_factory
# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def convert_length_validator_factory(max_key, min_key):
def validator_converter(validator):
converted = None
if isinstance(validator, colander.Length):
converted = {}
if validator.max is not None:
converted[max_key] = validator.max
if validator.min is not None:
converted[min_key] = validator.min
return converted
return validator_converter