<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def duration_to_number(duration, units='seconds'):
 """If duration is already a numeric type, then just return duration. If duration is a timedelta, return a duration in seconds. TODO: allow for multiple types of units. """

    if isinstance(duration, (int, float, long)):
        return duration
    elif isinstance(duration, (datetime.timedelta,)):
        if units == 'seconds':
            return duration.total_seconds()
        else:
            msg = 'unit "%s" is not supported' % units
            raise NotImplementedError(msg)
    elif duration == inf or duration == -inf:
        msg = "Can't convert infinite duration to number"
        raise ValueError(msg)
    else:
        msg = 'duration is an unknown type (%s)' % duration
        raise TypeError(msg)