示例#1
0
def convert_value(bind, value):
    """ Type casting. """
    type_name = get_type(bind)
    try:
        return typecast.cast(type_name, value)
    except typecast.ConverterError:
        return value
示例#2
0
 def test_utils(self):
     conv = value.String()
     conv2 = typecast.converter('string')
     assert type(conv2) == type(conv), \
         typecast.converter('string')
     assert typecast.cast('string', 'foo') == 'foo'
     assert typecast.stringify('number', 7) == '7'
示例#3
0
 def test_utils(self):
     conv = value.String()
     conv2 = typecast.converter('string')
     assert type(conv2) == type(conv), \
         typecast.converter('string')
     assert typecast.cast('string', 'foo') == 'foo'
     assert typecast.stringify('number', 7) == '7'
示例#4
0
def cast(field, row):
    return typecast.cast(field.get('type'),
                         row.get(field.get('title')),
                         **field)
示例#5
0
 def test_jts_spec(self):
     field = {'type': 'date', 'format': '%Y!%m!%d'}
     out = typecast.cast(field, '2009!04!12')
     assert out.year == 2009, out
     assert out.day == 12, out
示例#6
0
 def test_jts_spec(self):
     field = {'type': 'date', 'format': '%Y!%m!%d'}
     out = typecast.cast(field, '2009!04!12')
     assert out.year == 2009, out
     assert out.day == 12, out