eric6/DebugClients/Python/DebugClientBase.py

branch
multi_processing
changeset 7646
39e3db2b4936
parent 7627
812ee8c0a91a
parent 7639
422fd05e9c91
child 7802
eefe954f01e8
diff -r 812ee8c0a91a -r 39e3db2b4936 eric6/DebugClients/Python/DebugClientBase.py
--- a/eric6/DebugClients/Python/DebugClientBase.py	Wed Jun 17 17:14:12 2020 +0200
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Sun Jul 05 11:11:24 2020 +0200
@@ -35,40 +35,16 @@
 from BreakpointWatch import Breakpoint, Watch
 ##from MultiProcessDebugExtension import patchNewProcessFunctions
 
-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.
     
@@ -82,39 +58,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):
-        try:
-            import __main__
-            DebugClientOrigRawInput = __main__.__builtins__.__dict__[
-                'raw_input'
-            ]
-            __main__.__builtins__.__dict__['raw_input'] = DebugClientRawInput
-        except (AttributeError, KeyError):
-            DebugClientOrigRawInput = lambda x: ''  # __IGNORE_WARNING__
-
-    try:
-        DebugClientOrigInput = __builtins__.__dict__['input']
-        __builtins__.__dict__['input'] = DebugClientInput
-    except (AttributeError, KeyError):
-        try:
-            import __main__
-            DebugClientOrigInput = __main__.__builtins__.__dict__['input']
-            __main__.__builtins__.__dict__['input'] = DebugClientInput
-        except (AttributeError, KeyError):
-            DebugClientOrigInput = lambda x: ''  # __IGNORE_WARNING__
-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
 
 ###############################################################################
 
@@ -293,9 +244,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)
@@ -308,15 +259,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
@@ -326,7 +268,7 @@
         """
         try:
             self.set_quit()
-        except Exception:
+        except Exception:       # secok
             pass
 
         self.debugging = False
@@ -355,13 +297,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:
@@ -403,9 +338,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(
@@ -441,7 +373,7 @@
                 })
         
         elif method == "RequestCapabilities":
-            clientType = "Python2" if sys.version_info[0] == 2 else "Python3"
+            clientType = "Python3"
             self.sendJsonCommand("ResponseCapabilities", {
                 "capabilities": self.__clientCapabilities(),
                 "clientType": clientType
@@ -616,13 +548,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]
@@ -666,7 +595,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
@@ -694,15 +623,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:
@@ -1447,9 +1376,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.
@@ -1462,9 +1388,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):
@@ -1671,7 +1594,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)
@@ -1682,7 +1605,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(
@@ -1875,7 +1798,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
@@ -2415,6 +2338,3 @@
         sysPath.insert(0, firstEntry)
         sysPath.insert(0, '')
         return sysPath
-
-#
-# eflag: noqa = M702

eric ide

mercurial