Example #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
Example #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'
Example #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'
Example #4
0
def cast(field, row):
    return typecast.cast(field.get('type'),
                         row.get(field.get('title')),
                         **field)
Example #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
Example #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