本文整理汇总了Python中message.Message.id方法的典型用法代码示例。如果您正苦于以下问题:Python Message.id方法的具体用法?Python Message.id怎么用?Python Message.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message.Message
的用法示例。
在下文中一共展示了Message.id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import id [as 别名]
def send(self, fr, to=[], subj="", msg="", attach=[], ttl=50, reply="", headers={}, no_multipart=False,
content_type=[]):
#def send(self, *args, **kwargs):# attach item must be a tuple (data, filename, content_type, content_subtype)
self.__load_config()
if not self.smtp_server:
return None
self.__sem.lock()
try:
x = self.__id
if self.smtp_sender and self.smtp_sender.find("@")!=-1:
sender = self.smtp_sender
else:
sender = self.smtp_user
if isinstance(fr, Message):
m = fr
m.from_email = "%s <%s>"%(m.from_email,sender)
else:
#if isinstance(to, str) or isinstance(to, unicode):
# to = to.split(",")
sender = "%s <%s>"%(fr,sender)
m = {"from": sender, "to": to, "subj": subj, "msg": msg, "attach": attach,
"ttl": ttl, "headers": headers, "no_multipart": no_multipart}
if reply:
m['reply'] = reply
if len(content_type) > 0:
m['content_type'] = content_type[0]
if len(content_type) > 1:
m['content_charset'] = content_type[1]
if len(content_type) > 2:
m['content_params'] = content_type[2]
m = Message(**m)
m.id = x
self.__queue.append(m)
self.__id += 1
return x
finally:
self.__sem.unlock()
示例2: parseMessage
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import id [as 别名]
def parseMessage(self, messageNode):
fmsg = Message()
msg_id = messageNode.getAttributeValue('id')
attribute_t = messageNode.getAttributeValue('t')
fromAttribute = messageNode.getAttributeValue('from')
author = messageNode.getAttributeValue('author')
typeAttribute = messageNode.getAttributeValue('type')
if fromAttribute is not None and msg_id is not None:
fmsg.id = msg_id
fmsg.remote = fromAttribute
if typeAttribute == 'error':
message = None
errorCode = 0
errorNodes = messageNode.getAllChildren('error')
for errorNode in errorNodes:
codeString = errorNode.getAttributeValue('code')
try:
errorCode = int(codeString)
except ValueError:
message = None
if message is not None:
message.status = 7
self.connection.event.message_error(message, errorCode)
elif typeAttribute == 'subject':
receiptRequested = False
requestNodes = messageNode.getAllChildren('request')
for requestNode in requestNodes:
if requestNode.getAttributeValue('xmlns') == 'urn:xmpp:receipts':
receiptRequested = True
bodyNode = messageNode.getChild('body')
subject = (None if bodyNode is None else bodyNode.data)
if subject is not None:
self.connection.event.newGroupSubject.emit(group=fromAttribute, author=author, subject=subject)
if receiptRequested:
self.connection.event.subjectReceiptRequested(fromAttribute, msg_id)
elif typeAttribute == 'chat':
wants_receipt = False
messageChildren = ([] if messageNode.children
is None else messageNode.children)
if author:
fmsg.author = author
for childNode in messageChildren:
if ProtocolTreeNode.tagEquals(childNode, 'composing'):
if self.connection.event is not None:
self.connection.event.typing_received(fromAttribute)
elif ProtocolTreeNode.tagEquals(childNode, 'paused'):
if self.connection.event is not None:
self.connection.event.paused_received(fromAttribute)
elif ProtocolTreeNode.tagEquals(childNode,"media") and msg_id is not None:
fmsg.type = "media"
url = messageNode.getChild("media").getAttributeValue("url");
fmsg.media_type = media_type = messageNode.getChild("media").getAttributeValue("type")
data = {}
if media_type == "image":
data['preview'] = messageNode.getChild("media").data
data['url'] = url
elif media_type == "audio":
data['url'] = url
elif media_type == "video":
data['url'] = url
elif media_type == "location":
data['latitude'] = messageNode.getChild("media").getAttributeValue("latitude")
data['longitude'] = messageNode.getChild("media").getAttributeValue("longitude")
data['preview'] = messageNode.getChild("media").data
elif media_type == "vcard":
data['contact'] = messageNode.getChild("media").data
else:
continue
fmsg.data = data
elif ProtocolTreeNode.tagEquals(childNode, 'body') and msg_id is not None:
fmsg.type = "chat"
fmsg.data = childNode.data
elif not ProtocolTreeNode.tagEquals(childNode, 'active'):
if ProtocolTreeNode.tagEquals(childNode, 'request'):
fmsg.wants_receipt = True
elif ProtocolTreeNode.tagEquals(childNode, 'notify'):
fmsg.notify_name = childNode.getAttributeValue('name')
elif ProtocolTreeNode.tagEquals(childNode, 'x'):
xmlns = childNode.getAttributeValue('xmlns')
if 'jabber:x:delay' == xmlns:
continue
stamp_str = \
childNode.getAttributeValue('stamp')
if stamp_str is not None:
stamp = stamp_str
fmsg.timestamp = stamp
fmsg.offline = True
else:
#.........这里部分代码省略.........