def requires_open_handle(method):  # pylint: disable=invalid-name
  """Decorator to ensure a handle is open for certain methods.

  Subclasses should decorate their Read() and Write() with this rather than
  checking their own internal state, keeping all "is this handle open" logic
  in is_closed().

  Args:
    method: A class method on a subclass of UsbHandle

  Raises:
    HandleClosedError: If this handle has been closed.

  Returns:
    A wrapper around method that ensures the handle is open before calling through
  to the wrapped method.
  """
  @functools.wraps(method)
  def wrapper_requiring_open_handle(self, *args, **kwargs):
    """The wrapper to be returned."""
    if self.is_closed():
      raise usb_exceptions.HandleClosedError()
    return method(self, *args, **kwargs)
  return wrapper_requiring_open_handle
Decorator to ensure a handle is open for certain methods.

  Subclasses should decorate their Read() and Write() with this rather than
  checking their own internal state, keeping all "is this handle open" logic
  in is_closed().

  Args:
    method: A class method on a subclass of UsbHandle

  Raises:
    HandleClosedError: If this handle has been closed.

  Returns:
    A wrapper around method that ensures the handle is open before calling through
  to the wrapped method.