本文整理汇总了Python中message.Message.parse方法的典型用法代码示例。如果您正苦于以下问题:Python Message.parse方法的具体用法?Python Message.parse怎么用?Python Message.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message.Message
的用法示例。
在下文中一共展示了Message.parse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: receiveData
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def receiveData(self):
data, addr = self.sock.recvfrom( 1024 )
#prints a string but crashes on OSC msg
#print("received: " + data.decode("utf-8"))
m = Message()
m.parse(data)
return m
示例2: handle_message
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def handle_message(self, data, *args, **kwargs):
""" message handler. """
if '<delay xmlns="urn:xmpp:delay"' in str(data): logging.debug("ignoring delayed message") ; return
m = Message()
m.parse(data, self)
if m.type == 'groupchat' and m.subject:
logging.debug("%s - checking topic" % self.cfg.name)
self.topiccheck(m)
nm = Message(m)
callbacks.check(self, nm)
return
if m.isresponse:
logging.debug("%s - message is a response" % self.cfg.name)
return
jid = None
m.origjid = m.jid
#if self.cfg.user in m.jid or (m.groupchat and self.cfg.nick == m.nick):
# logging.error("%s - message to self .. ignoring" % self.cfg.name)
# return 0
if self.cfg.fulljids and not m.msg:
utarget = self.userhosts.get(m.nick)
if utarget: m.userhost = m.jid = m.auth = stripped(utarget)
else: m.userhost = m.jid
if m.msg: m.userhost = stripped(m.userhost)
logging.debug("using %s as userhost" % m.userhost)
m.dontbind = False
self.put(m)
示例3: handle_message
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def handle_message(self, data):
""" message handler. """
m = Message(data)
m.parse(self)
if data.type == 'groupchat' and data.subject:
logging.debug("%s - checking topic" % self.name)
self.topiccheck(m)
nm = Message(m)
callbacks.check(self, nm)
return
if data.get('x').xmlns == 'jabber:x:delay':
logging.warn("%s - ignoring delayed message" % self.name)
return
self.privwait.check(m)
if m.isresponse:
logging.debug("%s - message is a response" % self.name)
return
jid = None
m.origjid = m.jid
for node in m.subelements:
try: m.jid = node.x.item.jid
except (AttributeError, TypeError): continue
if self.me in m.fromm:
logging.debug("%s - message to self .. ignoring" % self.name)
return 0
try:
if m.type == 'error':
if m.code:
logging.error('%s - error - %s' % (self.name, str(m)))
self.errorwait.check(m)
self.errorHandler(m)
except Exception, ex:
handle_exception()
示例4: do_call
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [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)
示例5: read_message
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def read_message(self):
while self._running:
# If we have a message in buffer already, return it
if len(self._buffer) >= 5 and len(self._buffer) >= self._buffer[1] + 4:
packet = self._buffer[:self._buffer[1] + 4]
self._buffer = self._buffer[self._buffer[1] + 4:]
return Message.parse(packet)
# Otherwise, read some data and call the function again
else:
data = self._driver.read()
self._buffer.extend(data)
_logger.debug("Read data: %s (now have %s in buffer)",
format_list(data), format_list(self._buffer))
示例6: _socket_receive_loop
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def _socket_receive_loop(self):
""" Receives data from socket forever. """
while True:
if self._stop_requested:
return
try:
data_bytes = self._socket.recv(UDP_RECEIVE_BUFFER_SIZE)
if self._stop_requested:
return
except:
pass
else:
msg = Message.parse(bytearray(data_bytes))
self._transition_message(msg, MessageState.to_be_received)
self.fsm_event.set()
示例7: read_message
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def read_message(self):
# If we have a message in buffer already, return it
if len(self._buffer) >= 5 and len(self._buffer) >= self._buffer[1] + 4:
packet = self._buffer[:self._buffer[1] + 4]
self._buffer = self._buffer[self._buffer[1] + 4:]
return Message.parse(packet)
# Otherwise, read some data and call the function again
else:
data = self._in.read(4096)
self._buffer.extend(data)
if debug_protocol:
_logger.debug("Read data: %s (now have %s in buffer)",
format_list(data), format_list(self._buffer))
return self.read_message()
示例8: handle_message
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def handle_message(self, data):
""" message handler. """
m = Message(data)
m.parse(self)
if data.type == 'groupchat' and data.subject:
logging.debug("%s - checking topic" % self.cfg.name)
self.topiccheck(m)
nm = Message(m)
callbacks.check(self, nm)
return
if data.get('x').xmlns == 'jabber:x:delay':
logging.debug("%s - ignoring delayed message" % self.cfg.name)
return
if m.isresponse:
logging.debug("%s - message is a response" % self.cfg.name)
return
jid = None
m.origjid = m.jid
for node in m.subelements:
try: m.jid = node.x.item.jid
except (AttributeError, TypeError): continue
if self.cfg.user in m.fromm or (m.groupchat and self.cfg.nick == m.nick):
logging.debug("%s - message to self .. ignoring" % self.cfg.name)
return 0
if self.cfg.fulljids:
utarget = self.userhosts.get(m.nick)
if utarget: m.userhost = m.jid = m.auth = stripped(utarget)
else: m.userhost = m.jid
logging.warn("using %s as userhost" % m.userhost)
try:
if m.type == 'error':
if m.code:
logging.error('%s - error - %s' % (self.cfg.name, str(m)))
self.errorHandler(m)
except Exception, ex:
handle_exception()
示例9: handle_data
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def handle_data(self, buf):
self.bufs.append(buf)
while len(self.bufs) > 0:
try:
request, remaining_buf = Message.parse("".join(self.bufs))
except MessageIncomplete:
return True
except MessageInvalid, e:
raise ServerCommunicationError(e)
self.bufs = [remaining_buf, ]
fname = request['name']
args = request['args']
kwargs = request['kwargs']
func_name = 'handle_%s' % fname
if self.server.handler_kwargs:
callee = self.server.handler(**self.server.handler_kwargs)
else:
callee = self.server.handler()
callee.data = request
callee.address = self.address
callee.connection = self
callee.prepare()
if hasattr(callee, func_name):
try:
result = getattr(callee, func_name)(*args, **kwargs)
except Exception, e:
#raise # for debugging purposes
response = Message({
'status': 'exception',
'text': unicode(e)
})
else:
response = Message({
'status': 'ok',
'result': result
})
示例10: TestMessage
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
class TestMessage(unittest.TestCase):
MENTION = '@test_mention'
MENTION_RESULT = 'test_mention'
EMOTICON = '(test_emoticon)'
EMOTICON_RESULT = 'test_emoticon'
LINK = 'http://example.com'
LINK_TITLE = 'Example Domain'
def setUp(self):
self.message = Message()
def test_message_len(self):
message_len = Message.MAX_MESSAGE_LEN + 1
self.message = Message(rstr.rstr(string.ascii_letters,
message_len))
self.assertEqual(len(self.message.message), Message.MAX_MESSAGE_LEN)
message_len = Message.MAX_MESSAGE_LEN
self.message = Message(rstr.rstr(string.ascii_letters,
message_len))
self.assertEqual(len(self.message.message), Message.MAX_MESSAGE_LEN)
message_len = Message.MAX_MESSAGE_LEN - 1
self.message = Message(rstr.rstr(string.ascii_letters,
message_len))
self.assertEqual(len(self.message.message), message_len)
def test_parse_mention(self):
self.message = Message(TestMessage.MENTION)
result = self.message.parse()
mention_dict = {'mentions': [TestMessage.MENTION_RESULT]}
self.assertEqual(result, mention_dict)
embedded_mention = '[email protected]'
self.message = Message(embedded_mention)
result = self.message.parse()
self.assertEqual(result, {})
def test_parse_emoticon(self):
min_emoticon = '(a)'
self.message = Message(min_emoticon)
result = self.message.parse()
emoticon_dict = {'emoticons': ['a']}
self.assertEqual(result, emoticon_dict)
max_emoticon = '(aaaaaaaaaaaaaaa)'
self.message = Message(max_emoticon)
result = self.message.parse()
emoticon_dict = {'emoticons': ['aaaaaaaaaaaaaaa']}
self.assertEqual(result, emoticon_dict)
embedded_emoticon = 'bbb(a)bbb(x)bbb(a)bbb'
self.message = Message(embedded_emoticon)
result = self.message.parse()
emoticon_dict = {'emoticons': ['a', 'x', 'a']}
self.assertEqual(result, emoticon_dict)
def test_parse_not_emoticon(self):
no_emoticon = '()'
self.message = Message(no_emoticon)
result = self.message.parse()
self.assertEqual(result, {})
long_emoticon = '(aaaaaaaaaaaaaaaa)'
self.message = Message(long_emoticon)
result = self.message.parse()
self.assertEqual(result, {})
def test_parse_link(self):
self.message = Message(TestMessage.LINK)
result = self.message.parse()
link_dict = {'links': [{'title': TestMessage.LINK_TITLE,
'url': TestMessage.LINK}]}
self.assertEqual(result, link_dict)
def test_parse(self):
self.message.message = ' '.join([TestMessage.MENTION,
TestMessage.EMOTICON,
TestMessage.LINK])
result = self.message.parse()
message_dict = {'mentions': [TestMessage.MENTION_RESULT],
'emoticons': [TestMessage.EMOTICON_RESULT],
'links': [{'title': TestMessage.LINK_TITLE,
'url': TestMessage.LINK}]}
self.assertEqual(result, message_dict)
def test_get_link(self):
result = self.message.get_link(TestMessage.LINK)
link_dict = {'url': TestMessage.LINK,
'title': TestMessage.LINK_TITLE}
self.assertEqual(result, link_dict)
def test_get_title(self):
title = self.message.get_title(TestMessage.LINK)
self.assertEqual(title, TestMessage.LINK_TITLE)
def test_get_title_unavailable(self):
title = self.message.get_title('http://example')
self.assertEqual(title, None)
示例11: test_basic
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def test_basic(self):
m = Message('PRIVMSG #foo :this is a test message')
m.parse()
self.assertEqual(m.command, 'PRIVMSG')
self.assertEqual(m.params[0], '#foo')
self.assertEqual(m.params[1], 'this is a test message')
示例12: test_escape_colon
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import parse [as 别名]
def test_escape_colon(self):
m = Message('PRIVMSG #foo :test: completed')
m.parse()
self.assertEqual(m.command, 'PRIVMSG')
self.assertEqual(m.params[0], '#foo')
self.assertEqual(m.params[1], 'test: completed')