Giter Site home page Giter Site logo

chut's People

Contributors

gawel avatar glehmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chut's Issues

dealing more gracefully with spaces

currently with chut, we can't pass args with spaces unless shell=True is passed
to the command:

>>> python("""-c 'print "a            b"'""") >1
ERROR:chut:File "<string>", line 1
    'print
         ^
SyntaxError: EOL while scanning string literal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/glehmann/Library/Python/2.7/lib/python/site-packages/chut/__init__.py", line 466, in __gt__
    return self._write(filename, 'wb+')
  File "/Users/glehmann/Library/Python/2.7/lib/python/site-packages/chut/__init__.py", line 523, in _write
    self._raise(output=output)
  File "/Users/glehmann/Library/Python/2.7/lib/python/site-packages/chut/__init__.py", line 547, in _raise
    raise OSError(self.commands_line, output.stderr)
OSError: [Errno python -c 'print "a b"'] File "<string>", line 1
    'print
         ^
SyntaxError: EOL while scanning string literal

passing several arguments helps - there are no exception, but the output is not
the expected one

>>> python("-c", 'print "a            b"') >1

''

even with shell=True, the output is not the as expected - the number of spaces
is not preserved:

>>> python("""-c 'print "a            b"'""", shell=True) >1
a b
''

Several propositions comes to mind. In all the cases, don't split anything when
shell=True - let the shell do all the splitting job - and passing several args
is not allowed when shell=True. Then

  1. shell=True becomes the default. Don't split anything when shell=False and
    just pass the list as is to execve. Seems to be the most usual IMO.
  2. shell=True is the default with 0 or 1 args, but shell=False is used with several
    args. Don't split anything when shell=False and just pass the list as is to execve.
    This may be confusing to switch the behavior depending on the number of args.
  3. shell=False stays the default. Args are split with shlex to preserve the content
    inside the quotes. Add a shell=None to really do nothing on the args. There
    would be 3 level of "shellness". Not exactly usual.
  4. shell=False stays the default. Args are split with shlex to preserve the content
    inside the quotes. Allow to pass a list in the arguments that is passed
    unchanged to execve. Some examples:
echo(["a    b", "c"], "d    e")        # echo "a   b" "c" "d" "e"
echo("a    b c d    e")                # echo "a" "b" "c" "d" "e"
echo("'a    b' c d    e")              # echo "a    b" "c" "d" "e"
echo("'a    b' c d    e", sh=true)     # echo "a    b" "c" "d" "e"
echo("a    b", "c", "d    e", sh=True) # raise exception, too much args

my preference clearly goes to 1. Option 4 might be ok, but clearly introduce a complex
behavior that may not be desirable.

And of course there might be better options, perhaps even already there!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.