SAMPIntegratedClient#
- class astropy.samp.SAMPIntegratedClient(name=None, description=None, metadata=None, addr=None, port=0, callable=True)[源代码]#
基类:
object
一个简单的SAMP客户端。
该类旨在简化客户端的使用,提供一个代理类来合并
SAMPClient
和SAMPHubProxy
简化API中的功能。- 参数:
- name :
str
,可选Python:字符串,可选 客户名称(对应于
samp.name
元数据关键字)。- description :
str
,可选Python:字符串,可选 客户描述(对应于
samp.description.text
元数据关键字)。- metadata :
dict
,可选Python:Dict,可选 标准SAMP格式的客户端应用程序元数据。
- addr :
str
,可选Python:字符串,可选 监听地址(或IP)。如果无法访问internet,则默认为127.0.0.1,否则默认为主机名。
- port :
int
,可选PYTHON:int,可选 正在侦听XML-RPC服务器套接字端口。如果left设置为0(默认值),操作系统将选择一个空闲端口。
- callable : bool ,可选可选的布尔
客户端是否可以接收呼叫和通知。如果设置为
False
,则客户端可以发送通知和呼叫,但不能接收任何通知和呼叫。
- name :
属性摘要
用于验证客户端与正在运行的集线器的连接的测试方法。
方法总结
bind_receive_call
(mtype, function[, ...])将特定的MType调用绑定到函数或类方法。
bind_receive_message
(mtype, function[, ...])将特定的MType绑定到函数或类方法,用于调用或通知。
bind_receive_notification
(mtype, function[, ...])将特定的MType通知绑定到函数或类方法。
bind_receive_response
(msg_tag, function)将特定的msg标记响应绑定到函数或类方法。
call
(recipient_id, msg_tag, message)代理人
call
SAMP Hub方法。call_all
(msg_tag, message)代理人
callAll
SAMP Hub方法。call_and_wait
(recipient_id, message, timeout)代理人
callAndWait
SAMP Hub方法。connect
([hub, hub_params, pool_size])连接当前或指定的SAMP集线器,启动并注册客户端。
declare_metadata
\(元数据)代理人
declareMetadata
SAMP Hub方法。declare_subscriptions
([subscriptions])声明客户端希望订阅的MType,用MType绑定方法隐式定义
bind_receive_notification()
和bind_receive_call()
.disconnect
\()从当前SAMP集线器注销客户机,停止该客户机并断开与集线器的连接。
ecall
(recipient_id, msg_tag, mtype, **params)易于使用的版本
call()
.ecall_all
(msg_tag, mtype, **params)易于使用的版本
call_all()
.ecall_and_wait
(recipient_id, mtype, timeout, ...)易于使用的版本
call_and_wait()
.enotify
(recipient_id, mtype, **params)易于使用的版本
notify()
.enotify_all
(mtype, **params)易于使用的版本
notify_all()
.ereply
(msg_id, status[, result, error])易于使用的版本
reply()
.get_metadata
(client_id)代理人
getMetadata
SAMP Hub方法。get_private_key
\()返回用于在注册时获得的标准配置文件通信的客户端私钥 (
samp.private-key
)get_public_id
\()返回注册时获得的公共客户端ID (
samp.self-id
)代理人
getRegisteredClients
SAMP Hub方法。get_subscribed_clients
\(mtype)代理人
getSubscribedClients
SAMP Hub方法。get_subscriptions
(client_id)代理人
getSubscriptions
SAMP Hub方法。notify
(recipient_id, message)代理人
notify
SAMP Hub方法。notify_all
\(消息)代理人
notifyAll
SAMP Hub方法。ping
\()代理人
ping
SAMP Hub方法(仅标准配置文件)。receive_call
(private_key, sender_id, msg_id, ...)标准可调用客户端
receive_call
方法。receive_notification
(private_key, sender_id, ...)标准可调用客户端
receive_notification
方法。receive_response
(private_key, responder_id, ...)标准可调用客户端
receive_response
方法。reply
(msg_id, response)代理人
reply
SAMP Hub方法。unbind_receive_call
(mtype[, declare])从调用绑定表中删除指定的MType并从中取消订阅客户端(如果需要)。
unbind_receive_notification
(mtype[, declare])从通知绑定表中删除指定的MType,并从中取消订阅客户端(如果需要)。
unbind_receive_response
(msg_tag)从响应绑定表中删除指定的消息标记。
属性文档
方法文件
- bind_receive_call(mtype, function, declare=True, metadata=None)[源代码]#
将特定的MType调用绑定到函数或类方法。
函数的格式必须为:
def my_function_or_method(<self,> private_key, sender_id, msg_id, mtype, params, extra)
在哪里?
private_key
是客户端私钥,sender_id
是通知发件人ID,msg_id
是集线器消息id,mtype
是消息MType,params
是否设置了消息参数(的内容"samp.params"
)extra
是包含任何额外消息映射项的字典。默认情况下,客户机自动声明为订阅MType。- 参数:
- mtype :
str
Python :字符串 要捕获的MType。
- function :
callable()
Python:Callable() 在以下情况下要使用的应用程序函数
mtype
收到。- declare : bool ,可选可选的布尔
指定是否必须将客户端自动声明为已订阅MType(另请参阅
declare_subscriptions()
)- metadata :
dict
,可选Python:Dict,可选 包含要声明与订阅的MType关联的附加元数据的字典(另请参阅
declare_subscriptions()
)
- mtype :
- bind_receive_message(mtype, function, declare=True, metadata=None)[源代码]#
将特定的MType绑定到函数或类方法,用于调用或通知。
函数的格式必须为:
def my_function_or_method(<self,> private_key, sender_id, msg_id, mtype, params, extra)
在哪里?
private_key
是客户端私钥,sender_id
是通知发件人ID,msg_id
是集线器消息id(仅调用,否则为None
)mtype
是消息MType,params
是否设置了消息参数(的内容"samp.params"
)extra
是包含任何额外消息映射项的字典。默认情况下,客户机自动声明为订阅MType。- 参数:
- mtype :
str
Python :字符串 要捕获的MType。
- function :
callable()
Python:Callable() 在以下情况下要使用的应用程序函数
mtype
收到。- declare : bool ,可选可选的布尔
指定是否必须将客户端自动声明为已订阅MType(另请参阅
declare_subscriptions()
)- metadata :
dict
,可选Python:Dict,可选 包含要声明与订阅的MType关联的附加元数据的字典(另请参阅
declare_subscriptions()
)
- mtype :
- bind_receive_notification(mtype, function, declare=True, metadata=None)[源代码]#
将特定的MType通知绑定到函数或类方法。
函数的格式必须为:
def my_function_or_method(<self,> private_key, sender_id, mtype, params, extra)
在哪里?
private_key
是客户端私钥,sender_id
是通知发件人ID,mtype
是消息MType,params
是否设置了通知消息参数(的内容"samp.params"
)extra
是包含任何额外消息映射项的字典。默认情况下,客户机自动声明为订阅MType。- 参数:
- mtype :
str
Python :字符串 要捕获的MType。
- function :
callable()
Python:Callable() 在以下情况下要使用的应用程序函数
mtype
收到。- declare : bool ,可选可选的布尔
指定是否必须将客户端自动声明为已订阅MType(另请参阅
declare_subscriptions()
)- metadata :
dict
,可选Python:Dict,可选 包含要声明与订阅的MType关联的附加元数据的字典(另请参阅
declare_subscriptions()
)
- mtype :
- bind_receive_response(msg_tag, function)[源代码]#
将特定的msg标记响应绑定到函数或类方法。
函数的格式必须为:
def my_function_or_method(<self,> private_key, responder_id, msg_tag, response)
在哪里?
private_key
是客户端私钥,responder_id
是消息响应程序ID,msg_tag
是否在呼叫时提供消息标签,以及response
是收到的响应。- 参数:
- msg_tag :
str
Python :字符串 要捕获的消息标记。
- function :
callable()
Python:Callable() 在以下情况下要使用的应用程序函数
msg_tag
收到。
- msg_tag :
- connect(hub=None, hub_params=None, pool_size=20)[源代码]#
连接当前或指定的SAMP集线器,启动并注册客户端。
- 参数:
- hub :
SAMPHubServer
可选SAMPHubServer,可选 要连接到的集线器。
- hub_params :
dict
,可选Python:Dict,可选 包含要连接的集线器的锁定文件内容的可选字典。这本词典有
{{<token-name>: <token-string>, ...}}
.- pool_size :
int
,可选PYTHON:int,可选 为与集线器通信而打开的套接字连接数。
- hub :
- declare_subscriptions(subscriptions=None)[源代码]#
声明客户端希望订阅的MType,用MType绑定方法隐式定义
bind_receive_notification()
和bind_receive_call()
.可选的
subscriptions
映射可以添加到传递给declare_subscriptions()
方法。- 参数:
- subscriptions :
dict
,可选Python:Dict,可选 包含要订阅的mtype列表的字典,其格式与
subscriptions
地图传递给declare_subscriptions()
方法。
- subscriptions :
- ecall(recipient_id, msg_tag, mtype, **params)[源代码]#
易于使用的版本
call()
.这是一个代理
call
方法,该方法允许以简化的方式发送调用消息。请注意,保留
extra_kws
关键字是一种特殊含义的词典,除了标准之外,还用来添加额外的关键字samp.mtype
和samp.params
,发送的消息。- 参数:
实例
>>> from astropy.samp import SAMPIntegratedClient >>> cli = SAMPIntegratedClient() >>> ... >>> msgid = cli.ecall("abc", "xyz", "samp.msg.progress", ... txt = "initialization", percent = "10", ... extra_kws = {"my.extra.info": "just an example"})
- ecall_all(msg_tag, mtype, **params)[源代码]#
易于使用的版本
call_all()
.这是一个代理
callAll
方法,该方法允许以简化的方式发送调用消息。请注意,保留
extra_kws
关键字是一种特殊含义的词典,除了标准之外,还用来添加额外的关键字samp.mtype
和samp.params
,发送的消息。- 参数:
实例
>>> from astropy.samp import SAMPIntegratedClient >>> cli = SAMPIntegratedClient() >>> ... >>> msgid = cli.ecall_all("xyz", "samp.msg.progress", ... txt = "initialization", percent = "10", ... extra_kws = {"my.extra.info": "just an example"})
- ecall_and_wait(recipient_id, mtype, timeout, **params)[源代码]#
易于使用的版本
call_and_wait()
.这是一个代理
callAndWait
方法,该方法允许以简化的方式发送调用消息。请注意,保留
extra_kws
关键字是一种特殊含义的词典,除了标准之外,还用来添加额外的关键字samp.mtype
和samp.params
,发送的消息。- 参数:
实例
>>> from astropy.samp import SAMPIntegratedClient >>> cli = SAMPIntegratedClient() >>> ... >>> cli.ecall_and_wait("xyz", "samp.msg.progress", "5", ... txt = "initialization", percent = "10", ... extra_kws = {"my.extra.info": "just an example"})
- enotify(recipient_id, mtype, **params)[源代码]#
易于使用的版本
notify()
.这是一个代理
notify
方法,该方法允许以简化的方式发送通知消息。请注意,保留
extra_kws
关键字是一种特殊含义的词典,除了标准之外,还用来添加额外的关键字samp.mtype
和samp.params
,发送的消息。- 参数:
实例
>>> from astropy.samp import SAMPIntegratedClient >>> cli = SAMPIntegratedClient() >>> ... >>> cli.enotify("samp.msg.progress", msgid = "xyz", txt = "initialization", ... percent = "10", extra_kws = {"my.extra.info": "just an example"})
- enotify_all(mtype, **params)[源代码]#
易于使用的版本
notify_all()
.这是一个代理
notifyAll
方法,该方法允许以简化的方式发送通知消息。请注意,保留
extra_kws
关键字是一种特殊含义的词典,除了标准之外,还用来添加额外的关键字samp.mtype
和samp.params
,发送的消息。- 参数:
实例
>>> from astropy.samp import SAMPIntegratedClient >>> cli = SAMPIntegratedClient() >>> ... >>> cli.enotify_all("samp.msg.progress", txt = "initialization", ... percent = "10", ... extra_kws = {"my.extra.info": "just an example"})
- ereply(msg_id, status, result=None, error=None)[源代码]#
易于使用的版本
reply()
.这是一个代理
reply
方法,该方法允许以简化的方式发送答复消息。- 参数:
实例
>>> from astropy.samp import SAMPIntegratedClient, SAMP_STATUS_ERROR >>> cli = SAMPIntegratedClient() >>> ... >>> cli.ereply("abd", SAMP_STATUS_ERROR, result={}, ... error={"samp.errortxt": "Test error message"})
- get_private_key()[源代码]#
返回用于在注册时获得的标准配置文件通信的客户端私钥 (
samp.private-key
)- 返回:
- key :
str
Python :字符串 私钥客户端。
- key :
- receive_call(private_key, sender_id, msg_id, message)[源代码]#
标准可调用客户端
receive_call
方法。当
bind_receive_call()
方法用于将不同的操作绑定到多个类型。如果自定义的可调用客户端实现继承自SAMPClient
类应重写此方法。备注
重写时,此方法必须始终返回字符串结果(甚至为空)。
- receive_notification(private_key, sender_id, message)[源代码]#
标准可调用客户端
receive_notification
方法。当
bind_receive_notification()
方法用于将不同的操作绑定到多个类型。如果自定义的可调用客户端实现继承自SAMPClient
类应重写此方法。备注
重写时,此方法必须始终返回字符串结果(甚至为空)。
- receive_response(private_key, responder_id, msg_tag, response)[源代码]#
标准可调用客户端
receive_response
方法。当
bind_receive_response()
方法用于将不同的操作绑定到多个类型。如果自定义的可调用客户端实现继承自SAMPClient
类应重写此方法。备注
重写时,此方法必须始终返回字符串结果(甚至为空)。
- unbind_receive_call(mtype, declare=True)[源代码]#
从调用绑定表中删除指定的MType并从中取消订阅客户端(如果需要)。
- 参数:
- mtype :
str
Python :字符串 要删除的MType。
- declare : bool布尔
指定是否必须将客户端自动声明为从MType取消订阅(另请参见
declare_subscriptions()
)
- mtype :
- unbind_receive_notification(mtype, declare=True)[源代码]#
从通知绑定表中删除指定的MType,并从中取消订阅客户端(如果需要)。
- 参数:
- mtype :
str
Python :字符串 要删除的MType。
- declare : bool布尔
指定是否必须将客户端自动声明为从MType取消订阅(另请参见
declare_subscriptions()
)
- mtype :