示例#1
0
 def _decode(s, format, **kwargs):
     try:
         content = io_util.read_content(s)
         # decode content using the given format
         data = io_util.decode(content, format, **kwargs)
         if type_util.is_dict(data):
             return data
         elif type_util.is_list(data):
             # force list to dict
             return {'values': data}
         else:
             raise ValueError(
                 'Invalid data type: {}, expected dict or list.'.format(
                     type(data)))
     except Exception as e:
         raise ValueError(
             'Invalid data or url or filepath argument: {}\n{}'.format(
                 s, e))
示例#2
0
 def test_decode_with_invalid_format(self):
     with self.assertRaises(ValueError):
         io_util.decode('', format='xxx')