@classmethod
def register_type_replacement(cls, object_type, replacement_function):

    def custom_serializer(obj, serpent_serializer, outputstream, indentlevel):
        replaced = replacement_function(obj)
        if (replaced is obj):
            serpent_serializer.ser_default_class(replaced, outputstream, indentlevel)
        else:
            serpent_serializer._serialize(replaced, outputstream, indentlevel)
    if ((object_type is type) or (not inspect.isclass(object_type))):
        raise ValueError("refusing to register replacement for a non-type or the type 'type' itself")
    serpent.register_class(object_type, custom_serializer)
@classmethod
def register_type_replacement(cls, object_type, replacement_function):

    def custom_serializer(obj, serpent_serializer, outputstream, indentlevel):
        replaced = replacement_function(obj)
        if (replaced is obj):
            serpent_serializer.ser_default_class(replaced, outputstream, indentlevel)
        else:
            serpent_serializer._serialize(replaced, outputstream, indentlevel)
    if ((object_type is type) or (not inspect.isclass(object_type))):
        raise ValueError("refusing to register replacement for a non-type or the type 'type' itself")
    serpent.register_class(object_type, custom_serializer)