本文整理汇总了Python中message.Message.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python Message.serialize方法的具体用法?Python Message.serialize怎么用?Python Message.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message.Message
的用法示例。
在下文中一共展示了Message.serialize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lineReceived
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
def lineReceived(self, line):
""" """
message = json.loads(line)
log.msg("Receiver received message {0}".format(message))
if message['command'] == session.beginMsg:
ok = self.teilerWindow.questionMessage(message['fileName'], "peer")
log.msg("OK is {0}".format(ok))
if ok == "no":
log.msg("Download rejected")
rejectMessage = Message(session.rejectMsg)
self.transport.write(rejectMessage.serialize() + '\r\n')
elif ok == "yes":
log.msg("The file is accepted!")
self.teiler.dlSessions.add(message['sessionID'])
acceptMessage = Message(session.acceptMsg)
self.transport.write(acceptMessage.serialize() + '\r\n')
elif message['command'] == session.dirMsg:
dirName = message['dirName']
msgSession = message['sessionID']
if message['sessionID'] in self.teiler.dlSessions:
reactor.callLater(0, utils.createDirectory, self.teiler.downloadPath + dirName)
receivedMessage = Message(session.receivedMsg)
self.transport.write(receivedMessage.serialize() + '\r\n')
else:
log.msg("Dir Message was not in a proper session!")
self.transport.loseConnection()
elif message['command'] == session.fileMsg:
self.fileName = message['fileName']
self.fileSize = message['fileSize']
self.sessionID = message['sessionID']
log.msg("Vals are filename: {0}, filesize: {1}, sessionID: {2}".format(self.fileName, self.fileSize, self.sessionID))
if message['sessionID'] in self.teiler.dlSessions:
self.outFile = open(self.teiler.downloadPath + self.fileName, 'wb+')
log.msg("Saving file to {0}".format(self.outFile))
self.setRawMode()
else:
log.msg("File Message was not in a proper session!")
self.transport.loseConnection()
elif message['command'] == session.endMsg:
msgSession = message['sessionID']
if msgSession in self.teiler.dlSessions:
log.msg("EOT message received!")
''' Commenting out for now '''
self.teiler.dlSessions.remove(msgSession)
self.transport.loseConnection()
else:
log.msg("EOT Message was not in a proper session!")
self.transport.loseConnection()
else:
log.msg("Command not recognized.")
示例2: do_call
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
def do_call(*args, **kwargs):
data = {
'name': name,
'args': args,
'kwargs': kwargs,
}
data.update(self.env)
request = Message(data)
# Send request
self.send(request.serialize())
# Receive response
bufs = []
while True:
try:
buf = self.recv()
except ClientException, e:
raise ClientCommunicationError(e)
if not buf:
raise ClientCommunicationError('Server hang up.')
bufs.append(buf)
try:
response, _ = Message.parse("".join(bufs))
except MessageIncomplete:
continue
except MessageInvalid, e:
raise ClientCommunicationError(e)
示例3: test_deserialize
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
def test_deserialize(self):
m = Message("irc", "complete_nick!foobar", "channel_name", "BaZ: message contents", 10)
m2 = Message(serialized_str=m.serialize())
self.assertEquals(m.serialize(), m2.serialize())
m3 = Message(serialized_str="10 @@@ irc @@@ complete_nick!foobar @@@ channel_name @@@ BaZ: message contents")
self.assertEquals(m.serialize(), m3.serialize())
示例4: test_serialize
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
def test_serialize(self):
m = Message("irc", "complete_nick!foobar", "channel_name", "BaZ: message contents", 10)
self.assertEquals(m.serialize(), "10 @@@ irc @@@ complete_nick!foobar @@@ channel_name @@@ BaZ: message contents")
示例5: Message
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
#raise # for debugging purposes
response = Message({
'status': 'exception',
'text': unicode(e)
})
else:
response = Message({
'status': 'ok',
'result': result
})
else:
response = Message({
'status': 'notfound'
})
self.send(response.serialize())
class RPCServerHandler(object):
def prepare(self):
return
class RPCServerException(Exception): pass
class ServerCommunicationError(RPCServerException): pass
class RPCServer(Server):
CONNECTION_CLASS = RPCServerConnection
def __init__(self, *args, **kwargs):
self.handler = kwargs.pop('handler')
if kwargs.has_key('handler_kwargs'):
self.handler_kwargs = kwargs.pop('handler_kwargs')
示例6: sendReceivedMessage
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
def sendReceivedMessage(self):
receivedMessage = Message(session.receivedMsg)
self.transport.write(receivedMessage.serialize() + '\r\n')
示例7: test_serialize
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import serialize [as 别名]
def test_serialize(self):
serialString = "{\"sessionID\": \"" + self.sessionID + "\", \"command\": \"" + self.testCommand + "\"}"
mesg = Message(self.testCommand, self.sessionID)
self.assertEqual(serialString, mesg.serialize())