def get_socket_name(socket, socketlist, is_input, node):
    """
    Determine name for a socket. The names given through BPy differ from
    what is at the lowest level. This level is also what C[CS]?ycles uses,
    so some mapping is necessary.
    """
    sockname = socket.name
    if is_input:
        if node.type == 'MATH':
            i = 0
            for sck in socketlist.items():
                i+=1
                if sck[1]==socket:
                    name = socket.name
                    sockname = name + str(i)
                    break
        if socket.name == "Shader":
            i = 0
            for sck in socketlist.items():
                if sck[1].name == "Shader": i+=1
                if sck[1]==socket:
                    sockname = "Closure" + str(i)
                    break
    else:
        if socket.name == "Shader":
            if 'BSDF' in node.type:
                sockname = "BSDF"
            else:
                sockname = "Closure"
    sockname = sockname.replace(" ", "")
    return sockname