コード例 #1
0
def ds_item(definition, data):
    if isinstance(definition, XObject):
        return (~definition)(data)
    if isinstance(definition, basestring):
        return StringFormatter(definition)(data)
    if callable(definition):
        return definition(data)
    try:
        return DSBuilder(definition)(data)
    except NoBuilder:
        # static item
        return definition
コード例 #2
0
 def test_unicode2(self):
     f = StringFormatter(u'Asdf {0}')
     assert f(u'Žluťoučký kůň') == u'Asdf Žluťoučký kůň'
コード例 #3
0
 def test_format_one_arg(self):
     f = StringFormatter('This is {0}!!1')
     assert f('Spartah') == 'This is Spartah!!1'
コード例 #4
0
 def test_format_dict(self):
     f = StringFormatter('{a} and {b}')
     assert f(dict(a='A', b='B')) == 'A and B'
コード例 #5
0
 def test_format_generator(self):
     f = StringFormatter('{0} + {0} = {1}')
     assert f(xrange(1, 3)) == '1 + 1 = 2'
コード例 #6
0
 def test_format_list(self):
     f = StringFormatter('{0} + {0} = {1}')
     assert f([1, 2]) == '1 + 1 = 2'
コード例 #7
0
 def test_format_tuple(self):
     f = StringFormatter('{0} + {0} = {1}')
     assert f((1, 2)) == '1 + 1 = 2'
コード例 #8
0
    def auto_string_formatter_wrapper(function, *args, **kwargs):
        if isinstance(function, string_types):
            function = StringFormatter(function)

        return func(function, *args, **kwargs)