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


Python flatland.String类代码示例

本文整理汇总了Python中flatland.String的典型用法代码示例。如果您正苦于以下问题:Python String类的具体用法?Python String怎么用?Python String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_filter_form

def user_filter_form(values=None):
    schema = Dict.of(
        String.named(u'field1').using(optional=True),
        String.named(u'field2'))
    if values is None:
        values = {
            u'field1': u'val',
            }
    el = schema(values)
    el[u'field2'].errors.append(u'Missing')

    def label_filter(tag, attrs, stream, context, el):
        from genshi import QName
        if el is None:
            return tag, attrs, stream
        content = stream.render()
        if not content:
            label = el.label
            if not el.optional:
                label += ' *'
            stream = label
        if not el.optional:
            css = (attrs.get(u'class', u'') + u' required').strip()
            attrs |= [(QName(u'class'), css)]
        return tag, attrs, stream
    label_filter.tags = (u'label',)

    return dict(form=el, label_filter=label_filter)
开发者ID:dag,项目名称:flatland,代码行数:28,代码来源:test_tags.py

示例2: test_update_object

def test_update_object():

    class Obj(object):

        def __init__(self, **kw):
            for (k, v) in kw.items():
                setattr(self, k, v)

    schema = Dict.of(String.named(u'x'), String.named(u'y'))

    o = Obj()
    assert not hasattr(o, 'x')
    assert not hasattr(o, 'y')

    def updated_(obj_factory, initial_value, wanted=None, **update_kw):
        el = schema(initial_value)
        obj = obj_factory()
        update_kw.setdefault('key', asciistr)
        el.update_object(obj, **update_kw)
        if wanted is None:
            wanted = dict((asciistr(k), v) for k, v in initial_value.items())
        have = dict(obj.__dict__)
        assert have == wanted

    updated_(Obj, {u'x': u'X', u'y': u'Y'})
    updated_(Obj, {u'x': u'X'}, {'x': u'X', 'y': None})
    updated_(lambda: Obj(y=u'Y'), {u'x': u'X'}, {'x': u'X', 'y': None})
    updated_(lambda: Obj(y=u'Y'), {u'x': u'X'}, {'x': u'X', 'y': u'Y'},
             omit=('y',))
    updated_(lambda: Obj(y=u'Y'), {u'x': u'X'}, {'y': u'Y'},
             include=(u'z',))
    updated_(Obj, {u'x': u'X'}, {'y': None, 'z': u'X'},
             rename=(('x', 'z'),))
开发者ID:dag,项目名称:flatland,代码行数:33,代码来源:test_dicts.py

示例3: test_path

def test_path():
    schema = Dict.named('root').of(
        String.named('element'),
        Dict.named('dict').of(String.named('dict_element')))
    element = schema()

    assert (list(element.el(['dict', 'dict_element']).path) ==
            [element, element['dict'], element['dict']['dict_element']])
开发者ID:mbr,项目名称:flatland0,代码行数:8,代码来源:test_schema.py

示例4: shadow

    def shadow():
        schema = Dict.named(u'dict_name').of(
            String.named(u'name'),
            String.named(u'u'))

        element = schema({u'name': u'string name',
                          u'u': u'string u'})
        element.set_prefix(u'top')
        return {'top': element, 'bound': element.bind}
开发者ID:dag,项目名称:flatland,代码行数:9,代码来源:test_expressions.py

示例5: test_naming_bogus

def test_naming_bogus():
    e = String(name=u's')

    assert e.el(u'.') is e
    assert_raises(LookupError, e.el, u'')
    assert_raises(TypeError, e.el, None)
    assert_raises(LookupError, e.el, ())
    assert_raises(LookupError, e.el, iter(()))
    assert_raises(TypeError, e.el)
开发者ID:dag,项目名称:flatland,代码行数:9,代码来源:test_containers.py

示例6: elements

    def elements():
        from flatland import Dict, String
        anon = Dict.of(String.named(u'anon_field'))()
        named = Dict.named(u'named').of(String.named(u'named_field'))()
        prefixed = Dict.named(u'prefixed').of(String.named(u'prefixed_field'))()
        prefixed.set_prefix(u'three.levels.down')

        return {'form': anon,
                'forms': {'named': named },
                'three': {'levels': {'down': prefixed}}}
开发者ID:dag,项目名称:flatland,代码行数:10,代码来源:test_expressions.py

示例7: test_set_flat_doubly_anonymous_dict

def test_set_flat_doubly_anonymous_dict():
    pairs = ((u'0_x', u'x0'), (u'0_y', u'y0'),
             (u'1_x', u'x1'), (u'1_y', u'y1'),
             (u'2_x', u'x2'), )

    schema = List.of(String.named(u'x'), String.named(u'y'))
    el = schema.from_flat(pairs)

    eq_(len(el), 3)
    eq_(el[0].value, dict((k[-1], v) for k, v in pairs[0:2]))
    eq_(el[1].value, dict((k[-1], v) for k, v in pairs[2:4]))
    eq_(el[2].value, {u'x': u'x2', u'y': None})
开发者ID:dag,项目名称:flatland,代码行数:12,代码来源:test_lists.py

示例8: test_validator_validated

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,代码行数:50,代码来源:test_signals.py

