<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def Units(uname):
 """Generate a unit object. Parameters uname : str Wavelength or flux unit name. Returns ------- unit : `BaseUnit` or `None` Unit object. `None` means unitless. Raises ------ ValueError Unknown unit name. """

    if isinstance(uname,BaseUnit):
        return uname
    else:
        try:
            if issubclass(uname,BaseUnit):
                return uname()
        except TypeError:

            try:
                return factory(uname)
            except KeyError:
                if uname == str(None):
                    return None
                else:
                    raise ValueError("Unknown units %s"%uname)