src/eric7/DebugClients/Python/DebugClientBase.py

branch
eric7
changeset 10417
c6011e501282
parent 10331
c1a2ff7e3575
child 10423
299802979277
equal deleted inserted replaced
10416:5d807e997391 10417:c6011e501282
79 79
80 def DebugClientClose(fd): 80 def DebugClientClose(fd):
81 """ 81 """
82 Replacement for the standard os.close(fd). 82 Replacement for the standard os.close(fd).
83 83
84 @param fd open file descriptor to be closed (integer) 84 @param fd open file descriptor to be closed
85 @type int
85 """ 86 """
86 if DebugClientInstance is None: 87 if DebugClientInstance is None:
87 DebugClientOrigClose(fd) 88 DebugClientOrigClose(fd)
88 else: 89 else:
89 DebugClientInstance.close(fd) 90 DebugClientInstance.close(fd)
99 100
100 def DebugClientSetRecursionLimit(limit): 101 def DebugClientSetRecursionLimit(limit):
101 """ 102 """
102 Replacement for the standard sys.setrecursionlimit(limit). 103 Replacement for the standard sys.setrecursionlimit(limit).
103 104
104 @param limit recursion limit (integer) 105 @param limit recursion limit
106 @type int
105 """ 107 """
106 rl = max(limit, 64) 108 rl = max(limit, 64)
107 setRecursionLimit(rl) 109 setRecursionLimit(rl)
108 DebugClientOrigSetRecursionLimit(rl + 64) 110 DebugClientOrigSetRecursionLimit(rl + 64)
109 111
205 207
206 def getCoding(self): 208 def getCoding(self):
207 """ 209 """
208 Public method to return the current coding. 210 Public method to return the current coding.
209 211
210 @return codec name (string) 212 @return codec name
213 @rtype str
211 """ 214 """
212 return self.__coding 215 return self.__coding
213 216
214 def __setCoding(self, filename): 217 def __setCoding(self, filename):
215 """ 218 """
216 Private method to set the coding used by a python file. 219 Private method to set the coding used by a python file.
217 220
218 @param filename name of the file to inspect (string) 221 @param filename name of the file to inspect
222 @type str
219 """ 223 """
220 if self.noencoding: 224 if self.noencoding:
221 self.__coding = sys.getdefaultencoding() 225 self.__coding = sys.getdefaultencoding()
222 else: 226 else:
223 default = "utf-8" 227 default = "utf-8"
261 def sessionClose(self, terminate=True): 265 def sessionClose(self, terminate=True):
262 """ 266 """
263 Public method to close the session with the debugger and optionally 267 Public method to close the session with the debugger and optionally
264 terminate. 268 terminate.
265 269
266 @param terminate flag indicating to terminate (boolean) 270 @param terminate flag indicating to terminate
271 @type bool
267 """ 272 """
268 with contextlib.suppress(Exception): # secok 273 with contextlib.suppress(Exception): # secok
269 self.set_quit() 274 self.set_quit()
270 275
271 self.debugging = False 276 self.debugging = False
339 Public method to handle a command serialized as a JSON string. 344 Public method to handle a command serialized as a JSON string.
340 345
341 @param jsonStr string containing the command received from the IDE 346 @param jsonStr string containing the command received from the IDE
342 @type str 347 @type str
343 """ 348 """
344 ## printerr(jsonStr) ## debug # __IGNORE_WARNING_M891__ 349 ## printerr(jsonStr) ## debug # noqa: M891
345 350
346 try: 351 try:
347 commandDict = json.loads(jsonStr.strip()) 352 commandDict = json.loads(jsonStr.strip())
348 except (TypeError, ValueError) as err: 353 except (TypeError, ValueError) as err:
349 printerr("Error handling command: " + jsonStr) 354 printerr("Error handling command: " + jsonStr)
890 """ 895 """
891 Public method to signal the deletion of a temporary breakpoint. 896 Public method to signal the deletion of a temporary breakpoint.
892 897
893 @param filename name of the file the bp belongs to 898 @param filename name of the file the bp belongs to
894 @type str 899 @type str
895 @param lineno linenumber of the bp 900 @param lineno line number of the bp
896 @type int 901 @type int
897 """ 902 """
898 self.sendJsonCommand( 903 self.sendJsonCommand(
899 "ResponseClearBreakpoint", {"filename": filename, "line": lineno} 904 "ResponseClearBreakpoint", {"filename": filename, "line": lineno}
900 ) 905 )
1027 1032
1028 def __clientCapabilities(self): 1033 def __clientCapabilities(self):
1029 """ 1034 """
1030 Private method to determine the clients capabilities. 1035 Private method to determine the clients capabilities.
1031 1036
1032 @return client capabilities (integer) 1037 @return client capabilities
1038 @rtype int
1033 """ 1039 """
1034 if importlib.util.find_spec("PyProfile") is None: 1040 if importlib.util.find_spec("PyProfile") is None:
1035 return self.clientCapabilities & ~DebugClientCapabilities.HasProfiler 1041 return self.clientCapabilities & ~DebugClientCapabilities.HasProfiler
1036 else: 1042 else:
1037 return self.clientCapabilities 1043 return self.clientCapabilities
1086 def eventLoop(self, disablePolling=False): 1092 def eventLoop(self, disablePolling=False):
1087 """ 1093 """
1088 Public method implementing our event loop. 1094 Public method implementing our event loop.
1089 1095
1090 @param disablePolling flag indicating to enter an event loop with 1096 @param disablePolling flag indicating to enter an event loop with
1091 polling disabled (boolean) 1097 polling disabled
1098 @type bool
1092 """ 1099 """
1093 self.eventExit = False 1100 self.eventExit = False
1094 self.pollingDisabled = disablePolling 1101 self.pollingDisabled = disablePolling
1095 selectErrors = 0 1102 selectErrors = 0
1096 1103
1218 1225
1219 def __unhandled_exception(self, exctype, excval, exctb): 1226 def __unhandled_exception(self, exctype, excval, exctb):
1220 """ 1227 """
1221 Private method called to report an uncaught exception. 1228 Private method called to report an uncaught exception.
1222 1229
1223 @param exctype the type of the exception 1230 @param exctype class of the exception
1224 @param excval data about the exception 1231 @type type
1232 @param excval exception instance
1233 @type Exception
1225 @param exctb traceback for the exception 1234 @param exctb traceback for the exception
1235 @type traceback
1226 """ 1236 """
1227 self.mainThread.user_exception((exctype, excval, exctb), True) 1237 self.mainThread.user_exception((exctype, excval, exctb), True)
1228 1238
1229 def __interceptSignals(self): 1239 def __interceptSignals(self):
1230 """ 1240 """
1293 Public method to convert a filename to an absolute name. 1303 Public method to convert a filename to an absolute name.
1294 1304
1295 sys.path is used as a set of possible prefixes. The name stays 1305 sys.path is used as a set of possible prefixes. The name stays
1296 relative if a file could not be found. 1306 relative if a file could not be found.
1297 1307
1298 @param fn filename (string) 1308 @param fn filename
1299 @return the converted filename (string) 1309 @type str
1310 @return the converted filename
1311 @rtype str
1300 """ 1312 """
1301 if os.path.isabs(fn): 1313 if os.path.isabs(fn):
1302 return fn 1314 return fn
1303 1315
1304 # Check the cache. 1316 # Check the cache.
1331 1343
1332 def getRunning(self): 1344 def getRunning(self):
1333 """ 1345 """
1334 Public method to return the main script we are currently running. 1346 Public method to return the main script we are currently running.
1335 1347
1336 @return flag indicating a running debug session (boolean) 1348 @return flag indicating a running debug session
1349 @rtype bool
1337 """ 1350 """
1338 return self.running 1351 return self.running
1339 1352
1340 def progTerminated(self, status, message="", closeSession=True): 1353 def progTerminated(self, status, message="", closeSession=True):
1341 """ 1354 """
1673 def __generateFilterObjects(self, scope, filterString): 1686 def __generateFilterObjects(self, scope, filterString):
1674 """ 1687 """
1675 Private slot to convert a filter string to a list of filter objects. 1688 Private slot to convert a filter string to a list of filter objects.
1676 1689
1677 @param scope 1 to generate filter for global variables, 0 for local 1690 @param scope 1 to generate filter for global variables, 0 for local
1678 variables (int) 1691 variables
1692 @type int
1679 @param filterString string of filter patterns separated by ';' 1693 @param filterString string of filter patterns separated by ';'
1694 @type str
1680 """ 1695 """
1681 patternFilterObjects = None 1696 patternFilterObjects = None
1682 filterString = filterString.strip() 1697 filterString = filterString.strip()
1683 if filterString: 1698 if filterString:
1684 if filterString[0] == "~": 1699 if filterString[0] == "~":
1701 1716
1702 def __completionList(self, text): 1717 def __completionList(self, text):
1703 """ 1718 """
1704 Private slot to handle the request for a commandline completion list. 1719 Private slot to handle the request for a commandline completion list.
1705 1720
1706 @param text the text to be completed (string) 1721 @param text the text to be completed
1722 @type str
1707 """ 1723 """
1708 completerDelims = " \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?" 1724 completerDelims = " \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"
1709 1725
1710 completions = set() 1726 completions = set()
1711 # find position of last delim character 1727 # find position of last delim character
1740 1756
1741 def __getCompletionList(self, text, completer, completions): 1757 def __getCompletionList(self, text, completer, completions):
1742 """ 1758 """
1743 Private method to create a completions list. 1759 Private method to create a completions list.
1744 1760
1745 @param text text to complete (string) 1761 @param text text to complete
1762 @type str
1746 @param completer completer method 1763 @param completer completer method
1747 @param completions set where to add new completions strings (set) 1764 @type function
1765 @param completions set where to add new completions strings
1766 @type set
1748 """ 1767 """
1749 state = 0 1768 state = 0
1750 try: 1769 try:
1751 comp = completer(text, state) 1770 comp = completer(text, state)
1752 except Exception: 1771 except Exception:
1964 1983
1965 def run_call(self, scriptname, func, *args): 1984 def run_call(self, scriptname, func, *args):
1966 """ 1985 """
1967 Public method used to start the remote debugger and call a function. 1986 Public method used to start the remote debugger and call a function.
1968 1987
1969 @param scriptname name of the script to be debugged (string) 1988 @param scriptname name of the script to be debugged
1989 @type str
1970 @param func function to be called 1990 @param func function to be called
1991 @type function
1971 @param *args arguments being passed to func 1992 @param *args arguments being passed to func
1993 @type list
1972 @return result of the function call 1994 @return result of the function call
1995 @rtype Any
1973 """ 1996 """
1974 self.startDebugger(scriptname, enableTrace=False) 1997 self.startDebugger(scriptname, enableTrace=False)
1975 res = self.mainThread.runcall(func, *args) 1998 res = self.mainThread.runcall(func, *args)
1976 self.progTerminated(res, closeSession=False) 1999 self.progTerminated(res, closeSession=False)
1977 return res 2000 return res
1978 2001
1979 def __resolveHost(self, host): 2002 def __resolveHost(self, host):
1980 """ 2003 """
1981 Private method to resolve a hostname to an IP address. 2004 Private method to resolve a hostname to an IP address.
1982 2005
1983 @param host hostname of the debug server (string) 2006 @param host hostname of the debug server
1984 @return IP address (string) 2007 @type str
2008 @return IP address
2009 @rtype str
1985 """ 2010 """
1986 try: 2011 try:
1987 host, version = host.split("@@") 2012 host, version = host.split("@@")
1988 except ValueError: 2013 except ValueError:
1989 version = "v4" 2014 version = "v4"
2166 Public method implementing a close method as a replacement for 2191 Public method implementing a close method as a replacement for
2167 os.close(). 2192 os.close().
2168 2193
2169 It prevents the debugger connections from being closed. 2194 It prevents the debugger connections from being closed.
2170 2195
2171 @param fd file descriptor to be closed (integer) 2196 @param fd file descriptor to be closed
2197 @type int
2172 """ 2198 """
2173 if fd in [ 2199 if fd in [
2174 self.readstream.fileno(), 2200 self.readstream.fileno(),
2175 self.writestream.fileno(), 2201 self.writestream.fileno(),
2176 self.errorstream.fileno(), 2202 self.errorstream.fileno(),
2182 def __getSysPath(self, firstEntry): 2208 def __getSysPath(self, firstEntry):
2183 """ 2209 """
2184 Private slot to calculate a path list including the PYTHONPATH 2210 Private slot to calculate a path list including the PYTHONPATH
2185 environment variable. 2211 environment variable.
2186 2212
2187 @param firstEntry entry to be put first in sys.path (string) 2213 @param firstEntry entry to be put first in sys.path
2188 @return path list for use as sys.path (list of strings) 2214 @type str
2215 @return path list for use as sys.path
2216 @rtype list of str
2189 """ 2217 """
2190 sysPath = [ 2218 sysPath = [
2191 path 2219 path
2192 for path in os.environ.get("PYTHONPATH", "").split(os.pathsep) 2220 for path in os.environ.get("PYTHONPATH", "").split(os.pathsep)
2193 if path not in sys.path 2221 if path not in sys.path

eric ide

mercurial