本文整理汇总了Python中session.Session.send方法的典型用法代码示例。如果您正苦于以下问题:Python Session.send方法的具体用法?Python Session.send怎么用?Python Session.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.send方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stopProcess
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import send [as 别名]
def stopProcess(address, port, dbPassword):
s = Session(address, port=port, service="Monitor")
s.authorize("Cloud", dbPassword)
s.doConnect()
s.send("<Request Action=\"shutdown\"/>")
s.close()
示例2: queryEngine
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import send [as 别名]
def queryEngine(address, port, target, dbPassword, msgBody=None):
s = Session(address, port=port, service="Query")
s.authorize("Cloud", dbPassword)
s.doConnect()
msg = "<Query Target=\"%s\"/>" % target
if msgBody is not None:
xml = ElementTree.fromstring(msg)
xml.append(msgBody)
msg = ElementTree.tostring(xml)
s.send(msg)
response = s.recv()
checkForError(response)
s.close()
return response
示例3: Domain
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import send [as 别名]
class Domain(BaseListener):
"""Represents the NuoDB domain.
The domain is the top level NuoDB management object. The domain object
provides access to the peers and databases that are contained within.
"""
def __init__(self, broker_addr, domain_user, domain_pwd, listener=None):
"""
@type broker_addr str
@type domain_user str
@type domain_pwd str
@type listener
"""
if not domain_pwd:
raise Exception("A password is required to join a domain")
self.__session = Session(broker_addr, service="Monitor")
self.__session.authorize(domain_user, domain_pwd)
self.__user = domain_user
self.__password = domain_pwd
self.__listener = listener
self.__peers = dict()
""" @type : dict[str, Peer] """
self.__databases = dict()
""" @type : dict[str, Database] """
self.__monitor = SessionMonitor(self.__session, self)
# These will be set in handle status after joining the domain
self.__domain_name = None
""" @type : str """
self.__entry_peer = None
""" @type : Peer """
try:
self.__session.doConnect()
self.__handle_status(self.__session.recv())
except Exception:
self.__monitor.close()
raise
self.__monitor.start()
def __str__(self):
return self.domain_name + " [Entered through: " + self.entry_peer.connect_str + "]"
def disconnect(self):
"""Disconnect from the domain."""
self.__monitor.close()
def _send_domain_message(self, service, attributes=None, text=None, children=None):
session = Session(self.__entry_peer.address, port=self.__entry_peer.port, service=service)
session.authorize(self.__user, self.__password)
return session.doRequest(attributes, text, children)
@property
def user(self):
"""Return the domain user."""
return self.__user
@property
def password(self):
"""Return the domain password."""
return self.__password
@property
def domain_name(self):
"""Return the domain name."""
return self.__domain_name
def find_peer(self, address):
"""
Find a peer by address
@type: address str
@rtype: Peer
"""
def get_peer(self, agent_id):
"""
Return a peer for a given agent_id.
@type agent_id str
@rtype: Peer
"""
return self.__peers.get(agent_id)
@property
def peers(self):
"""
Return a list of all peers in the domain.
@rtype: list[Peer]
"""
return self.__peers.values()
@property
def entry_peer(self):
"""
Return the peer that was used to enter the domain.
@rtype: Peer
#.........这里部分代码省略.........
示例4: Domain
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import send [as 别名]
#.........这里部分代码省略.........
self,
self.__session.getAddress(),
root.get("AgentId"),
(root.get("Role") == "Broker"),
self.__session.getPort(),
root.get("Hostname"),
root.get("Version"),
)
self.__peerJoined(self.__entryPeer)
for child in list(root):
if child.tag == "Broker":
self.__peerJoined(Peer.fromMessage(self, child))
for child in list(root):
if child.tag == "Database":
name = child.get("Name")
if self.__listener:
try:
self.__listener.databaseJoined(self.__databases[name])
except:
pass
for processElement in list(child):
if processElement.tag == "Process":
if name not in self.__databases:
self.__databases[name] = Database(self, name)
self.__processJoined(Process.fromMessage(self.__databases[name], processElement), None)
def __peerJoined(self, peer):
self.__peers[peer.getId()] = peer
if self.__listener:
try:
self.__listener.peerJoined(peer)
except:
pass
def __peerLeft(self, peer):
del self.__peers[peer.getId()]
if self.__listener:
try:
self.__listener.peerLeft(peer)
except:
pass
def __processJoined(self, process, startId):
process.getDatabase()._addProcess(process)
process.getPeer()._notifyStartId(startId, process)
if self.__listener:
try:
self.__listener.processJoined(process)
except:
pass
def __processLeft(self, process):
database = process.getDatabase()
database._removeProcess(process)
process.getPeer()._removeProcess(process)
if self.__listener:
try:
self.__listener.processLeft(process)
except:
pass
if database.getProcessCount() == 0:
del self.__databases[database.getName()]
if self.__listener:
try:
self.__listener.databaseLeft(database)
except:
pass
def __processFailed(self, peer, startId, reason):
peer._notifyStartId(startId, reason)
if self.__listener:
try:
self.__listener.processFailed(peer, reason)
except:
pass
def __processStatusChanged(self, process, status):
process._setStatus(status)
if self.__listener:
try:
self.__listener.processStatusChanged(process, status)
except:
pass
# an initial verison only to support the shutdown routine that doesn't
# need to watch for return messages ... right now this module is only
# supporting the tests, which don't need the other management routines
# at this point, so we'll flesh this out (as in the Java implementation)
# in the second round when other utilites get updated as well
def _sendManagementMessage(self, message, peer, process):
root = ElementTree.fromstring(
'<ManagementRequest AgentId="%s" ProcessId="%i"/>' % (peer.getId(), process.getPid())
)
root.append(message)
self.__session.send(ElementTree.tostring(root))