<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_locked(lock):
 """Return whether a lock is locked. Suppors :class:`Lock`, :class:`RLock`, :class:`threading.Lock` and :class:`threading.RLock` instances. """

    if hasattr(lock, 'locked'):
        return lock.locked()
    elif hasattr(lock, '_is_owned'):
        return lock._is_owned()
    else:
        raise TypeError('expecting Lock/RLock')