示例9: form

    def form():
        schema = Dict.named(u'field0').of(
            String.named(u'field1'),
            String.named(u'field2'),
            List.named(u'field3').of(String.named(u'field4')),
            List.named(u'field5').of(
                List.named(u'field6').of(String.named(u'field7'))))

        element = schema(
            {u'field1': u'val1',
             u'field2': u'val2',
             u'field3': [u'val3'],
             u'field5': [[u'val4']]})
        element.set_prefix(u'form')
        return {'form': element, 'bound': element.bind}
开发者ID:dag,项目名称:flatland,代码行数:15,代码来源:test_expressions.py

示例10: test_naming_shallow

def test_naming_shallow():
    root = String(name=u's')
    assert root.fq_name() == u'.'
    assert root.flattened_name() == u's'
    assert root.el(u'.') is root

    root = String(name=None)
    assert root.fq_name() == u'.'
    assert root.flattened_name() == u''
    assert root.el(u'.') is root
    assert_raises(LookupError, root.el, ())
    assert root.el([Root]) is root
开发者ID:dag,项目名称:flatland,代码行数:12,代码来源:test_containers.py

示例11: test_naming_dict

def test_naming_dict():
    for name, root_flat, leaf_flat in ((u'd', u'd', u'd_s'),
                                       (None, u'', u's')):
        schema = Dict.named(name).of(String.named(u's'))
        root = schema()
        leaf = root[u's']

        assert root.fq_name() == u'.'
        assert root.flattened_name() == root_flat
        assert root.el(u'.') is root

        assert leaf.fq_name() == u'.s'
        assert leaf.flattened_name() == leaf_flat
        assert root.el(u'.s') is leaf
        assert root.el(u's') is leaf
        assert leaf.el(u'.s') is leaf
        with pytest.raises(LookupError):
            leaf.el(u's')
        assert leaf.el(u'.') is root

        assert root.el([Root]) is root
        assert root.el([u's']) is leaf
        assert root.el([Root, u's']) is leaf
        assert root.el(iter([u's'])) is leaf
        assert root.el(iter([Root, u's'])) is leaf
开发者ID:mbr,项目名称:flatland0,代码行数:25,代码来源:test_containers.py

示例12: test_compose_abstract_fixme

def test_compose_abstract_fixme():
    with pytest.raises(TypeError):
        # really it'd be nice if serialize simply wasn't inherited. would
        # have to rejigger the hierarchy, not sure its worth it.
        schema = Compound.using(field_schema=[String.named(u'y')])
        el = schema()
        schema.serialize(el, u'abc')
开发者ID:mbr,项目名称:flatland0,代码行数:7,代码来源:test_compound.py

示例13: test_joined_string

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,代码行数:32,代码来源:test_compound.py

示例14: test_naming_list_list

def test_naming_list_list():
    # make sure nested Slots-users don't bork
    for name, root_flat, leaf_flat in ((u'l', u'l', u'l_0_l2_0_s'),
                                       (None, u'', u'0_l2_0_s')):
        schema = List.named(name).of(List.named(u'l2').of(String.named(u's')))

        root = schema([u'x'])
        leaf = root[0][0]

        assert root.fq_name() == u'.'
        assert root.flattened_name() == root_flat
        assert root.el(u'.') is root

        assert leaf.fq_name() == u'.0.0'
        assert leaf.flattened_name() == leaf_flat
        assert root.el(u'.0.0') is leaf
        assert root.el(u'0.0') is leaf
        assert leaf.el(u'.0.0') is leaf
        with pytest.raises(LookupError):
            leaf.el(u'0')
        with pytest.raises(LookupError):
            leaf.el(u's')
        assert leaf.el(u'.') is root

        assert root.el([u'0', u'0']) is leaf
开发者ID:mbr,项目名称:flatland0,代码行数:25,代码来源:test_containers.py

示例15: _populate_app_fields

    def _populate_app_fields(self):
        with WindowServiceProxy(59000) as w:
            self.video_mode_map = w.get_video_mode_map()
            if self.video_mode_map:
                self._video_available = True
            else:
                self._video_available = False
            self.video_mode_keys = sorted(self.video_mode_map.keys())
            if self._video_available:
                self.device_key, self.devices = w.get_video_source_configs()

        field_list = [
            Integer.named('overlay_opacity').using(default=50, optional=True),
            Directory.named('device_directory').using(default='', optional=True),
            String.named('transform_matrix').using(default='', optional=True,
                                                properties={'show_in_gui':
                                                            False}), ]

        if self._video_available:
            video_mode_enum = Enum.named('video_mode').valued(
                *self.video_mode_keys).using(default=self.video_mode_keys[0],
                                             optional=True)
            video_enabled_boolean = Boolean.named('video_enabled').using(
                default=False, optional=True, properties={'show_in_gui': True})
            recording_enabled_boolean = Boolean.named('recording_enabled').using(
                default=False, optional=True, properties={'show_in_gui': False})
            field_list.append(video_mode_enum)
            field_list.append(video_enabled_boolean)
            field_list.append(recording_enabled_boolean)
        return Form.of(*field_list)
开发者ID:fusionbob,项目名称:microdrop,代码行数:30,代码来源:dmf_device_controller.py


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