当前位置: 首页>>代码示例>>Python>>正文


Python String.using方法代码示例

本文整理汇总了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()
开发者ID:dag,项目名称:flatland,代码行数:52,代码来源:test_signals.py

示例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 ']
开发者ID:mbr,项目名称:flatland0,代码行数:34,代码来源:test_compound.py

示例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, [])
开发者ID:dag,项目名称:flatland,代码行数:24,代码来源:test_arrays.py

示例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
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:34,代码来源:forms.py

示例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'))
开发者ID:dag,项目名称:flatland,代码行数:5,代码来源:test_lists.py

示例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())
开发者ID:xiaq,项目名称:tunaweb,代码行数:9,代码来源:widgets.py

示例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),
开发者ID:denedios,项目名称:moin-2.0,代码行数:33,代码来源:validation.py

示例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))
开发者ID:mbr,项目名称:flatland0,代码行数:5,代码来源:test_containers.py


注:本文中的flatland.String.using方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。