eric6/DebugClients/Python/DebugClientBase.py

changeset 7637
c878e8255972
parent 7635
0cdead130a81
child 7639
422fd05e9c91
--- a/eric6/DebugClients/Python/DebugClientBase.py	Mon Jun 22 17:55:06 2020 +0200
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Tue Jun 23 17:24:18 2020 +0200
@@ -31,78 +31,37 @@
 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):
+def DebugClientRawInput(prompt=""):
     """
-    Replacement for the standard raw_input() builtin (Python 2) and
-    the standard input() builtin (Python 3).
+    Replacement for the standard input() builtin.
     
     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).
-    
-    This function works with the split debugger.
-    
-    @param prompt prompt to be shown
-    @type str
-    @return result of the input() call
-    @rtype str
-    """
-    if DebugClientInstance is None or not DebugClientInstance.redirect:
         return DebugClientOrigInput(prompt)
 
     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'] = DebugClientRawInput
+except (AttributeError, KeyError):
+    import __main__
+    DebugClientOrigInput = __main__.__builtins__.__dict__['input']
+    __main__.__builtins__.__dict__['input'] = DebugClientRawInput
 
 ###############################################################################
 
@@ -274,9 +233,9 @@
                     return
             self.__coding = default
         
-    def raw_input(self, prompt, echo):
+    def input(self, prompt):
         """
-        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)
@@ -284,20 +243,11 @@
         """
         self.sendJsonCommand("RequestRaw", {
             "prompt": prompt,
-            "echo": echo,
+            "echo": True,
         })
         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))       # secok
-        
     def sessionClose(self, terminate=True):
         """
         Public method to close the session with the debugger and optionally
@@ -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]
@@ -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):
@@ -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(

eric ide

mercurial