def default(self, obj):
    replacer = self.__type_replacements.get(type(obj), None)
    if replacer:
        obj = replacer(obj)
    if isinstance(obj, set):
        return tuple(obj)
    if isinstance(obj, uuid.UUID):
        return str(obj)
    if isinstance(obj, bytearray):
        return bytes(obj)
    if isinstance(obj, complex):
        return msgpack.ExtType(48, struct.pack('dd', obj.real, obj.imag))
    if isinstance(obj, datetime.datetime):
        if obj.tzinfo:
            raise errors.SerializeError('msgpack cannot serialize datetime with timezone info')
        return msgpack.ExtType(50, struct.pack('d', obj.timestamp()))
    if isinstance(obj, datetime.date):
        return msgpack.ExtType(51, struct.pack('l', obj.toordinal()))
    if isinstance(obj, decimal.Decimal):
        return str(obj)
    if isinstance(obj, numbers.Number):
        return msgpack.ExtType(49, str(obj).encode('ascii'))
    if isinstance(obj, array.array):
        if (obj.typecode == 'c'):
            return obj.tostring()
        if (obj.typecode == 'u'):
            return obj.tounicode()
        return obj.tolist()
    return self.class_to_dict(obj)
def default(self, obj):
    replacer = self.__type_replacements.get(type(obj), None)
    if replacer:
        obj = replacer(obj)
    if isinstance(obj, set):
        return tuple(obj)
    if isinstance(obj, uuid.UUID):
        return str(obj)
    if isinstance(obj, bytearray):
        return bytes(obj)
    if isinstance(obj, complex):
        return msgpack.ExtType(48, struct.pack('dd', obj.real, obj.imag))
    if isinstance(obj, datetime.datetime):
        if obj.tzinfo:
            raise errors.SerializeError('msgpack cannot serialize datetime with timezone info')
        return msgpack.ExtType(50, struct.pack('d', obj.timestamp()))
    if isinstance(obj, datetime.date):
        return msgpack.ExtType(51, struct.pack('l', obj.toordinal()))
    if isinstance(obj, decimal.Decimal):
        return str(obj)
    if isinstance(obj, numbers.Number):
        return msgpack.ExtType(49, str(obj).encode('ascii'))
    if isinstance(obj, array.array):
        if (obj.typecode == 'c'):
            return obj.tostring()
        if (obj.typecode == 'u'):
            return obj.tounicode()
        return obj.tolist()
    return self.class_to_dict(obj)