[issue9723] pipes.quote() needs to be documented

New submission from Brandon Craig Rhodes <brandon@rhodesmill.org>: The only way to safely build shell command lines from inside of Python — which is necessary when sending commands across SSH, since that behaves like os.system() rather than like subprocess.call() — is to use the wonderful pipes.call() method to turn possibly-dangerous arguments, like filenames that might have spaces, special characters, and embedded "rm -r" calls, into perfectly quoted strings for an "sh"-like shell (say, bash or zsh). This call is already recommended on mailing lists, blog posts, and Stack Overflow — and since it doesn't start with a "_", I think its public use is fair game. But the "pipes" documentation itself doesn't officially mention or support it. I think it should be added to the Standard Library documentation for "pipes". So. Yeah. ---------- assignee: docs@python components: Documentation messages: 115263 nosy: brandon-rhodes, docs@python priority: normal severity: normal status: open title: pipes.quote() needs to be documented type: feature request versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Eric Smith <eric@trueblade.com> added the comment: I think you mean pipe.quote in your message, not pipe.call. The subject looks correct. I'm not sure pipes is the best place for this, but I agree it should probably be documented in older versions. It seems to me we've had this discussion before about quoting command lines, how it applies differently between Windows and various shells, and which functions to expose. But having said that, I can't find a previous issue that discusses it. Not the least of my concerns is that pipes says it's available on Unix systems, despite the fact that I have it on a Windows machine. And I might need the functionality of passing a bash command from a Windows machine to a Unix machine, so we definitely need this cross platform. ---------- nosy: +eric.smith _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Éric Araujo <merwok@netwok.org> added the comment: Eric referred to this thread: http://mail.python.org/pipermail/stdlib-sig/2010-May/thread.html ---------- nosy: +eric.araujo versions: -Python 2.5, Python 2.6, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Matt Joiner <anacrolix@gmail.com> added the comment: I agree, I discovered this function (pipes.quote) only through recommendation here: http://stackoverflow.com/questions/4748344/whats-the-reverse-of-shlex-split I suggest that it be added to shlex, perhaps as shlex.quote. While the quoting style it performs, and the module it's found in are specific to Unix tools, the shlex module is available on non-Unix platforms. To this end, adding the function to shlex would make it available elsewhere, as well as be appropriately shell-related. ---------- nosy: +anacrolix _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Éric Araujo <merwok@netwok.org> added the comment: Why do you want to move quote from pipes to shlex? The function is available, the issue here is lack of documentation. ---------- stage: -> unit test needed type: feature request -> _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Changes by Éric Araujo <merwok@netwok.org>: ---------- stage: unit test needed -> needs patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Matt Joiner <anacrolix@gmail.com> added the comment: Two reasons: The pipes module is Unix only, but pipes.quote is useful on all platforms. Secondly pipes.quote pertains to shell command-lines, this is also the domain of shlex which already cross platform. In pipes, an import shlex.quote would more than sufficient. If this belongs in another separate bug I shall submit one. Please advise. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Eric Smith <eric@trueblade.com> added the comment: I think you mean pipe.quote in your message, not pipe.call. The subject looks correct. I'm not sure pipes is the best place for this, but I agree it should probably be documented in older versions. It seems to me we've had this discussion before about quoting command lines, how it applies differently between Windows and various shells, and which functions to expose. But having said that, I can't find a previous issue that discusses it. Not the least of my concerns is that pipes says it's available on Unix systems, despite the fact that I have it on a Windows machine. And I might need the functionality of passing a bash command from a Windows machine to a Unix machine, so we definitely need this cross platform. ---------- nosy: +eric.smith _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Éric Araujo <merwok@netwok.org> added the comment: Eric referred to this thread: http://mail.python.org/pipermail/stdlib-sig/2010-May/thread.html ---------- nosy: +eric.araujo versions: -Python 2.5, Python 2.6, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Matt Joiner <anacrolix@gmail.com> added the comment: I agree, I discovered this function (pipes.quote) only through recommendation here: http://stackoverflow.com/questions/4748344/whats-the-reverse-of-shlex-split I suggest that it be added to shlex, perhaps as shlex.quote. While the quoting style it performs, and the module it's found in are specific to Unix tools, the shlex module is available on non-Unix platforms. To this end, adding the function to shlex would make it available elsewhere, as well as be appropriately shell-related. ---------- nosy: +anacrolix _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Éric Araujo <merwok@netwok.org> added the comment: Why do you want to move quote from pipes to shlex? The function is available, the issue here is lack of documentation. ---------- stage: -> unit test needed type: feature request -> _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Changes by Éric Araujo <merwok@netwok.org>: ---------- stage: unit test needed -> needs patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________

Matt Joiner <anacrolix@gmail.com> added the comment: Two reasons: The pipes module is Unix only, but pipes.quote is useful on all platforms. Secondly pipes.quote pertains to shell command-lines, this is also the domain of shlex which already cross platform. In pipes, an import shlex.quote would more than sufficient. If this belongs in another separate bug I shall submit one. Please advise. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9723> _______________________________________
participants (4)
-
Brandon Craig Rhodes
-
Eric Smith
-
Matt Joiner
-
Éric Araujo