本文整理汇总了Python中message.Message方法的典型用法代码示例。如果您正苦于以下问题:Python message.Message方法的具体用法?Python message.Message怎么用?Python message.Message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message
的用法示例。
在下文中一共展示了message.Message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def parse(self):
list_of_messages = []
set_of_senders = set()
for l in self.raw_messages:
content = l["message"].encode("utf-8")
sender = l["from"].encode("utf-8")
datetime_str = l["datetime"].encode("utf-8")
date, time = datetime_str.split("T")
time = time.replace("+0000", "")
msg_date = date + " " + time
datetime_obj = datetime.strptime(msg_date, "%Y-%m-%d %H:%M:%S")
set_of_senders.add(sender)
list_of_messages.append(message.Message(sender, content, date, time, datetime_obj))
return list(set_of_senders), list_of_messages
示例2: _get_pose
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def _get_pose(self):
msg = Message()
msg.id = CommunicationProtocolIDs.GET_POSE
response = self._send_command(msg)
self.x = struct.unpack_from('f', response.params, 0)[0]
self.y = struct.unpack_from('f', response.params, 4)[0]
self.z = struct.unpack_from('f', response.params, 8)[0]
self.r = struct.unpack_from('f', response.params, 12)[0]
self.j1 = struct.unpack_from('f', response.params, 16)[0]
self.j2 = struct.unpack_from('f', response.params, 20)[0]
self.j3 = struct.unpack_from('f', response.params, 24)[0]
self.j4 = struct.unpack_from('f', response.params, 28)[0]
if self.verbose:
print("pydobot: x:%03.1f \
y:%03.1f \
z:%03.1f \
r:%03.1f \
j1:%03.1f \
j2:%03.1f \
j3:%03.1f \
j4:%03.1f" %
(self.x, self.y, self.z, self.r, self.j1, self.j2, self.j3, self.j4))
return response
示例3: update_share
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def update_share(self, team_id, user_id):
"""
Update onboarding welcome message after recieving a "message" event
with an "is_share" attachment from Slack. Update timestamp for
welcome message.
Parameters
----------
team_id : str
id of the Slack team associated with the incoming event
user_id : str
id of the Slack user associated with the incoming event
"""
# These updated attachments use markdown and emoji to mark the
# onboarding task as complete
completed_attachments = {"text": ":white_check_mark: "
"~*Share this Message*~ "
":mailbox_with_mail:",
"color": "#439FE0"}
# Grab the message object we want to update by team id and user id
message_obj = self.messages[team_id].get(user_id)
# Update the message's attachments by switching in incomplete
# attachment with the completed one above.
message_obj.share_attachment.update(completed_attachments)
# Update the message in Slack
post_message = self.client.api_call("chat.update",
channel=message_obj.channel,
ts=message_obj.timestamp,
text=message_obj.text,
attachments=message_obj.attachments
)
# Update the timestamp saved on the message object
message_obj.timestamp = post_message["ts"]
示例4: route
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def route(self, msg: Message) -> None:
return await self.router.route(msg)
示例5: send_query
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def send_query(self, msg: Message) -> None:
query_msg = Message({
'@type': ProtocolDiscovery.QUERY,
'query': msg['query']
})
await self.agent.send_message_to_agent(msg['did'], query_msg)
await self.agent.send_admin_message(
Message({
'@type': AdminProtocolDiscovery.QUERY_SENT,
'from': msg['did']
})
)
示例6: query_received
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def query_received(self, msg: Message) -> None:
await self.agent.send_admin_message(
Message({
'@type': AdminProtocolDiscovery.QUERY_RECEIVED,
'from': msg.context['from_did']
})
)
matching_modules = []
def map_query(char):
if char == '*':
return '.*'
return char
query = ''.join(list(map(map_query, msg['query'])))
for module in self.agent.modules.keys():
matches = re.match(query, module)
if matches:
matching_modules.append(module)
disclose_msg = Message({
'@type': ProtocolDiscovery.DISCLOSE,
'~thread': {'thid': msg.id},
'protocols': list(map(lambda mod: {'pid': mod}, matching_modules)),
})
await self.agent.send_message_to_agent(msg.context['from_did'], disclose_msg)
await self.agent.send_admin_message(
Message({
'@type': AdminProtocolDiscovery.DISCLOSE_SENT,
'from': msg.context['from_did']
})
)
示例7: disclose_received
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def disclose_received(self, msg: Message) -> None:
await self.agent.send_admin_message(
Message({
'@type': AdminProtocolDiscovery.DISCLOSE_RECEIVED,
'from': msg.context['from_did'],
'protocols': msg['protocols']
})
)
示例8: validate
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def validate(query):
validate_message(
[
('@type', ProtocolDiscovery.Message.QUERY),
'@id',
'query'
],
query
)
示例9: build
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def build(thid: str, supported_families: [str]):
return Message({
'@type': ProtocolDiscovery.Message.DISCLOSE,
'~thread': {'thid': thid},
'protocols': list(map(lambda mod: {'pid': mod}, supported_families))
})
示例10: worker
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def worker(self):
try:
while True:
queue = self.work.get()
frame = queue.get()
channel = self.channel(frame.channel)
if frame.method_type.content:
content = read_content(queue)
else:
content = None
self.delegate(channel, Message(channel, frame, content))
except QueueClosed, e:
self.closed(str(e) or "worker closed")
示例11: invoke_reliable
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def invoke_reliable(self, frame, content = None):
if not self.synchronous:
future = Future()
self.request(frame, future.put_response, content)
if not frame.method.responses: return None
else: return future
self.request(frame, self.queue_response, content)
if not frame.method.responses:
if self.use_execution_layer and frame.method_type.is_l4_command():
self.execution_sync()
self.completion.wait()
if self._closed:
raise Closed(self.reason)
return None
try:
resp = self.responses.get()
if resp.method_type.content:
return Message(self, resp, read_content(self.responses))
else:
return Message(self, resp)
except QueueClosed, e:
if self._closed:
raise Closed(self.reason)
else:
raise e
# used for 0-8 and 0-10
示例12: parse
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def parse(self):
list_of_messages = []
set_of_senders = set()
for l in self.raw_messages:
msg_date, sep, msg = l.partition(": ")
raw_date, sep, time = msg_date.partition(" ")
sender, sep, content = msg.partition(": ")
raw_date = raw_date.replace(",", "")
year = raw_date.split(" ")[0].split("/")[-1]
# The following lines treats:
# 3/24/14 1:59:59 PM
# 24/3/14 13:59:59 PM
# Couldn't we use msg_date instead of chatTimeString here?
# colonIndex = [x.start() for x in re.finditer(':', l)]
# print l, colonIndex
# chatTimeString = l[0:colonIndex[2]]
# This ignores a minority of bad formatted lines using try/except block.
# an execption is raised when the datetime_obj is not created due to date parsing error
try:
if "AM" in msg_date or "PM" in msg_date:
datetime_obj = datetime.strptime(
msg_date, "%m/%d/%y, %I:%M:%S %p")
else:
if len(year) == 2:
datetime_obj = datetime.strptime(msg_date, "%m/%d/%y %H:%M:%S")
else:
datetime_obj = datetime.strptime(msg_date, "%m/%d/%Y %H:%M:%S")
except ValueError:
continue
set_of_senders.add(sender)
list_of_messages.append(message.Message(sender, content, raw_date, time, datetime_obj))
return list(set_of_senders), list_of_messages
示例13: _get_queued_cmd_current_index
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def _get_queued_cmd_current_index(self):
msg = Message()
msg.id = CommunicationProtocolIDs.GET_QUEUED_CMD_CURRENT_INDEX
response = self._send_command(msg)
idx = struct.unpack_from('L', response.params, 0)[0]
return idx
示例14: _read_message
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def _read_message(self):
time.sleep(0.1)
b = self.ser.read_all()
if len(b) > 0:
msg = Message(b)
if self.verbose:
print('pydobot: <<', msg)
return msg
return
示例15: _set_cp_cmd
# 需要导入模块: import message [as 别名]
# 或者: from message import Message [as 别名]
def _set_cp_cmd(self, x, y, z):
msg = Message()
msg.id = CommunicationProtocolIDs.SET_CP_CMD
msg.ctrl = ControlValues.THREE
msg.params = bytearray(bytes([0x01]))
msg.params.extend(bytearray(struct.pack('f', x)))
msg.params.extend(bytearray(struct.pack('f', y)))
msg.params.extend(bytearray(struct.pack('f', z)))
msg.params.append(0x00)
return self._send_command(msg)