def canonicalize_temperatures(parsed, current):
    """
	Canonicalizes the temperatures provided in parsed.

	Will make sure that returned result only contains extruder keys
	like Tn, so always qualified with a tool number.

	The algorithm for cleaning up the parsed keys is the following:

	  * If ``T`` is not included with the reported extruders, return
	  * If more than just ``T`` is reported:
	    * If both ``T`` and ``T0`` are reported, remove ``T`` from
	      the result.
	    * Else set ``T0`` to ``T`` and delete ``T`` (Smoothie extra).
	  * If only ``T`` is reported, set ``Tc`` to ``T`` and delete ``T``
	  * return

	Arguments:
	    parsed (dict): the parsed temperatures (mapping tool => (actual, target))
	      to canonicalize
	    current (int): the current active extruder
	Returns:
	    dict: the canonicalized version of ``parsed``
	"""
    reported_extruders = list(filter(lambda x: x.startswith('T'), parsed.
        keys()))
    if not 'T' in reported_extruders:
        return parsed
    current_tool_key = 'T%d' % current
    result = dict(parsed)
    if len(reported_extruders) > 1:
        if 'T0' in reported_extruders:
            if current_tool_key not in reported_extruders:
                result[current_tool_key] = result['T']
            del result['T']
        else:
            result['T0'] = result['T']
            del result['T']
    else:
        result[current_tool_key] = result['T']
        del result['T']
    return result
