

def object_hook(dct):
    if ('$oid' in dct):
        return ObjectId(str(dct['$oid']))
    if ('$ref' in dct):
        return DBRef(dct['$ref'], dct['$id'], dct.get('$db', None))
    if ('$date' in dct):
        dtm = dct['$date']
        if isinstance(dtm, string_type):
            aware = datetime.datetime.strptime(dtm[:23], '%Y-%m-%dT%H:%M:%S.%f').replace(tzinfo=utc)
            offset = dtm[23:]
            if ((not offset) or (offset == 'Z')):
                return aware
            else:
                if (len(offset) == 5):
                    secs = ((int(offset[1:3]) * 3600) + (int(offset[3:]) * 60))
                elif ((':' in offset) and (len(offset) == 6)):
                    (hours, minutes) = offset[1:].split(':')
                    secs = ((int(hours) * 3600) + (int(minutes) * 60))
                else:
                    raise ValueError('invalid format for offset')
                if (offset[0] == '-'):
                    secs *= (- 1)
                return (aware - datetime.timedelta(seconds=secs))
        elif isinstance(dtm, collections.Mapping):
            secs = (float(dtm['$numberLong']) / 1000.0)
        else:
            secs = (float(dtm) / 1000.0)
        return (EPOCH_AWARE + datetime.timedelta(seconds=secs))
    if ('$regex' in dct):
        flags = 0
        for opt in dct.get('$options', ''):
            flags |= _RE_OPT_TABLE.get(opt, 0)
        return Regex(dct['$regex'], flags)
    if ('$minKey' in dct):
        return MinKey()
    if ('$maxKey' in dct):
        return MaxKey()
    if ('$binary' in dct):
        if isinstance(dct['$type'], int):
            dct['$type'] = ('%02x' % dct['$type'])
        subtype = int(dct['$type'], 16)
        if (subtype >= 4294967168):
            subtype = int(dct['$type'][6:], 16)
        return Binary(base64.b64decode(dct['$binary'].encode()), subtype)
    if ('$code' in dct):
        return Code(dct['$code'], dct.get('$scope'))
    if ('$uuid' in dct):
        return uuid.UUID(dct['$uuid'])
    if ('$undefined' in dct):
        return None
    if ('$numberLong' in dct):
        return Int64(dct['$numberLong'])
    if ('$timestamp' in dct):
        tsp = secs['$timestamp']
        return Timestamp(tsp['t'], tsp['i'])
    return dct

dataset/ETHPy150Open mongodb/mongo-python-driver/bson/json_util.py object_hook/VarMisuse@623/772 `dct`->`secs`