diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-03-17 06:49:51 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-03-17 06:49:51 +0000 |
commit | 436d2416039c42bfa9665c0572ba3ec4f877156a (patch) | |
tree | 7ff9e8285951b40d0c1fd6c41b5a433461ec61a2 /Lib | |
parent | dea90d92c29e799b501b366a2be16496d5e1f932 (diff) | |
download | cpython-436d2416039c42bfa9665c0572ba3ec4f877156a.tar.gz |
Get rid of a bunch more raw_input references
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/cmd.py | 10 | ||||
-rw-r--r-- | Lib/code.py | 10 | ||||
-rw-r--r-- | Lib/distutils/command/register.py | 5 | ||||
-rw-r--r-- | Lib/getpass.py | 3 | ||||
-rw-r--r-- | Lib/idlelib/PyShell.py | 2 | ||||
-rwxr-xr-x | Lib/pdb.py | 5 | ||||
-rw-r--r-- | Lib/plat-mac/aetools.py | 5 | ||||
-rwxr-xr-x | Lib/pydoc.py | 5 | ||||
-rw-r--r-- | Lib/rlcompleter.py | 6 | ||||
-rw-r--r-- | Lib/site.py | 4 | ||||
-rw-r--r-- | Lib/test/test_exceptions.py | 4 | ||||
-rw-r--r-- | Lib/urllib.py | 7 |
12 files changed, 43 insertions, 23 deletions
diff --git a/Lib/cmd.py b/Lib/cmd.py index 3f82b48710..23dc5b2fb2 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -40,18 +40,20 @@ The data members `self.doc_header', `self.misc_header', and `self.undoc_header' set the headers used for the help function's listings of documented functions, miscellaneous topics, and undocumented functions respectively. - -These interpreters use raw_input; thus, if the readline module is loaded, -they automatically support Emacs-like command history and editing features. """ -import string +import string, sys __all__ = ["Cmd"] PROMPT = '(Cmd) ' IDENTCHARS = string.ascii_letters + string.digits + '_' +def raw_input(prompt): + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + class Cmd: """A simple framework for writing line-oriented command interpreters. diff --git a/Lib/code.py b/Lib/code.py index 6bdc658add..b67009b93b 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -269,12 +269,14 @@ class InteractiveConsole(InteractiveInterpreter): The returned line does not include the trailing newline. When the user enters the EOF key sequence, EOFError is raised. - The base implementation uses the built-in function - raw_input(); a subclass may replace this with a different - implementation. + The base implementation uses sys.stdin.readline(); a subclass + may replace this with a different implementation. """ - return raw_input(prompt) + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + def interact(banner=None, readfunc=None, local=None): diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py index dec9aa2bf2..f8912621c8 100644 --- a/Lib/distutils/command/register.py +++ b/Lib/distutils/command/register.py @@ -13,6 +13,11 @@ import StringIO, ConfigParser from distutils.core import Command from distutils.errors import * +def raw_input(prompt): + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + class register(Command): description = ("register the distribution with the Python package index") diff --git a/Lib/getpass.py b/Lib/getpass.py index e96491f90b..a30d3a1541 100644 --- a/Lib/getpass.py +++ b/Lib/getpass.py @@ -69,8 +69,7 @@ def default_getpass(prompt='Password: '): def _raw_input(prompt=""): - # A raw_input() replacement that doesn't save the string in the - # GNU readline history. + # This doesn't save the string in the GNU readline history. prompt = str(prompt) if prompt: sys.stdout.write(prompt) diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index f81091bc4b..b6abe408ce 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -1122,7 +1122,7 @@ class PyShell(OutputWindow): self.text.tag_add("stdin", "iomark", "end-1c") self.text.update_idletasks() if self.reading: - self.top.quit() # Break out of recursive mainloop() in raw_input() + self.top.quit() # Break out of recursive mainloop() else: self.runit() return "break" diff --git a/Lib/pdb.py b/Lib/pdb.py index b00f68b79d..1aa2eaee27 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -22,6 +22,11 @@ _saferepr = _repr.repr __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", "post_mortem", "help"] +def raw_input(prompt): + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + def find_function(funcname, filename): cre = re.compile(r'def\s+%s\s*[(]' % funcname) try: diff --git a/Lib/plat-mac/aetools.py b/Lib/plat-mac/aetools.py index 79f3978316..861dd2fd1b 100644 --- a/Lib/plat-mac/aetools.py +++ b/Lib/plat-mac/aetools.py @@ -342,6 +342,11 @@ _application_file._elemdict = { # XXXX Should test more, really... def test(): + def raw_input(prompt): + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + target = AE.AECreateDesc('sign', 'quil') ae = AE.AECreateAppleEvent('aevt', 'oapp', target, -1, 0) print unpackevent(ae) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index ee45643b43..b6afc7f9ad 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1505,6 +1505,11 @@ def writedocs(dir, pkgpath='', done=None): done[modname] = 1 writedoc(modname) +def raw_input(prompt): + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + class Helper: keywords = { 'and': 'BOOLEAN', diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 1d291670f1..6eb77f97e1 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -28,12 +28,6 @@ application (or the user) to enable this feature, I consider this an acceptable risk. More complicated expressions (e.g. function calls or indexing operations) are *not* evaluated. -- GNU readline is also used by the built-in functions input() and -raw_input(), and thus these also benefit/suffer from the completer -features. Clearly an interactive application can benefit by -specifying its own completer function and using raw_input() for all -its input. - - When the original stdin is not a tty device, GNU readline is never used, and this module (and the readline module) are silently inactive. diff --git a/Lib/site.py b/Lib/site.py index 6818e8531f..5e7ff7bc12 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -299,7 +299,9 @@ class _Printer(object): lineno += self.MAXLINES key = None while key is None: - key = raw_input(prompt) + sys.stdout.write(prompt) + sys.stdout.flush() + key = sys.stdin.readline() if key not in ('', 'q'): key = None if key == 'q': diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index fdef876879..65f7876673 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -44,8 +44,8 @@ fp = open(TESTFN, 'r') savestdin = sys.stdin try: try: - sys.stdin = fp - x = raw_input() + import marshal + marshal.loads('') except EOFError: pass finally: diff --git a/Lib/urllib.py b/Lib/urllib.py index aeca3f1007..136f42ea20 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -768,10 +768,11 @@ class FancyURLopener(URLopener): def prompt_user_passwd(self, host, realm): """Override this in a GUI environment!""" - import getpass + import getpass, sys try: - user = raw_input("Enter username for %s at %s: " % (realm, - host)) + sys.stdout.write("Enter username for %s at %s: " % (realm, host)) + sys.stdout.flush() + user = sys.stdin.readline() passwd = getpass.getpass("Enter password for %s in %s at %s: " % (user, realm, host)) return user, passwd |