##// END OF EJS Templates
Fixing docstrings and a few more places for msg_id/msg_type.
Brian E. Granger -
Show More
@@ -1165,7 +1165,7 b' class Hub(SessionFactory):'
1165 msg = self.session.msg(header['msg_type'])
1165 msg = self.session.msg(header['msg_type'])
1166 msg['content'] = rec['content']
1166 msg['content'] = rec['content']
1167 msg['header'] = header
1167 msg['header'] = header
1168 msg['msg_id'] = rec['msg_id']
1168 msg['header']['msg_id'] = rec['msg_id']
1169 self.session.send(self.resubmit, msg, buffers=rec['buffers'])
1169 self.session.send(self.resubmit, msg, buffers=rec['buffers'])
1170
1170
1171 finish(dict(status='ok'))
1171 finish(dict(status='ok'))
@@ -350,15 +350,15 b' class Session(Configurable):'
350 def msg_header(self, msg_type):
350 def msg_header(self, msg_type):
351 return msg_header(self.msg_id, msg_type, self.username, self.session)
351 return msg_header(self.msg_id, msg_type, self.username, self.session)
352
352
353 def msg(self, msg_type, content=None, parent=None, subheader=None):
353 def msg(self, msg_type, content=None, parent=None, subheader=None, header=None):
354 """Return the nested message dict.
354 """Return the nested message dict.
355
355
356 This format is different from what is sent over the wire. The
356 This format is different from what is sent over the wire. The
357 self.serialize method converts this nested message dict to the wire
357 serialize/unserialize methods converts this nested message dict to the wire
358 format, which uses a message list.
358 format, which is a list of message parts.
359 """
359 """
360 msg = {}
360 msg = {}
361 msg['header'] = self.msg_header(msg_type)
361 msg['header'] = self.msg_header(msg_type) if header is None else header
362 msg['parent_header'] = {} if parent is None else extract_header(parent)
362 msg['parent_header'] = {} if parent is None else extract_header(parent)
363 msg['content'] = {} if content is None else content
363 msg['content'] = {} if content is None else content
364 sub = {} if subheader is None else subheader
364 sub = {} if subheader is None else subheader
@@ -436,8 +436,8 b' class Session(Configurable):'
436
436
437 return to_send
437 return to_send
438
438
439 def send(self, stream, msg_or_type, content=None, parent=None, ident=None,
439 def send(self, stream, msg_or_type, content=None, parent=None, ident=None
440 buffers=None, subheader=None, track=False):
440 buffers=None, subheader=None, track=False, header=None):
441 """Build and send a message via stream or socket.
441 """Build and send a message via stream or socket.
442
442
443 The message format used by this function internally is as follows:
443 The message format used by this function internally is as follows:
@@ -445,37 +445,41 b' class Session(Configurable):'
445 [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content,
445 [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content,
446 buffer1,buffer2,...]
446 buffer1,buffer2,...]
447
447
448 The self.serialize method converts the nested message dict into this
448 The serialize/unserialize methods convert the nested message dict into this
449 format.
449 format.
450
450
451 Parameters
451 Parameters
452 ----------
452 ----------
453
453
454 stream : zmq.Socket or ZMQStream
454 stream : zmq.Socket or ZMQStream
455 the socket-like object used to send the data
455 The socket-like object used to send the data.
456 msg_or_type : str or Message/dict
456 msg_or_type : str or Message/dict
457 Normally, msg_or_type will be a msg_type unless a message is being
457 Normally, msg_or_type will be a msg_type unless a message is being
458 sent more than once.
458 sent more than once.
459
459
460 content : dict or None
460 content : dict or None
461 the content of the message (ignored if msg_or_type is a message)
461 The content of the message (ignored if msg_or_type is a message).
462 header : dict or None
463 The header dict for the message (ignores if msg_to_type is a message).
462 parent : Message or dict or None
464 parent : Message or dict or None
463 the parent or parent header describing the parent of this message
465 The parent or parent header describing the parent of this message
466 (ignored if msg_or_type is a message).
464 ident : bytes or list of bytes
467 ident : bytes or list of bytes
465 the zmq.IDENTITY routing path
468 The zmq.IDENTITY routing path.
466 subheader : dict or None
469 subheader : dict or None
467 extra header keys for this message's header
470 Extra header keys for this message's header (ignored if msg_or_type
471 is a message).
468 buffers : list or None
472 buffers : list or None
469 the already-serialized buffers to be appended to the message
473 The already-serialized buffers to be appended to the message.
470 track : bool
474 track : bool
471 whether to track. Only for use with Sockets,
475 Whether to track. Only for use with Sockets, because ZMQStream
472 because ZMQStream objects cannot track messages.
476 objects cannot track messages.
473
477
474 Returns
478 Returns
475 -------
479 -------
476 msg : message dict
480 msg : dict
477 the constructed message
481 The constructed message.
478 (msg,tracker) : (message dict, MessageTracker)
482 (msg,tracker) : (dict, MessageTracker)
479 if track=True, then a 2-tuple will be returned,
483 if track=True, then a 2-tuple will be returned,
480 the first element being the constructed
484 the first element being the constructed
481 message, and the second being the MessageTracker
485 message, and the second being the MessageTracker
@@ -488,12 +492,13 b' class Session(Configurable):'
488 raise TypeError("ZMQStream cannot track messages")
492 raise TypeError("ZMQStream cannot track messages")
489
493
490 if isinstance(msg_or_type, (Message, dict)):
494 if isinstance(msg_or_type, (Message, dict)):
491 # we got a Message, not a msg_type
495 # We got a Message or message dict, not a msg_type so don't
492 # don't build a new Message
496 # build a new Message.
493 msg = msg_or_type
497 msg = msg_or_type
494 else:
498 else:
495 msg = self.msg(msg_or_type, content, parent, subheader)
499 msg = self.msg(msg_or_type, content=content, parent=parent,
496
500 subheader=subheader, header=header)
501
497 buffers = [] if buffers is None else buffers
502 buffers = [] if buffers is None else buffers
498 to_send = self.serialize(msg, ident)
503 to_send = self.serialize(msg, ident)
499 flag = 0
504 flag = 0
@@ -523,7 +528,7 b' class Session(Configurable):'
523 msg['tracker'] = tracker
528 msg['tracker'] = tracker
524
529
525 return msg
530 return msg
526
531
527 def send_raw(self, stream, msg_list, flags=0, copy=True, ident=None):
532 def send_raw(self, stream, msg_list, flags=0, copy=True, ident=None):
528 """Send a raw message via ident path.
533 """Send a raw message via ident path.
529
534
@@ -545,7 +550,7 b' class Session(Configurable):'
545 ident = [ident]
550 ident = [ident]
546 if ident is not None:
551 if ident is not None:
547 to_send.extend(ident)
552 to_send.extend(ident)
548
553
549 to_send.append(DELIM)
554 to_send.append(DELIM)
550 to_send.append(self.sign(msg_list))
555 to_send.append(self.sign(msg_list))
551 to_send.extend(msg_list)
556 to_send.extend(msg_list)
General Comments 0
You need to be logged in to leave comments. Login now