本文整理汇总了Python中flatland.String.using方法的典型用法代码示例。如果您正苦于以下问题:Python String.using方法的具体用法?Python String.using怎么用?Python String.using使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flatland.String
的用法示例。
在下文中一共展示了String.using方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validator_validated
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
def test_validator_validated():
sentinel = []
def listener(**kw):
sentinel.append(kw)
signals.validator_validated.connect(listener)
schema = String.using(validators=[Present(),
Converted(),
NoLongerThan(5)])
el = schema()
assert not el.validate()
eq_(sentinel, [dict(sender=schema.validators[0],
element=el,
state=None,
result=False)])
del sentinel[:]
el = schema(value='abcd')
assert el.validate()
assert len(sentinel) == 3
assert sentinel[-1]['result']
del sentinel[:]
el = schema('squiznart')
assert not el.validate()
assert len(sentinel) == 3
assert not sentinel[-1]['result']
s2 = String.using(optional=False)
del sentinel[:]
el = s2()
assert not el.validate()
eq_(sentinel, [dict(sender=NotEmpty, element=el,
state=None, result=False)])
del sentinel[:]
el = s2('squiznart')
assert el.validate()
eq_(sentinel, [dict(sender=NotEmpty, element=el,
state=None, result=True)])
del listener
del sentinel[:]
el = schema('squiznart')
assert not el.validate()
assert not sentinel
signals.validator_validated._clear_state()
示例2: test_joined_string
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
def test_joined_string():
el = JoinedString(u'abc')
assert el.value == u'abc'
assert [child.value for child in el] == [u'abc']
el = JoinedString(u'abc,def')
assert el.value == u'abc,def'
assert [child.value for child in el] == [u'abc', u'def']
el = JoinedString([u'abc', u'def'])
assert el.value == u'abc,def'
assert [child.value for child in el] == [u'abc', u'def']
el = JoinedString(u' abc,,ghi ')
assert el.value == u'abc,ghi'
assert [child.value for child in el] == [u'abc', u'ghi']
el = JoinedString(u'abc,,ghi', prune_empty=False)
assert el.value == u'abc,,ghi'
assert [child.value for child in el] == [u'abc', u'', u'ghi']
# The child (String) strips by default
el = JoinedString(u' abc ,, ghi ', strip=False)
assert el.value == 'abc,ghi'
assert [child.value for child in el] == [u'abc', u'ghi']
# Try with a non-stripping String
el = JoinedString(u' abc ,, ghi ',
strip=False,
member_schema=String.using(strip=False))
assert el.value == ' abc , ghi '
assert [child.value for child in el] == [u' abc ', u' ghi ']
示例3: test_set_default
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
def test_set_default():
schema = Array.of(String).using(default=[u'x', u'y'])
el = schema()
eq_(el.value, [])
el.set_default()
eq_(el.value, [u'x', u'y'])
el.append(u'z')
eq_(el.value, [u'x', u'y', u'z'])
el.set_default()
eq_(el.value, [u'x', u'y'])
defaulted_child = String.using(default='not triggered')
schema = Array.of(defaulted_child).using(default=[u'x'])
el = schema.from_defaults()
eq_(el.value, [u'x'])
schema = Array.of(String.using(default=u'x'))
el = schema.from_defaults()
eq_(el.value, [])
示例4: different
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
if not self.validnamespace(meta.get(NAMESPACE)):
return self.note_error(element, state, 'invalid_namespace_msg')
if state[FQNAME].field == ITEMID:
if not self.validitemid(meta.get(ITEMID, state[FQNAME].value)):
return self.note_error(element, state, 'invalid_itemid_msg')
return True
JSON = OptionalMultilineText.with_properties(lang='en', dir='ltr').validated_by(ValidJSON())
URL = String.with_properties(widget=WIDGET_TEXT).validated_by(URLValidator())
OpenID = URL.using(label=L_('OpenID')).with_properties(placeholder=L_("OpenID address"))
YourOpenID = OpenID.with_properties(placeholder=L_("Your OpenID address"))
Email = String.using(label=L_('E-Mail')).with_properties(widget=WIDGET_EMAIL,
placeholder=L_("E-Mail address")).validated_by(IsEmail())
YourEmail = Email.with_properties(placeholder=L_("Your E-Mail address"))
Password = Text.with_properties(widget=WIDGET_PASSWORD).using(label=L_('Password'))
RequiredPassword = Password.validated_by(Present())
Checkbox = Boolean.with_properties(widget=WIDGET_CHECKBOX).using(optional=True, default=1)
InlineCheckbox = Checkbox.with_properties(widget=WIDGET_INLINE_CHECKBOX)
Select = Enum.with_properties(widget=WIDGET_SELECT)
# SelectSubmit is like Select in that it is rendered as a group of controls
# with different (predefined) `value`s for the same `name`. But the controls are
示例5: factory
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
def factory(default, **kw):
return List.using(default=default, **kw).of(
String.using(default=u'val'))
示例6: IsEmail
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
from flatland import String
from flatland.validation import Present, IsEmail
OptionalText = String.using(optional=True)
RequiredText = String.validated_by(Present())
RequiredEmail = String.validated_by(Present(), IsEmail())
示例7:
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
re.compile(value, re.U)
valid = True
except re.error:
valid = False
if not valid:
element.add_error("Subscription has invalid value.")
return valid
common_meta = (
String.named(keys.ITEMID).validated_by(itemid_validator),
String.named(keys.REVID).validated_by(revid_validator),
String.named(keys.PARENTID).validated_by(uuid_validator).using(optional=True),
String.named(keys.WIKINAME).using(strip=False).validated_by(wikiname_validator),
String.named(keys.NAMESPACE).using(strip=False).validated_by(namespace_validator),
List.named(keys.NAME).of(String.using(strip=False).validated_by(name_validator)).using(optional=True),
List.named(keys.NAME_OLD).of(String.using(strip=False).validated_by(name_validator)).using(optional=True),
Integer.named(keys.MTIME).validated_by(mtime_validator),
String.named(keys.ACTION).validated_by(action_validator),
String.named(keys.ACL).validated_by(acl_validator),
String.named(keys.COMMENT).validated_by(comment_validator),
String.named(keys.ADDRESS).validated_by(address_validator),
String.named(keys.HOSTNAME).validated_by(hostname_validator).using(optional=True),
List.named(keys.TAGS).of(String.named('tag').validated_by(tag_validator)).using(optional=True),
)
ContentMetaSchema = DuckDict.named('ContentMetaSchema').of(
String.named(keys.CONTENTTYPE).validated_by(contenttype_validator),
String.named(keys.USERID).validated_by(userid_validator),
Integer.named(keys.SIZE).validated_by(size_validator),
String.named(keys.HASH_ALGORITHM).validated_by(hash_validator),
示例8: validated_string
# 需要导入模块: from flatland import String [as 别名]
# 或者: from flatland.String import using [as 别名]
def validated_string(*validators):
return List.named('test').of(String.using(name=u'foo',
validators=validators))