mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
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).
This commit is contained in:
parent
30d0008577
commit
e7691d36b7
1 changed files with 12 additions and 4 deletions
16
Lib/pydoc.py
16
Lib/pydoc.py
|
@ -1618,16 +1618,24 @@ has the same effect as typing a particular string at the help> prompt.
|
||||||
def interact(self):
|
def interact(self):
|
||||||
self.output.write('\n')
|
self.output.write('\n')
|
||||||
while True:
|
while True:
|
||||||
self.output.write('help> ')
|
|
||||||
self.output.flush()
|
|
||||||
try:
|
try:
|
||||||
request = self.input.readline()
|
request = self.getline('help> ')
|
||||||
if not request: break
|
if not request: break
|
||||||
except KeyboardInterrupt: break
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
break
|
||||||
request = strip(replace(request, '"', '', "'", ''))
|
request = strip(replace(request, '"', '', "'", ''))
|
||||||
if lower(request) in ['q', 'quit']: break
|
if lower(request) in ['q', 'quit']: break
|
||||||
self.help(request)
|
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):
|
def help(self, request):
|
||||||
if type(request) is type(''):
|
if type(request) is type(''):
|
||||||
if request == 'help': self.intro()
|
if request == 'help': self.intro()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue