예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
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
예제 #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
예제 #6
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
예제 #7
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
예제 #8
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
예제 #9
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