Ejemplo n.º 1
0
 def default(self, obj):
     try:
         return json.JSONEncoder.default(self, obj)
     except TypeError, catched:
         if isinstance(obj, GeneratorType):
             return list(obj)
         if isinstance(obj, ResultsWrapper):
             return list(obj)
         elif isinstance(obj, datetime):
             return datetime_to_rfc3339(obj)
         raise catched
Ejemplo n.º 2
0
Archivo: dicts.py Proyecto: UPCnet/max
def decodeBSONEntity(di, key):
    """
        Inspired by pymongo bson.json_util.default, but specially processing some value types:

        ObjectId --> hexvalue
        datetime --> rfc3339
    """
    value = di[key]
    if isinstance(value, ObjectId):
        di[key] = str(value)
    elif isinstance(value, datetime):
        di[key] = datetime_to_rfc3339(value)