Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a built-in function.
This invokes the RPC in the global application context. Note that most
user-defined RPCs expect to be invoked in the context of a session. Default
variables will be pulled from that scope. If you call a function from the
wrong context it may fail because its defaults will not be set properly.
:param invocation: A function invocation string.
:param timeout: Max number of secondsto wait. Negative values mean to use
the system default timeout.
:returns: The result of the invocation if successful.
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
response = await iterm2.rpc.async_invoke_function(
connection,
invocation,
timeout=timeout)
which = response.invoke_function_response.WhichOneof('disposition')
if which == 'error':
# pylint: disable=no-member
if (response.invoke_function_response.error.status ==
iterm2.api_pb2.InvokeFunctionResponse.Status.Value("TIMEOUT")):
raise iterm2.rpc.RPCException("Timeout")
raise iterm2.rpc.RPCException("{}: {}".format(
iterm2.api_pb2.InvokeFunctionResponse.Status.Name(
response.invoke_function_response.error.status),
response.invoke_function_response.error.error_reason))
return json.loads(response.invoke_function_response.success.json_result)
This invokes the RPC in the context of this session. Most user-defined
RPCs are invoked in a session context (for example, invocations
attached to triggers or key bindings). Default variables will be pulled
from that scope. If you call a function from the wrong context it may
fail because its defaults will not be set properly.
:param invocation: A function invocation string.
:param timeout: Max number of secondsto wait. Negative values mean to
use the system default timeout.
:returns: The result of the invocation if successful.
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
response = await iterm2.rpc.async_invoke_function(
self.connection,
invocation,
session_id=self.session_id,
timeout=timeout)
which = response.invoke_function_response.WhichOneof('disposition')
# pylint: disable=no-member
if which == 'error':
if (response.invoke_function_response.error.status ==
iterm2.api_pb2.InvokeFunctionResponse.Status.
Value("TIMEOUT")):
raise iterm2.rpc.RPCException("Timeout")
raise iterm2.rpc.RPCException("{}: {}".format(
iterm2.api_pb2.InvokeFunctionResponse.Status.Name(
response.invoke_function_response.error.status),
response.invoke_function_response.error.error_reason))
return json.loads(
This invokes the RPC in the context of this window. Note that most
user-defined RPCs expect to be invoked in the context of a session.
Default variables will be pulled from that scope. If you call a
function from the wrong context it may fail because its defaults will
not be set properly.
:param invocation: A function invocation string.
:param timeout: Max number of secondsto wait. Negative values mean to
use the system default timeout.
:returns: The result of the invocation if successful.
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
response = await iterm2.rpc.async_invoke_function(
self.connection,
invocation,
window_id=self.window_id,
timeout=timeout)
which = response.invoke_function_response.WhichOneof('disposition')
# pylint: disable=no-member
if which == 'error':
if (response.invoke_function_response.error.status ==
iterm2.api_pb2.InvokeFunctionResponse.Status.Value(
"TIMEOUT")):
raise iterm2.rpc.RPCException("Timeout")
raise iterm2.rpc.RPCException("{}: {}".format(
iterm2.api_pb2.InvokeFunctionResponse.Status.Name(
response.invoke_function_response.error.status),
response.invoke_function_response.error.error_reason))
return json.loads(
async def async_invoke_method(connection, receiver, invocation, timeout):
"""Convenience wrapper around async_invoke_function for methods."""
assert receiver
response = await iterm2.rpc.async_invoke_function(
connection,
invocation,
receiver=receiver,
timeout=timeout)
which = response.invoke_function_response.WhichOneof('disposition')
if which == 'error':
if (response.invoke_function_response.error.status ==
iterm2.api_pb2.InvokeFunctionResponse.Status.Value("TIMEOUT")):
raise iterm2.rpc.RPCException("Timeout")
raise iterm2.rpc.RPCException("{}: {}".format(
iterm2.api_pb2.InvokeFunctionResponse.Status.Name(
response.invoke_function_response.error.status),
response.invoke_function_response.error.error_reason))
return json.loads(response.invoke_function_response.success.json_result)
This invokes the RPC in the context of this tab. Note that most
user-defined RPCs expect to be invoked in the context of a session.
Default variables will be pulled from that scope. If you call a
function from the wrong context it may fail because its defaults will
not be set properly.
:param invocation: A function invocation string.
:param timeout: Max number of secondsto wait. Negative values mean to
use the system default timeout.
:returns: The result of the invocation if successful.
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
response = await iterm2.rpc.async_invoke_function(
self.connection,
invocation,
tab_id=self.tab_id,
timeout=timeout)
which = response.invoke_function_response.WhichOneof('disposition')
if which == 'error':
# pylint: disable=no-member
if (response.invoke_function_response.error.status ==
iterm2.api_pb2.InvokeFunctionResponse.Status.
Value("TIMEOUT")):
raise iterm2.rpc.RPCException("Timeout")
raise iterm2.rpc.RPCException("{}: {}".format(
iterm2.api_pb2.InvokeFunctionResponse.Status.Name(
response.invoke_function_response.error.status),
response.invoke_function_response.error.error_reason))
return json.loads(