DebugClients/Python/DebugClientBase.py

branch
maintenance
changeset 6004
548a9ba8c970
parent 5966
3325ecd87c7c
child 6040
dcf8c50ed06a
--- a/DebugClients/Python/DebugClientBase.py	Sun Nov 19 13:06:01 2017 +0100
+++ b/DebugClients/Python/DebugClientBase.py	Sat Dec 02 12:40:22 2017 +0100
@@ -187,7 +187,6 @@
         """
         self.breakpoints = {}
         self.redirect = True
-        self.__receiveBuffer = ""
         
         # special objects representing the main scripts thread and frame
         self.mainThread = self
@@ -355,23 +354,6 @@
         
         return code
     
-    def handleLine(self, line):
-        """
-        Public method to handle the receipt of a complete line.
-
-        It first looks for a valid protocol token at the start of the line.
-        Thereafter it trys to execute the lines accumulated so far.
-        
-        @param line the received line
-        """
-        # Remove any newline.
-        if line[-1] == '\n':
-            line = line[:-1]
-
-##        printerr(line)          ##debug
-        
-        self.handleJsonCommand(line)
-    
     def handleJsonCommand(self, jsonStr):
         """
         Public method to handle a command serialized as a JSON string.
@@ -379,9 +361,12 @@
         @param jsonStr string containing the command received from the IDE
         @type str
         """
+##        printerr(jsonStr)          ##debug
+        
         try:
             commandDict = json.loads(jsonStr.strip())
         except (TypeError, ValueError) as err:
+            printerr("Error handling command: " + jsonStr)
             printerr(str(err))
             return
         
@@ -393,12 +378,14 @@
         
         if method == "RequestVariables":
             self.__dumpVariables(
-                params["frameNumber"], params["scope"], params["filters"])
+                params["frameNumber"], params["scope"], params["filters"],
+                params["maxSize"])
         
         elif method == "RequestVariable":
             self.__dumpVariable(
                 params["variable"], params["frameNumber"],
-                params["scope"], params["filters"])
+                params["scope"], params["filters"],
+                params["maxSize"])
         
         elif method == "RequestThreadList":
             self.dumpThreadList()
@@ -1029,23 +1016,17 @@
         @param stream file like object that has data to be written
         """
         try:
-            got = stream.readline_p()
+            self.lockClient()
+            command = stream.readCommand()
+            self.unlockClient()
         except Exception:
             return
 
-        if len(got) == 0:
+        if len(command) == 0:
             self.sessionClose()
             return
-
-        self.__receiveBuffer = self.__receiveBuffer + got
-
-        # Call handleLine for the line if it is complete.
-        eol = self.__receiveBuffer.find('\n')
-        while eol >= 0:
-            line = self.__receiveBuffer[:eol + 1]
-            self.__receiveBuffer = self.__receiveBuffer[eol + 1:]
-            self.handleLine(line)
-            eol = self.__receiveBuffer.find('\n')
+        
+        self.handleJsonCommand(command)
 
     def writeReady(self, stream):
         """
@@ -1321,15 +1302,20 @@
         # reset coding
         self.__coding = self.defaultCoding
 
-    def __dumpVariables(self, frmnr, scope, filterList):
+    def __dumpVariables(self, frmnr, scope, filterList, maxSize):
         """
         Private method to return the variables of a frame to the debug server.
         
         @param frmnr distance of frame reported on. 0 is the current frame
-            (int)
-        @param scope 1 to report global variables, 0 for local variables (int)
+        @type int
+        @param scope 1 to report global variables, 0 for local variables
+        @type int
         @param filterList the indices of variable types to be filtered
-            (list of int)
+        @type list of int
+        @param maxSize maximum size the formatted value of a variable will
+            be shown. If it is bigger than that, a 'too big' indication will
+            be given.
+        @type int
         """
         if self.currentThread is None:
             return
@@ -1362,7 +1348,7 @@
             keylist = varDict.keys()
             
             vlist = self.__formatVariablesList(
-                keylist, varDict, scope, filterList)
+                keylist, varDict, scope, filterList, maxSize=maxSize)
             varlist.extend(vlist)
         
         self.sendJsonCommand("ResponseVariables", {
@@ -1370,17 +1356,21 @@
             "variables": varlist,
         })
     
-    def __dumpVariable(self, var, frmnr, scope, filterList):
+    def __dumpVariable(self, var, frmnr, scope, filterList, maxSize):
         """
         Private method to return the variables of a frame to the debug server.
         
         @param var list encoded name of the requested variable
-            (list of strings)
+        @type list of strings
         @param frmnr distance of frame reported on. 0 is the current frame
-            (int)
+        @type int
         @param scope 1 to report global variables, 0 for local variables (int)
         @param filterList the indices of variable types to be filtered
-            (list of int)
+        @type list of int
+        @param maxSize maximum size the formatted value of a variable will
+            be shown. If it is bigger than that, a 'too big' indication will
+            be given.
+        @type int
         """
         if self.currentThread is None:
             return
@@ -1429,7 +1419,8 @@
                 elif resolver:
                     varDict = resolver.getDictionary(variable)
                     vlist = self.__formatVariablesList(
-                        list(varDict.keys()), varDict, scope, filterList)
+                        list(varDict.keys()), varDict, scope, filterList,
+                        maxSize=maxSize)
                     varlist.extend(vlist)
         
         self.sendJsonCommand("ResponseVariable", {
@@ -1600,7 +1591,7 @@
         return varlist
     
     def __formatVariablesList(self, keylist, dict_, scope, filterList=None,
-                              formatSequences=False):
+                              formatSequences=False, maxSize=0):
         """
         Private method to produce a formated variables list.
         
@@ -1610,21 +1601,31 @@
         expressions. The formated variables list (a list of tuples of 3
         values) is returned.
         
-        @param keylist keys of the dictionary
+        @param keylist keys of the dictionary to be formatted
+        @type list of str
         @param dict_ the dictionary to be scanned
+        @type dict
         @param scope 1 to filter using the globals filter, 0 using the locals
-            filter (int).
+            filter.
             Variables are only added to the list, if their name do not match
             any of the filter expressions.
+        @type int
         @param filterList the indices of variable types to be filtered.
             Variables are only added to the list, if their type is not
             contained in the filter list.
+        @type list of int
         @param formatSequences flag indicating, that sequence or dictionary
             variables should be formatted. If it is 0 (or false), just the
-            number of items contained in these variables is returned. (boolean)
+            number of items contained in these variables is returned.
+        @type bool
+        @param maxSize maximum size the formatted value of a variable will
+            be shown. If it is bigger than that, a 'too big' indication will
+            be placed in the value field.
+        @type int
         @return A tuple consisting of a list of formatted variables. Each
             variable entry is a tuple of three elements, the variable name,
             its type and value.
+        @rtype list of tuple of (str, str, str)
         """
         filterList = [] if filterList is None else filterList[:]
         
@@ -1724,6 +1725,8 @@
                         if valtype.startswith('class') and \
                            rvalue[0] in ['{', '(', '[']:
                             rvalue = ""
+                        elif maxSize and len(rvalue) > maxSize:
+                            rvalue = "@@TOO_BIG_TO_SHOW@@"
                 except Exception:
                     rvalue = ''
             
@@ -2047,7 +2050,7 @@
                 redirect = True
             elif sys.argv[2] == "False":
                 redirect = False
-            else: 
+            else:
                 try:
                     redirect = int(sys.argv[2])
                 except (ValueError, IndexError):

eric ide

mercurial