Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73315
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'arguments': 0.09; 'moreover,': 0.09; 'subject:skip:t 10': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; 'braces,': 0.16; 'brackets': 0.16; 'bugs.': 0.16; 'command.': 0.16; 'contract.': 0.16; 'expands': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mesa': 0.16; 'operation,': 0.16; 'quirks': 0.16; 'sense...': 0.16; 'stdlib.': 0.16; 'tim,': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'command': 0.22; 'handles': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'case.': 0.24; 'directory.': 0.24; 'features,': 0.24; 'instance,': 0.24; 'specify': 0.24; 'typical': 0.24; 'mon,': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'login': 0.25; 'skip:" 30': 0.26; 'pass': 0.26; 'primary': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'leave': 0.29; 'skip:p 30': 0.29; 'matching': 0.30; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; "user's": 0.31; 'option': 0.32; 'quite': 0.32; 'open': 0.33; 'maybe': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'options:': 0.36; 'skip:~ 10': 0.36; 'should': 0.36; 'example,': 0.37; 'two': 0.37; 'list': 0.37; 'files': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'does': 0.39; 'itself': 0.39; 'sure': 0.39; 'according': 0.40; 'skip:u 10': 0.60; 'free': 0.61; 'black': 0.61; "you're": 0.61; 'back': 0.62; "you'll": 0.62; 'become': 0.64; 'incorporate': 0.68; 'prompt': 0.68; 'subject': 0.69; 'square': 0.74; 'goals': 0.81; 'wish.': 0.84; 'activity,': 0.91; 'shell,': 0.91; 'to:none': 0.92; 'serious': 0.97 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=OmWAWvc01fqOkFQzG2YdVFg7oDQF23A/za9ZHhk5TK8=; b=ML4o1TS9DRUQwb9eB9O0DCuvK53/iOKSJZrd/7TLL3QcAfq8/nbvt4t+Q4Tdmmv6iA 4uoF8vvIr/5PDaFQEs5GTkAIUu5GZHF7+yl+NQ+HeULLEAsCLPP0Tm/t9n3guMMfybbo f0ftYp2iPF5fMStcPGPzpAupOslfyZUriJth7h8rZXPaBQrMZ8S2YRie89R1XvZKLK9C +DptKmmLIpByxHfRB5jR528TmfnVAgy3XDV48TvRyZJdcLwtH9G+A4Ax2yaNevSUG9+v PFJ/GYPnuEAci4B72MVPCfW84qbGsl5cmrUf2pIKDxNbirEl7+fSXM+PXO0TfjxPbv5D X3qw== |
| MIME-Version | 1.0 |
| X-Received | by 10.58.110.106 with SMTP id hz10mr1453198veb.30.1402917950288; Mon, 16 Jun 2014 04:25:50 -0700 (PDT) |
| In-Reply-To | <871tupp1bb.fsf@elektro.pacujo.net> |
| References | <539EBF61.4050106@rece.vub.ac.be> <CAPTjJmqd74v013WwG2QrZP2y9N+gMk0TK5xT5-yy3=8gOuAs4g@mail.gmail.com> <539EC5EF.7040205@rece.vub.ac.be> <mailman.11082.1402915284.18130.python-list@python.org> <871tupp1bb.fsf@elektro.pacujo.net> |
| Date | Mon, 16 Jun 2014 21:25:50 +1000 |
| Subject | Re: line to argv transformation |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11086.1402917952.18130.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1402917952 news.xs4all.nl 2831 [2001:888:2000:d::a6]:39594 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:73315 |
Show key headers only | View raw
On Mon, Jun 16, 2014 at 8:59 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> def shell_split(cmd):
>> return subprocess.check_output("""python -c 'import sys;
>> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0")
>>
>> You'll get back a list of byte strings, in any case. Feel free to pass
>> them through a decode operation, or to incorporate a .decode() into
>> the above stream, as you wish.
>
> Now you are subject to the quirks of /bin/sh. For example, '*.xyz'
> expands itself ('*.xyz') if there is no match in the current working
> directory.
>
> Moreover, you need to guard against arguments like
>
> $(cat ~/.ssh/id_dsa)
>
> which would spill the beans.
As I said in response to Tim, the somewhat underspecified question
does leave open followups of whether both of those would be features,
rather than bugs. For instance, if "*.py" should expand to a list of
all files matching that glob, should "[123].py" expand to any files
matching that pattern? I'm not sure that your typical glob function
handles that. And should "spam{eggs,spam}" become
"spameggs","spamspam"? (Though that one's bash-specific, I believe.)
Where do you draw the line?
My reading is that it should be one of two options:
1) Split, according to shell rules, and then glob. Nothing more. No
square brackets (probably), no braces, nothing.
2) Do exactly what $CHELL would do, for some value of $CHELL.
But neither is quite clear, and I can see exactly why there isn't
anything in the stdlib. And what shell do you want to imitate, for
option 2? Using /bin/sh makes a lot of sense... but so does /bin/bash.
Or maybe you should use the user's own login shell, if you're wrapping
a command prompt in some way. Perhaps you want to use GLaDOS; but
remember that although fun and learning are the primary goals of this
activity, serious injuries may occur, especially when using backticks
or $( ) in the command.
OP needs to specify better. Otherwise Black Mesa will get the contract.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 20:41 +1000
Re: line to argv transformation Marko Rauhamaa <marko@pacujo.net> - 2014-06-16 13:59 +0300
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 21:25 +1000
csiph-web