--- a/eric6/DebugClients/Python/DebugClientBase.py Sun May 31 17:26:46 2020 +0200 +++ b/eric6/DebugClients/Python/DebugClientBase.py Sat Jul 04 11:45:34 2020 +0200 @@ -31,40 +31,16 @@ from DebugUtilities import prepareJsonCommand from BreakpointWatch import Breakpoint, Watch -if sys.version_info[0] == 2: - from inspect import getargvalues, formatargvalues -else: - unichr = chr - from DebugUtilities import getargvalues, formatargvalues +from DebugUtilities import getargvalues, formatargvalues DebugClientInstance = None ############################################################################### -def DebugClientRawInput(prompt="", echo=True): - """ - Replacement for the standard raw_input() builtin (Python 2) and - the standard input() builtin (Python 3). - - This function works with the split debugger. - - @param prompt prompt to be shown - @type str - @param echo flag indicating echoing of the input - @type bool - @return result of the raw_input()/input() call - @rtype str - """ - if DebugClientInstance is None or not DebugClientInstance.redirect: - return DebugClientOrigRawInput(prompt) - - return DebugClientInstance.raw_input(prompt, echo) - - def DebugClientInput(prompt=""): """ - Replacement for the standard input() builtin (Python 2). + Replacement for the standard input() builtin. This function works with the split debugger. @@ -78,31 +54,14 @@ return DebugClientInstance.input(prompt) -# Use our own input() and on Python 2 raw_input(). -if sys.version_info[0] == 2: - try: - DebugClientOrigRawInput = __builtins__.__dict__['raw_input'] - __builtins__.__dict__['raw_input'] = DebugClientRawInput - except (AttributeError, KeyError): - import __main__ - DebugClientOrigRawInput = __main__.__builtins__.__dict__['raw_input'] - __main__.__builtins__.__dict__['raw_input'] = DebugClientRawInput - - try: - DebugClientOrigInput = __builtins__.__dict__['input'] - __builtins__.__dict__['input'] = DebugClientInput - except (AttributeError, KeyError): - import __main__ - DebugClientOrigInput = __main__.__builtins__.__dict__['input'] - __main__.__builtins__.__dict__['input'] = DebugClientInput -else: - try: - DebugClientOrigInput = __builtins__.__dict__['input'] - __builtins__.__dict__['input'] = DebugClientRawInput - except (AttributeError, KeyError): - import __main__ - DebugClientOrigInput = __main__.__builtins__.__dict__['input'] - __main__.__builtins__.__dict__['input'] = DebugClientRawInput +# Use our own input(). +try: + DebugClientOrigInput = __builtins__.__dict__['input'] + __builtins__.__dict__['input'] = DebugClientInput +except (AttributeError, KeyError): + import __main__ + DebugClientOrigInput = __main__.__builtins__.__dict__['input'] + __main__.__builtins__.__dict__['input'] = DebugClientInput ############################################################################### @@ -274,9 +233,9 @@ return self.__coding = default - def raw_input(self, prompt, echo): + def input(self, prompt, echo=True): """ - Public method to implement raw_input() / input() using the event loop. + Public method to implement input() using the event loop. @param prompt the prompt to be shown (string) @param echo Flag indicating echoing of the input (boolean) @@ -289,15 +248,6 @@ self.eventLoop(True) return self.rawLine - def input(self, prompt): - """ - Public method to implement input() (Python 2) using the event loop. - - @param prompt the prompt to be shown (string) - @return the entered string evaluated as a Python expresion - """ - return eval(self.raw_input(prompt, True)) - def sessionClose(self, terminate=True): """ Public method to close the session with the debugger and optionally @@ -307,7 +257,7 @@ """ try: self.set_quit() - except Exception: + except Exception: # secok pass self.debugging = False @@ -334,13 +284,6 @@ with codecs.open(filename, encoding=self.__coding) as fp: statement = fp.read() - if sys.version_info[0] == 2: - lines = statement.splitlines(True) - for lineno, line in enumerate(lines[:2]): - lines[lineno] = self.coding_re.sub('', line) - - statement = unicode('').join(lines) # __IGNORE_WARNING__ - try: code = compile(statement + '\n', filename, mode) except SyntaxError: @@ -382,9 +325,6 @@ method = commandDict["method"] params = commandDict["params"] - if "filename" in params and sys.version_info[0] == 2: - params["filename"] = params["filename"].encode( - sys.getfilesystemencoding()) if method == "RequestVariables": self.__dumpVariables( @@ -408,7 +348,7 @@ }) elif method == "RequestCapabilities": - clientType = "Python2" if sys.version_info[0] == 2 else "Python3" + clientType = "Python3" self.sendJsonCommand("ResponseCapabilities", { "capabilities": self.__clientCapabilities(), "clientType": clientType @@ -583,13 +523,10 @@ self.debugMod.__dict__['__file__'] = sys.argv[0] sys.modules['__main__'] = self.debugMod script = '' - if sys.version_info[0] == 2: - script = 'execfile({0!r})'.format(sys.argv[0]) - else: - with codecs.open(sys.argv[0], encoding=self.__coding) as fp: - script = fp.read() - if script and not script.endswith('\n'): - script += '\n' + with codecs.open(sys.argv[0], encoding=self.__coding) as fp: + script = fp.read() + if script and not script.endswith('\n'): + script += '\n' if script: self.running = sys.argv[0] @@ -633,7 +570,7 @@ try: if self.running is None: - exec(code, self.debugMod.__dict__) + exec(code, self.debugMod.__dict__) # secok else: if self.currentThread is None: # program has terminated @@ -661,15 +598,15 @@ if "sys" in _globals: __stdout = _globals["sys"].stdout _globals["sys"].stdout = self.writestream - exec(code, _globals, _locals) + exec(code, _globals, _locals) # secok _globals["sys"].stdout = __stdout elif "sys" in _locals: __stdout = _locals["sys"].stdout _locals["sys"].stdout = self.writestream - exec(code, _globals, _locals) + exec(code, _globals, _locals) # secok _locals["sys"].stdout = __stdout else: - exec(code, _globals, _locals) + exec(code, _globals, _locals) # secok self.currentThread.storeFrameLocals(self.framenr) except SystemExit as exc: @@ -1372,9 +1309,6 @@ @return the converted filename (string) """ if os.path.isabs(fn): - if sys.version_info[0] == 2: - fn = fn.decode(sys.getfilesystemencoding()) - return fn # Check the cache. @@ -1387,9 +1321,6 @@ nafn = os.path.normcase(afn) if os.path.exists(nafn): - if sys.version_info[0] == 2: - afn = afn.decode(sys.getfilesystemencoding()) - self._fncache[fn] = afn d = os.path.dirname(afn) if (d not in sys.path) and (d not in self.dircache): @@ -1590,7 +1521,7 @@ def __formatQtVariable(self, value, qttype): """ - Private method to produce a formatted output of a simple Qt4/Qt5 type. + Private method to produce a formatted output of a simple Qt5 type. @param value variable to be formatted @param qttype type of the Qt variable to be formatted (string) @@ -1601,7 +1532,7 @@ varlist = [] if qttype == 'QChar': varlist.append( - ("", "QChar", "{0}".format(unichr(value.unicode())))) + ("", "QChar", "{0}".format(chr(value.unicode())))) varlist.append(("", "int", "{0:d}".format(value.unicode()))) elif qttype == 'QByteArray': varlist.append( @@ -1794,7 +1725,7 @@ # special handling for '__builtins__' (it's way too big) if key == '__builtins__': - rvalue = '<module __builtin__ (built-in)>' + rvalue = '<module builtins (built-in)>' valtype = 'module' if ConfigVarTypeStrings.index(valtype) in filterList: continue @@ -2270,6 +2201,3 @@ sysPath.insert(0, firstEntry) sysPath.insert(0, '') return sysPath - -# -# eflag: noqa = M702