Coder Social home page Coder Social logo

mslex's Introduction

mslex

Documentation Status

shlex for windows

Features

This is the missing shlex package for windows shell quoting. It provides three functions -- split, quote, and join -- just like shlex.

Windows Quoting

These are excellent articles to read if you really want to face the sanity-melting reality buried under the surface of how windows passes command line arguments to your programs. I recommend you read something else.

Automatic selection between mslex and shlex

If you want to automatically use mslex on Windows, and shlex otherwise, check out the oslex package.

mslex's People

Contributors

smoofra avatar petamas avatar jessielw avatar

Stargazers

Sandalots avatar Henry Schreiner avatar Oliver Schneider avatar Konstantin Kushnir avatar D. Bohdan avatar Qyriad avatar YOSHI avatar tsukumi avatar Soheyb Samadi avatar  avatar James E. A. avatar Dowon avatar  avatar Yehyoung Kang avatar Yuki Nagato avatar  avatar  avatar Adrian Friedli avatar Oz Tiram avatar Paul O'Leary McCann avatar Marko Ristin avatar Chris Timperley avatar Jacques Pharand avatar Russ Warren avatar Ruslan Kuprieiev avatar Mark Fisher avatar  avatar

Watchers

James Cloos avatar  avatar Mark Fisher avatar  avatar

Forkers

petamas jessielw

mslex's Issues

No f-strings in Python 3.5

  • mslex version: 0.3
  • Python version: 3.5.6
  • Operating System: CentOS 7

Syntax error mslex.py line 83 on import. f-strings were introduced in Python 3.6.

$ python3.5 -m venv zzz
$ . zzz/bin/activate
(zzz) $ pip install mslex
...
Successfully installed mslex-0.3.0
(zzz) $ python
Python 3.5.6 (default, Nov 16 2018, 15:51:11)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mslex
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "zzz/lib64/python3.5/site-packages/mslex.py", line 83
    raise ValueError(f"unquoted cmd metacharacters in string: {repr(s)}")
                                                                       ^
SyntaxError: invalid syntax
>>>

Incorrect expressions are processed incorrectly

  • mslex version: 1.2.0
  • Python version: 3.12.4
  • Operating System: macOS

Description

Hello!

When i pass a wrong command python -c " to the split() function of your library i have not any exceptions.

A similar experiment with shlex raises an error:

>>> from shlex import split
>>>
>>> split('python -c "')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/shlex.py", line 313, in split
    return list(lex)
           ^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/shlex.py", line 300, in __next__
    token = self.get_token()
            ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/shlex.py", line 109, in get_token
    raw = self.read_token()
          ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/shlex.py", line 191, in read_token
    raise ValueError("No closing quotation")
ValueError: No closing quotation

I also noticed that there are no tests in the project that would check situations when the functions of your package raise exceptions.

What I Did

>>> from mslex import split
>>>
>>> split('python -c "')
['python', '-c', '']

"Unquoted CMD metacharacters" error when all right

  • mslex version: 1.2.0
  • Python version: 3.12.4
  • Operating System: macOS

Description

I found that the python -c "print('hello,world!')" string is recognized by mslex as bad. However, I suspect that this should not be the case.

What I Did

>>> import mslex
>>>
>>> mslex.split('python -c "print(\'hello,world!\')"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pomponchik/Desktop/Projects/suby/venv/lib/python3.12/site-packages/mslex/__init__.py", line 104, in split
    s = "".join(i())
        ^^^^^^^^^^^^
  File "/Users/pomponchik/Desktop/Projects/suby/venv/lib/python3.12/site-packages/mslex/__init__.py", line 102, in i
    raise MSLexError("Unquoted CMD metacharacters in string: " + repr(s))
mslex.exceptions.MSLexError: Unquoted CMD metacharacters in string: 'python -c "print(\'hello,world!\')"'
>>>
>>> mslex.split("python -c \"print('hello,world!')\"")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pomponchik/Desktop/Projects/suby/venv/lib/python3.12/site-packages/mslex/__init__.py", line 104, in split
    s = "".join(i())
        ^^^^^^^^^^^^
  File "/Users/pomponchik/Desktop/Projects/suby/venv/lib/python3.12/site-packages/mslex/__init__.py", line 102, in i
    raise MSLexError("Unquoted CMD metacharacters in string: " + repr(s))
mslex.exceptions.MSLexError: Unquoted CMD metacharacters in string: 'python -c "print(\'hello,world!\')"'

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.