[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Changes by Ron Adam ron_a...@users.sourceforge.net: -- nosy: +ron_adam ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Changes by Éric Araujo mer...@netwok.org: -- status: closed - open type: - feature request versions: +Python 3.2 -Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Changes by Michael Hoffman qq9jsuv...@snkmail.com: -- nosy: +hoffman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Éric Araujo mer...@netwok.org added the comment: You could say my question was half-academic. I read your closing message and thought “this feature request has been closed because of the version, not really rejected”, so I asked about reopening. On a second level, it appears from your detailed message (thanks for writing it) that the situation is still unclear, so I do think that a review of docs and tests is needed, and maybe an API cleanup. I’m assigning this to myself as an opportunity to learn the insides of cmd in some months. -- assignee: - eric.araujo resolution: out of date - remind stage: unit test needed - type: feature request - ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Terry J. Reedy tjre...@udel.edu added the comment: Since 'we' can reopen any closed issue, I will try to answer what I think you might be asking. I closed this because of Daniel's suggestion coupled with the Richard disclaiming further interest and neither Raghuram nor any new responder saying anything more. The issue title is a misstatement arising from the OP not noticing how to change the behavior. Anyone reopening this (or opening a new issue) would need to change the title to reflect what he thinks should be done. I will not do that because the naive change proposed in the thread seems unnecessary, while further investigation suggests that it may be wrong or insufficient. The original post refers to use_rawinput as a 'module global value'. It is not that but a cmd.Cmd class data attribute that can be changed either for the class or an instance. It is one of 9 that might be so changed. Looking at the patch with #405952 shows that Cmd.__init__ had no parameters and Cmd.cmdloop always read input with raw_input(), now renamed just input() (making the attribute name a bit obsolete). The replacement then was something like if self.use_rawinput: try: line = input(self.prompt) except EOFError: line = 'EOF' else: sys.stdout.write(self.prompt) # note sys., sys.stdout.flush()# not self. here line = sys.stdin.readline() if not len(line): line = 'EOF' else: line = line[:-1] # chop \n The reason for this patch, which *almost* replicates raw_input(), was that raw_input and/or readline swallowed an exception, whereas the replacement code does not. I wonder: 1. Does input() still do the same and should it? 2. Is there something about cmd processing that this is the only use of input() where this exception swallowing is a problem? 3. If so, why not always use the replacement? Speed? 4. I am sort of asking whether this was/is really the right hack. Someone later added completekey as an initialization parameter (rather than as a date attribute) and the following code if self.use_rawinput and self.completekey: try: import readline self.old_completer = readline.get_completer() readline.set_completer(self.complete) readline.parse_and_bind(self.completekey+: complete) except ImportError: I know nothing about readline and why it (apparently) requires the use of input(), but the point here is that setting use_rawinput to False disables completekey. This should be documented but I did not see such. At the same or later time, someone added stdin and stdout parameters and change 'sys' to 'self' in the first snippet above. Given that these parameters appears useless when use_rawinput is True, why was use_rawinput not automatically set to false then? Blunder or subtle reason? Someone who proposes auto-resetting should try to find the name of the patch and/or commit author and ask. It seems to me that all the process parameters should be handled uniformly. Make then all class attributes and let any be changed for instances as keyword attributes to __init__(). Given the conflict noted above, perhaps raise ValueError if someone makes contradictory changes. So, Éric, if your question was academic, I would leave this closed. If it was not, and you want to reopen, retitle, and assign it to yourself, go ahead. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Éric Araujo mer...@netwok.org added the comment: Can we reopen this as a feature request for 3.2? -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Terry J. Reedy tjre...@udel.edu added the comment: Too late for new 2.7 features. -- nosy: +tjreedy resolution: - out of date status: pending - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Daniel Diniz aja...@gmail.com added the comment: Changing into a RFE: automatically set use_rawinput when 'stdin' is not None. Will be closed unless someone voices interest. -- components: +Library (Lib) -Extension Modules keywords: +easy priority: - low stage: - test needed status: open - pending type: behavior - feature request versions: +Python 2.7 -Python 2.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Raghuram Devarakonda [EMAIL PROTECTED] added the comment: On Wed, Jun 18, 2008 at 9:28 PM, Richard King [EMAIL PROTECTED] wrote: Richard King [EMAIL PROTECTED] added the comment: There were some other things I wanted too so I just made my own cmd.py. Yes. Lot of people seem to use their own versions of cmd.py. Recently, I also implemented another class on top of cmd.Cmd in order to have more useful functionality. I have seen at least three implementations ('cmdln' on googlecode, 'CommandLoop' and 'cmd2' on pypi). I hope that after some heavy use, I will be able to submit some patches to the standard library module. There is already one in #1294. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Raghuram Devarakonda [EMAIL PROTECTED] added the comment: Richard, I see the following very clearly mentioned in the doc: If you want a given stdin to be used, make sure to set the instance’s use_rawinput attribute to False, otherwise stdin will be ignored. Even though this seems like unnecessary, at least it is documented. If you want to push for automatically setting use_rawinput when 'stdin' is not None, you will need to submit a patch and convince some core developer to agree with you. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Richard King [EMAIL PROTECTED] added the comment: There were some other things I wanted too so I just made my own cmd.py. -Rick Raghuram Devarakonda wrote: Raghuram Devarakonda [EMAIL PROTECTED] added the comment: Richard, I see the following very clearly mentioned in the doc: If you want a given stdin to be used, make sure to set the instance’s use_rawinput attribute to False, otherwise stdin will be ignored. Even though this seems like unnecessary, at least it is documented. If you want to push for automatically setting use_rawinput when 'stdin' is not None, you will need to submit a patch and convince some core developer to agree with you. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 ___ No virus found in this incoming message. Checked by AVG. Version: 8.0.100 / Virus Database: 270.4.0/1506 - Release Date: 6/17/2008 4:30 PM ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Richard King [EMAIL PROTECTED] added the comment: (this is really 2 mails because my home email address was not registered so they were rejected at first) Right - I wasn't too clear. The module stashes stdin, whether from sys or passed in, in self.stdin. When it reads input it uses a flag raw_input to determine whether to use raw_input or self.stdin.readline(), but the flag is not reset when a different stdin is passed in, so raw_input is always true. The flag should be True/False, and I didn't think of setting it directly to be honest because it never occurred to me that I should have to do that to get a cmd class that i just instantiated with a different input object to use the one it was created with. I think the flag should be eliminated and replaced with the test self.stdin == sys.stdin anyway. I also entered a feature request to add a stack of stdin's which are stacked when you want to process lines in a file, and then pop off the stack automatically at end of file. This would make it easy to write a command-line tool, like i'm doing, so that any input object could enter commands that change to other input objects and then restore the previous input objectthis would allow for nesting of command files. There would be special conditions for sys.stdin (sys.stdin can only be used if there are no items on the stack). This could all be done outside the module, but it's so easy when it's integrated right in there. I think I understand better what you are getting at, but it makes more sense to me to be explicit in the code and not take advantage of the fact the raw_input always works off sys.stdin. Also, I see now that maybe the idea was to have raw_input be changeable so that you could switch back and forth between stdin (whatever that is), and some other input object - I'm having a hard time seeing the usefulness of that, though. Anyway, instantiating a cmd class with a non-stdin input object and then having to set raw_input to False to get it to use that input object seems wrong. does this make sense? -Rick King Daniel Diniz wrote: Daniel Diniz [EMAIL PROTECTED] added the comment: I don't think it should stop using raw_input just because you changed stdin, as you can change it to something that will work with raw_input. Consider: import sys sys.stdin = open(/dev/tty) raw_input() a 'a' You can tie it to any object (e.g. a GUI input) that supports the file protocol and keep using raw_input. Or change Cmd.use_rawinput to 0 to use stdin.readline directly. On a related issue. Cmd.use_rawinput should be True, not 1... -- nosy: +ajaksu2 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 __ __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
New submission from Richard King [EMAIL PROTECTED]: The module global value use_rawinput is initialized to 1 but not reset when stdin is replaced with a passed-in value. -- components: Extension Modules messages: 65094 nosy: rickbking severity: normal status: open title: cmd.py always uses raw_input, even when another stdin is specified type: behavior versions: Python 2.4 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Daniel Diniz [EMAIL PROTECTED] added the comment: I don't think it should stop using raw_input just because you changed stdin, as you can change it to something that will work with raw_input. Consider: import sys sys.stdin = open(/dev/tty) raw_input() a 'a' You can tie it to any object (e.g. a GUI input) that supports the file protocol and keep using raw_input. Or change Cmd.use_rawinput to 0 to use stdin.readline directly. On a related issue. Cmd.use_rawinput should be True, not 1... -- nosy: +ajaksu2 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2571] cmd.py always uses raw_input, even when another stdin is specified
Raghuram Devarakonda [EMAIL PROTECTED] added the comment: The doc for cmd at http://docs.python.org/dev/library/cmd.html#module-cmd says: Instances of Cmd subclasses have some public instance variables: . . . Cmd.use_rawinput¶ A flag, defaulting to true. If true, cmdloop() uses raw_input() to display a prompt and read the next command; if false, sys.stdout.write() and sys.stdin.readline() are used. (This means that by importing readline, on systems that support it, the interpreter will automatically support Emacs-like line editing and command-history keystrokes.) So it is for the user to modify use_rawinput as required. This flag has been introduced in #405952. BTW, this one and other similar variables are at class level and are not instance variables. Isn't it? -- nosy: +draghuram __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2571 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com