Beispiel #1
0
class Stderr(SON):
    """
    Stderr Message
    
    Message Arguments:
        bytes -- None
    """
    type = 2
    
    def __init__(self, bytes, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(2, _hsid, 0, _hflags)
        self.type = 2
        self['t'] = 2
        self['bytes'] = bytes
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #2
0
class Done(SON):
    """
    Done Message
    """
    type = 99
    
    def __init__(self, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(99, _hsid, 0, _hflags)
        self.type = 99
        self['t'] = 99
        
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #3
0
class Source(SON):
    """
    Source Message
    
    Message Arguments:
        object -- None
        format -- None
        obj_found -- None (default: False)
        source -- None (default: None)
    """
    type = 145
    
    def __init__(self, object, format, obj_found=False, source=None, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(145, _hsid, 0, _hflags)
        self.type = 145
        self['t'] = 145
        self['object'] = object
        self['format'] = format
        self['obj_found'] = obj_found
        self['source'] = source
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #4
0
class Interrupt(SON):
    """
    Interrupt a computation
    
    Message Arguments:
        timeout -- Time in seconds to wait before responding No (default: 1.0)
    """
    type = 110
    
    def __init__(self, timeout=1.0, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(110, _hsid, 0, _hflags)
        self.type = 110
        self['t'] = 110
        self['timeout'] = timeout
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #5
0
class GetSource(SON):
    """
    GetSource Message
    
    Message Arguments:
        object -- None
        format -- None (default: TEXT)
    """
    type = 144
    
    def __init__(self, object, format='TEXT', _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(144, _hsid, 0, _hflags)
        self.type = 144
        self['t'] = 144
        self['object'] = object
        self['format'] = format
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #6
0
 def __init__(self, object, format='TEXT', _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(144, _hsid, 0, _hflags)
     self.type = 144
     self['t'] = 144
     self['object'] = object
     self['format'] = format
Beispiel #7
0
class Completions(SON):
    """
    Completions Message
    
    Message Arguments:
        text -- None
        format -- None
        completions -- None
    """
    type = 141
    
    def __init__(self, text, format, completions, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(141, _hsid, 0, _hflags)
        self.type = 141
        self['t'] = 141
        self['text'] = text
        self['format'] = format
        self['completions'] = completions
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #8
0
 def __init__(self, text, format='TEXT', _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(140, _hsid, 0, _hflags)
     self.type = 140
     self['t'] = 140
     self['text'] = text
     self['format'] = format
Beispiel #9
0
class GetCompletions(SON):
    """
    GetCompletions Message
    
    Message Arguments:
        text -- the text to complete
        format -- None (default: TEXT)
    """
    type = 140
    
    def __init__(self, text, format='TEXT', _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(140, _hsid, 0, _hflags)
        self.type = 140
        self['t'] = 140
        self['text'] = text
        self['format'] = format
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #10
0
 def __init__(self, text, format, completions, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(141, _hsid, 0, _hflags)
     self.type = 141
     self['t'] = 141
     self['text'] = text
     self['format'] = format
     self['completions'] = completions
Beispiel #11
0
 def __init__(self, object, format, obj_found=False, source=None, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(145, _hsid, 0, _hflags)
     self.type = 145
     self['t'] = 145
     self['object'] = object
     self['format'] = format
     self['obj_found'] = obj_found
     self['source'] = source
Beispiel #12
0
 def __init__(self, object, format, obj_found=False, doc=None, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(143, _hsid, 0, _hflags)
     self.type = 143
     self['t'] = 143
     self['object'] = object
     self['format'] = format
     self['obj_found'] = obj_found
     self['doc'] = doc
Beispiel #13
0
 def __init__(self, stderr, stack=None, etype=None, value=None, syntax=None, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(10, _hsid, 0, _hflags)
     self.type = 10
     self['t'] = 10
     self['stderr'] = stderr
     self['stack'] = stack
     self['etype'] = etype
     self['value'] = value
     self['syntax'] = syntax
Beispiel #14
0
 def __init__(self, source, cid=0, echo_stdin=True, displayhook='LAST', assignhook='NONE', print_ast=False, except_msg=False, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(120, _hsid, 0, _hflags)
     self.type = 120
     self['t'] = 120
     self['source'] = source
     self['cid'] = cid
     self['echo_stdin'] = echo_stdin
     self['displayhook'] = displayhook
     self['assignhook'] = assignhook
     self['print_ast'] = print_ast
     self['except_msg'] = except_msg
Beispiel #15
0
class ExecCell(SON):
    """
    ExecCell Message
    
    Message Arguments:
        source -- Source code of the cell to execute
        cid -- Cell id (default: 0)
        echo_stdin -- Output Stdin messages when Stdin is returned to the executing code (default: True)
        displayhook -- 
            'LAST': only the last expression.
            'ALL': All expressions
            'NONE': nothing. (default: LAST)
        assignhook -- 
            'ALL': print results of all assignments.
            'NONE': nothing. (default: NONE)
        print_ast -- If True, print the abstract syntax tree before executing. (default: False)
        except_msg -- If True, send an Except message when an exception occurs.  If False, print to stderr. (default: False)
    """
    type = 120
    
    def __init__(self, source, cid=0, echo_stdin=True, displayhook='LAST', assignhook='NONE', print_ast=False, except_msg=False, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(120, _hsid, 0, _hflags)
        self.type = 120
        self['t'] = 120
        self['source'] = source
        self['cid'] = cid
        self['echo_stdin'] = echo_stdin
        self['displayhook'] = displayhook
        self['assignhook'] = assignhook
        self['print_ast'] = print_ast
        self['except_msg'] = except_msg
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #16
0
 def feed(self, bytes):
     """
     Returns a list of DecodedMsg instances.
     """
     jbuf = self._jbuf
     jbuf.extend(bytes)
     msgs = []
     while True:
         if self._hdr is None:
             if len(jbuf) < HDR_LEN:
                 break
             hdrbytes = jbuf.popleft(HDR_LEN)
             self._hdr = Hdr.decode(hdrbytes)
         else:
             if len(jbuf) < self._hdr.length:
                 break
             bodybytes = jbuf.popleft(self._hdr.length)
             m = DecodedMsg(self._hdr, bodybytes)
             msgs.append(m)
             self._hdr = None
             
     return msgs
Beispiel #17
0
 def feed(self, bytes):
     callbacks = self._callbacks
     jbuf = self._jbuf
     jbuf.extend(bytes)
     while True:
         if self._hdr is None:
             if len(jbuf) < HDR_LEN:
                 break
             hdrbytes = jbuf.popleft(HDR_LEN)
             self._hdr = Hdr.decode(hdrbytes)
         else:
             if len(jbuf) < self._hdr.length:
                 break
             if self._hdr.type in callbacks:
                 bodybytes = jbuf.popleft(self._hdr.length)
                 m = DecodedMsg(self._hdr, bodybytes)
                 callbacks[self._hdr.type](m)
             elif self._log is not None:
                 jbuf.popleft(self._hdr.length, False)
                 self._log.warning("Unhandled message type=%d",
                                   self._hdr.type)
             self._hdr = None
Beispiel #18
0
class Except(SON):
    """
    Except Message
    
    Message Arguments:
        stderr -- None
        stack -- None (default: None)
        etype -- None (default: None)
        value -- None (default: None)
        syntax -- None (default: None)
    """
    type = 10
    
    def __init__(self, stderr, stack=None, etype=None, value=None, syntax=None, _hsid=0, _hflags=0):
        SON.__init__(self)
        self.hdr = Hdr(10, _hsid, 0, _hflags)
        self.type = 10
        self['t'] = 10
        self['stderr'] = stderr
        self['stack'] = stack
        self['etype'] = etype
        self['value'] = value
        self['syntax'] = syntax
        
    def as_reply_to(self, m):
        self.hdr.sid = m.hdr.sid
        self.hdr.flags |= HDRF_SCLOSE
        return self
        
    def encode(self):
        """
        Returns the encoded representation of this message.
        """
        bodybytes = _dict_to_bson(self, False)
        self.hdr.length = len(bodybytes)
        return self.hdr.encode() + bodybytes
Beispiel #19
0
 def __init__(self, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(101, _hsid, 0, _hflags)
     self.type = 101
     self['t'] = 101
Beispiel #20
0
 def __init__(self, bytes, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(2, _hsid, 0, _hflags)
     self.type = 2
     self['t'] = 2
     self['bytes'] = bytes
Beispiel #21
0
 def __init__(self, timeout=1.0, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(110, _hsid, 0, _hflags)
     self.type = 110
     self['t'] = 110
     self['timeout'] = timeout
Beispiel #22
0
 def __init__(self, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(99, _hsid, 0, _hflags)
     self.type = 99
     self['t'] = 99
Beispiel #23
0
 def __init__(self, nbytes, _hsid=0, _hflags=0):
     SON.__init__(self)
     self.hdr = Hdr(90, _hsid, 0, _hflags)
     self.type = 90
     self['t'] = 90
     self['nbytes'] = nbytes