<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def acquire_restore(lock, state):
 """Acquire a lock and restore its state."""

    if hasattr(lock, '_acquire_restore'):
        lock._acquire_restore(state)
    elif hasattr(lock, 'acquire'):
        lock.acquire()
    else:
        raise TypeError('expecting Lock/RLock')