diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2004-08-17 13:21:53 +0000 |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2004-08-17 13:21:53 +0000 |
commit | 81e5bc4c7b8478ff25bfff5c3bca2514a3976473 (patch) | |
tree | 12217938adf79acd1f49b6cc6057712b37751ca0 /Lib/pydoc.py | |
parent | b035b8fac467e4056daeb7cfaff4f9cf99fccf10 (diff) | |
download | cpython-81e5bc4c7b8478ff25bfff5c3bca2514a3976473.tar.gz |
Use readline/raw_input() in pydoc.Helper.interact if available and self.input
is sys.stdin. Based on a patch (#726204) by Dmitry Vasiliev and a comment from
Guido in an older patch (#549901).
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index c02c1407f7..12ae27795c 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -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() |