Пример #1
0
def disable(method):
  """Decorator/function to disable RPC on a method."""
  if is_classmethod(method) or is_bound(method):
    setattr(method.__func__, _rpc_enabled_attr, False)  # for bound methods, we can only set attributes on the underlying function object
  else:
    setattr(method, _rpc_enabled_attr, False)  # NOTE this will fail if applied on an instancemethod
  return method
Пример #2
0
def disable(method):
    """Decorator/function to disable RPC on a method."""
    if is_classmethod(method) or is_bound(method):
        setattr(
            method.__func__, _rpc_enabled_attr, False
        )  # for bound methods, we can only set attributes on the underlying function object
    else:
        setattr(method, _rpc_enabled_attr,
                False)  # NOTE this will fail if applied on an instancemethod
    return method
Пример #3
0
def enable(method, payload_attr=None):
  """Decorator/function to enable RPC on a method."""
  #logger.debug("method: {}, type: {}, callable? {}, isfunction? {}, ismethod? {}, is_bound? {}, is_classmethod? {}".format(method, type(method), callable(method), isfunction(method), ismethod(method), is_bound(method), is_classmethod(method)))  # [verbose]
  if is_classmethod(method) or is_bound(method):
    setattr(method.__func__, _rpc_enabled_attr, True)  # for bound methods, we can only set attributes on the underlying function object
    if payload_attr is not None:
      setattr(method.__func__, payload_attr, True)
  else:
    setattr(method, _rpc_enabled_attr, True)  # NOTE this will fail if applied on an instancemethod
    if payload_attr is not None:
      setattr(method, payload_attr, True)
  return method
Пример #4
0
def enable(method, payload_attr=None):
    """Decorator/function to enable RPC on a method."""
    #logger.debug("method: {}, type: {}, callable? {}, isfunction? {}, ismethod? {}, is_bound? {}, is_classmethod? {}".format(method, type(method), callable(method), isfunction(method), ismethod(method), is_bound(method), is_classmethod(method)))  # [verbose]
    if is_classmethod(method) or is_bound(method):
        setattr(
            method.__func__, _rpc_enabled_attr, True
        )  # for bound methods, we can only set attributes on the underlying function object
        if payload_attr is not None:
            setattr(method.__func__, payload_attr, True)
    else:
        setattr(method, _rpc_enabled_attr,
                True)  # NOTE this will fail if applied on an instancemethod
        if payload_attr is not None:
            setattr(method, payload_attr, True)
    return method
Пример #5
0
def is_rpc_enabled(method):
    """Check if argument is an RPC-enabled bound method."""
    return ismethod(method) and is_bound(method) and getattr(
        method, _rpc_enabled_attr, False)
Пример #6
0
def is_rpc_enabled(method):
  """Check if argument is an RPC-enabled bound method."""
  return ismethod(method) and is_bound(method) and getattr(method, _rpc_enabled_attr, False)