Example #1
0
 def project_config(self):
   try:
     src = open(self.project_file()).read() if self.project_file() else "()"
     conf = sexp.read(src)
     return conf
   except StandardError:
     return []
Example #2
0
 def receive_loop(self):
   while self.connected:
     try:
       res = self.client.recv(4096)
       print "RECV: " + unicode(res, "utf-8")
       if res:
         len_str = res[:6]
         msglen = int(len_str, 16) + 6
         msg = res[6:msglen]
         nxt = strip(res[msglen:])
         while len(nxt) > 0 or len(msg) > 0:
           form = sexp.read(msg)
           sublime.set_timeout(functools.partial(self.handler.on_data, form), 0)
           if len(nxt) > 0:
             msglen = int(nxt[:6], 16) + 6
             msg = nxt[6:msglen]
             nxt = strip(nxt[msglen:])
           else: 
             msg = ""
             msglen = ""
       else:
         self.set_connected(False)
     except Exception as e:
       print "*****    ERROR     *****"
       print e
       self.handler.on_disconnect("server")
       self.set_connected(False)
Example #3
0
 def receive_loop(self):
   #TODO: possibly use a smaller buffer but allow for recomposing a message
   #      from multiple buffers in case they overflow.
   while self.connected:
     try:
       res = self.client.recv(2048 * 1024)
       print "RECV: " + unicode(res, "utf-8")
       if res:
         msglen = int(res[:6], 16) + 6
         msg = res[6:msglen]
         nxt = strip(res[msglen:])
         while len(nxt) > 0 or len(msg) > 0:
           form = sexp.read(msg)
           sublime.set_timeout(functools.partial(self.handler.on_data, form), 0)
           if len(nxt) > 0:
             msglen = int(nxt[:6], 16) + 6
             msg = nxt[6:msglen]
             nxt = strip(nxt[msglen:])
           else: 
             msg = ""
             msglen = ""
       else:
         self.set_connected(False)
     except Exception as e:
       print "*****    ERROR     *****"
       print e
       self.handler.on_disconnect("server")
       self.set_connected(False)
Example #4
0
 def receive_loop(self):
     while self.connected:
         try:
             res = self.client.recv(4096)
             print "RECV: " + unicode(res, "utf-8")
             if res:
                 len_str = res[:6]
                 msglen = int(len_str, 16) + 6
                 msg = res[6:msglen]
                 nxt = strip(res[msglen:])
                 while len(nxt) > 0 or len(msg) > 0:
                     form = sexp.read(msg)
                     sublime.set_timeout(
                         functools.partial(self.handler.on_data, form), 0)
                     if len(nxt) > 0:
                         msglen = int(nxt[:6], 16) + 6
                         msg = nxt[6:msglen]
                         nxt = strip(nxt[msglen:])
                     else:
                         msg = ""
                         msglen = ""
             else:
                 self.set_connected(False)
         except Exception as e:
             print "*****    ERROR     *****"
             print e
             self.handler.on_disconnect("server")
             self.set_connected(False)
Example #5
0
 def project_config(self):
     try:
         src = open(
             self.project_file()).read() if self.project_file() else "()"
         conf = sexp.read(src)
         return conf
     except StandardError:
         return []
Example #6
0
    def sync_send(self, request, msg_id):
        self._connect_lock.acquire()
        try:
            s = socket.socket()
            s.connect(("127.0.0.1", self.port()))
            try:
                s.send(request)
                result = ""
                keep_going = True
                nxt = ""
                while keep_going:
                    res = nxt + s.recv(4096)
                    msglen = int(res[:6], 16) + 6
                    msg = res[6:msglen]
                    if (len(msg) + 6) == msglen:
                        nxt = strip(res[msglen:])
                        while len(nxt) > 0 or len(msg) > 0:
                            if len(nxt) > 0:
                                sublime.set_timeout(
                                    functools.partial(self.handler.on_data,
                                                      sexp.read(msg)), 0)
                                msglen = int(nxt[:6], 16) + 6
                                msg = nxt[6:msglen]
                                nxt = strip(nxt[msglen:])
                            else:
                                nxt = ""
                                break
                        result = sexp.read(msg)
                        keep_going = result == None or msg_id != result[-1]
                        if keep_going:
                            sublime.set_timeout(
                                functools.partial(self.handler.on_data,
                                                  result), 0)
                    else:
                        nxt = res

                return result
            except Exception as error:
                print error
            finally:
                if s:
                    s.close()
        except Exception as error:
            print error
        finally:
            self._connect_lock.release()
Example #7
0
 def sync_send(self, request, msg_id): 
   self._connect_lock.acquire()
   try:
     s = socket.socket()
     s.connect(("127.0.0.1", self.port()))
     try:
       s.send(request)
       result = ""
       keep_going = True
       nxt = ""
       while keep_going: 
         res = nxt + s.recv(4096)
         msglen = int(res[:6], 16) + 6
         msg = res[6:msglen]
         if (len(msg) + 6) == msglen:
           nxt = strip(res[msglen:])
           while len(nxt) > 0 or len(msg) > 0:
             if len(nxt) > 0:
               sublime.set_timeout(functools.partial(self.handler.on_data, sexp.read(msg)), 0)
               msglen = int(nxt[:6], 16) + 6
               msg = nxt[6:msglen]
               nxt = strip(nxt[msglen:])
             else: 
               nxt = ""
               break
           result = sexp.read(msg)
           keep_going = result == None or msg_id != result[-1]
           if keep_going:
             sublime.set_timeout(functools.partial(self.handler.on_data, result), 0)
         else:
           nxt = res 
           
       return result
     except Exception as error:
       print error
     finally:
       if s: 
         s.close() 
   except Exception as error:
     print error
   finally:
     self._connect_lock.release()
Example #8
0
 def handle(self):
     print "Handling..."
     cur_thread = threading.currentThread()
     sys.stdout.flush()
     while True:
         data_len = int(self.request.recv(6), 16)
         print "Looking for " + str(data_len) + " bytes"
         data = self.request.recv(data_len)
         print "Sexp str: " + str(data)
         parsed_sexp = sexp.read(data)
         print "Sexp: " + str(parsed_sexp)
         self.handle_sexp(parsed_sexp)
Example #9
0
	def checkDecode(self, swankStr, parseFn):
		form = sexp.read(swankStr)
		result = parseFn(form)
		self.assertNotEqual(result, None)
Example #10
0
 def checkDecode(self, swank_str, parse_fn):
     form = sexp.read(swank_str)
     result = parse_fn(form)
     self.assertNotEqual(result, None)