]> granicus.if.org Git - python/commitdiff
Use readline/raw_input() in pydoc.Helper.interact if available and self.input
authorJohannes Gijsbers <jlg@dds.nl>
Tue, 17 Aug 2004 13:21:53 +0000 (13:21 +0000)
committerJohannes Gijsbers <jlg@dds.nl>
Tue, 17 Aug 2004 13:21:53 +0000 (13:21 +0000)
is sys.stdin. Based on a patch (#726204) by Dmitry Vasiliev and a comment from
Guido in an older patch (#549901).

Lib/pydoc.py

index c02c1407f74467f43085d5199cd477da6117117d..12ae27795cdbf6bf0f4b0d8fc66a6446bfb9b745 100755 (executable)
@@ -1618,16 +1618,24 @@ has the same effect as typing a particular string at the help> prompt.
     def interact(self):
         self.output.write('\n')
         while True:
-            self.output.write('help> ')
-            self.output.flush()
             try:
-                request = self.input.readline()
+                request = self.getline('help> ')
                 if not request: break
-            except KeyboardInterrupt: break
+            except (KeyboardInterrupt, EOFError):
+                break
             request = strip(replace(request, '"', '', "'", ''))
             if lower(request) in ['q', 'quit']: break
             self.help(request)
 
+    def getline(self, prompt):
+        """Read one line, using raw_input when available."""
+        if self.input is sys.stdin:
+            return raw_input(prompt)
+        else:
+            self.output.write(prompt)
+            self.output.flush()
+            return self.input.readline()
+
     def help(self, request):
         if type(request) is type(''):
             if request == 'help': self.intro()