Example #1
0
def _remove_null_value_from_map(value):
  if isinstance(value, ndb.Model):
    kv_map = value.to_dict()
    kv_map['key'] = value.key.urlsafe()
    kv_map['key_id'] = value.key.id()
    return _remove_null_value_from_map(kv_map)
  if isinstance(value, list):
    return [_remove_null_value_from_map(i) for i in value]
  elif isinstance(value, datetime):
    return to_epoch(value)
  elif isinstance(value, str) or isinstance(value, int) or isinstance(
    value, unicode):
    return value
  elif isinstance(value, dict):
    result = {}
    for k, v in value.iteritems():
      logging.info('current key: %s', k)
      if isinstance(v, (list, dict)) and not v:
        continue
      if v is None:
        continue

      result[k] = _remove_null_value_from_map(v)

    return result
  else:
    logging.fatal('unknown type: %s %s', type(value), repr(value))
Example #2
0
 def test_convert_from_to(self):
   """Time convert routines."""
   a = from_epoch(1390576468)
   b = to_epoch(a)
   self.assertEqual(b, 1390576468)