oslex2 0.1.5__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
oslex2/__init__.py CHANGED
@@ -1,69 +1,37 @@
1
- import sys
2
- from typing import List
3
-
4
-
5
- def is_posix() -> bool:
6
- """
7
- Returns whether the system running Python is POSIX compatible.
8
- This is the condition for oslex.underlying being shlex.
9
- This is also the condition for os.path being posixpath.
10
- """
11
- return "posix" in sys.builtin_module_names
12
-
13
-
14
- def is_windows() -> bool:
15
- """
16
- Returns whether the system running Python is Windows based.
17
- This is the condition for oslex.underlying being mslex.
18
- This is also the condition for os.path being ntpath.
19
- """
20
-
21
- if is_posix():
22
- # This early return is likely redundant, but we want to be 100% equivalent to the if-elseif structure found in os.py
23
- # See https://github.com/python/cpython/blob/3.7/Lib/os.py
24
- return False
25
-
26
- return "nt" in sys.builtin_module_names
27
-
28
-
29
- # Import OS-specific module
30
-
31
- if is_posix():
32
- import shlex as underlying
33
- elif is_windows():
34
- # mslex has no type annotations -> we have to ignore the "import" error
35
- # also, mypy does not understand conditional importing, so it thinks we are redefining the name "underlying" -> we have to ignore the "no-redef" error
36
- import mslex as underlying # type: ignore[import, no-redef]
37
- else:
38
- raise ImportError("no os specific module found")
39
-
40
- # Define functions
41
-
42
-
43
- def quote(s: str, **kwargs) -> str:
44
- """
45
- Return a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line, for cases where you cannot use a list.
46
- This function is safe to use both for POSIX-compatible shells and for Windows's cmd.
47
- """
48
- return underlying.quote(s, **kwargs)
49
-
50
-
51
- def split(s: str, **kwargs) -> List[str]:
52
- """
53
- Split the string s using shell-like syntax.
54
- This function is safe to use both for POSIX-compatible shells and for Windows's cmd.
55
- """
56
- return underlying.split(s, **kwargs)
57
-
58
-
59
- def join(split_command: List[str]) -> str:
60
- """
61
- Concatenate the tokens of the list split_command and return a string. This function is the inverse of split().
62
- The returned value is shell-escaped to protect against injection vulnerabilities (see quote()).
63
- This function is safe to use both for POSIX-compatible shells and for Windows's cmd.
64
- """
65
- # shlex only has join() since Python 3.8
66
- # mslex doesn't have it at all
67
- # It's easier to just implement it without trying to import the functionality
68
- # Implementation is the same as shlex.join(), see https://github.com/python/cpython/blob/3.8/Lib/shlex.py
69
- return " ".join(quote(arg) for arg in split_command)
1
+ import platform
2
+ from typing import List
3
+
4
+ # import OS-specific module
5
+ if platform.system() == "Windows":
6
+ import mslex as underlying
7
+ else:
8
+ import shlex as underlying
9
+
10
+
11
+ def quote(s: str, **kwargs) -> str:
12
+ """
13
+ Return a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line, for cases where you cannot use a list.
14
+ This function is safe to use both for POSIX-compatible shells and for Windows's cmd.
15
+ """
16
+ return underlying.quote(s, **kwargs)
17
+
18
+
19
+ def split(s: str, **kwargs) -> List[str]:
20
+ """
21
+ Split the string s using shell-like syntax.
22
+ This function is safe to use both for POSIX-compatible shells and for Windows's cmd.
23
+ """
24
+ return underlying.split(s, **kwargs)
25
+
26
+
27
+ def join(split_command: List[str]) -> str:
28
+ """
29
+ Concatenate the tokens of the list split_command and return a string. This function is the inverse of split().
30
+ The returned value is shell-escaped to protect against injection vulnerabilities (see quote()).
31
+ This function is safe to use both for POSIX-compatible shells and for Windows's cmd.
32
+ """
33
+ # shlex only has join() since Python 3.8
34
+ # mslex doesn't have it at all
35
+ # It's easier to just implement it without trying to import the functionality
36
+ # Implementation is the same as shlex.join(), see https://github.com/python/cpython/blob/3.8/Lib/shlex.py
37
+ return " ".join(quote(arg) for arg in split_command)
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: oslex2
3
+ Version: 1.0.0
4
+ Summary: OS-independent wrapper for shlex and mslex
5
+ Project-URL: Homepage, https://github.com/jessielw/oslex2
6
+ Project-URL: Bug Tracker, https://github.com/jessielw/oslex2/issues
7
+ Author-email: Jessie Wilson <jessielw4049@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Operating System :: POSIX
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Requires-Python: <3.15,>=3.7
22
+ Requires-Dist: mslex>=1.3.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # oslex2
26
+
27
+ [![CI](https://github.com/jessielw/oslex2/actions/workflows/ci.yml/badge.svg)](https://github.com/jessielw/oslex2/actions/workflows/ci.yml)
28
+ [![PyPI version](https://badge.fury.io/py/oslex2.svg)](https://badge.fury.io/py/oslex2)
29
+
30
+ **oslex2** is an OS-independent wrapper for Python's [`shlex`](https://docs.python.org/3/library/shlex.html) (POSIX) and [`mslex`](https://pypi.org/project/mslex/) (Windows) modules.
31
+
32
+ > Like `os.path` abstracts over `posixpath` and `ntpath`, `oslex2` abstracts over `shlex` and `mslex` for shell-quoting and splitting.
33
+
34
+ ## Features
35
+
36
+ - Unified API for shell quoting, splitting, and joining on all platforms
37
+ - Automatically uses `shlex` on POSIX and `mslex` on Windows
38
+ - Drop-in replacement for `shlex` in cross-platform code
39
+
40
+ ## Installation
41
+
42
+ ```sh
43
+ pip install oslex2
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ import oslex2
50
+
51
+ # Safely quote a string for the shell
52
+ cmd = oslex2.quote('foo; rm -rf /')
53
+
54
+ # Split a shell command into arguments
55
+ args = oslex2.split('python -m pip install "oslex2>=1.0.0"')
56
+
57
+ # Join arguments into a shell command
58
+ command = oslex2.join(["python", "-m", "pip", "install", "oslex2>=1.0.0"])
59
+ ```
60
+
61
+ ## API
62
+
63
+ - `oslex2.quote(s: str, **kwargs) -> str`: Shell-escape a string for safe use as a single token.
64
+ - `oslex2.split(s: str, **kwargs) -> List[str]`: Split a shell command string into arguments.
65
+ - `oslex2.join(args: List[str]) -> str`: Join arguments into a shell-escaped command string.
66
+
67
+ **Note:** All functions accept `**kwargs` and pass them through to the underlying `shlex` or `mslex` implementation. This allows you to use platform-specific options (such as `posix`, `punctuation_chars`, etc.) as needed.
68
+
69
+ ## Platform Detection
70
+
71
+ - On Windows, uses `mslex` for Windows shell syntax.
72
+ - On all other platforms, uses the standard library `shlex`.
73
+
74
+ ## License
75
+
76
+ - MIT License (this library)
77
+ - [`mslex`](https://pypi.org/project/mslex/) is Apache 2.0
78
+
79
+ ## Links
80
+
81
+ - [GitHub](https://github.com/jessielw/oslex2/)
82
+ - [PyPI](https://pypi.org/project/oslex2/)
83
+ - [mslex on PyPI](https://pypi.org/project/mslex/)
@@ -0,0 +1,5 @@
1
+ oslex2/__init__.py,sha256=-CBjP5LxXDgxWY3xEkm7MPmFmjHP0cxf9o7KgXZiAQ4,1472
2
+ oslex2-1.0.0.dist-info/METADATA,sha256=4FJt9JmyWtWJGy3q4sZvoxneYwqiq89JxhmnzaTstaA,3030
3
+ oslex2-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ oslex2-1.0.0.dist-info/licenses/LICENSE,sha256=K9p6RBnvTDt8wznkYkIo6R9e_KBjuwYGxMy2CQs9g50,1070
5
+ oslex2-1.0.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.22.4
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Tamás PEREGI
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jessie Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
oslex2/py.typed DELETED
File without changes
@@ -1,38 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: oslex2
3
- Version: 0.1.5
4
- Summary: OS-independent wrapper for shlex and mslex, meant to be temporary until original repo updates PR
5
- Project-URL: Homepage, https://github.com/petamas/oslex
6
- Project-URL: Bug Tracker, https://github.com/petamas/oslex/issues
7
- Author-email: Jessie Wilson <jessielw4049@gmail.com>
8
- License-File: LICENSE
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: MacOS
11
- Classifier: Operating System :: Microsoft :: Windows
12
- Classifier: Operating System :: POSIX
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.6
15
- Classifier: Programming Language :: Python :: 3.7
16
- Classifier: Programming Language :: Python :: 3.8
17
- Classifier: Programming Language :: Python :: 3.9
18
- Classifier: Programming Language :: Python :: 3.10
19
- Classifier: Programming Language :: Python :: 3.11
20
- Requires-Python: >=3.5
21
- Requires-Dist: mslex
22
- Description-Content-Type: text/markdown
23
-
24
- # oslex
25
-
26
- `oslex` is an OS-independent wrapper for [`shlex`](https://docs.python.org/3/library/shlex.html) and [`mslex`](https://pypi.org/project/mslex/).
27
-
28
- Its main purpose is to provide functions similar in functionality to `shlex.quote()`, `shlex.split()` and `shlex.join()` on both Windows and POSIX-compatible platforms.
29
-
30
- This goal is achieved by simply forwarding the calls to either `shlex` (from the standard library) on POSIX-compatible systems, or the excellent `mslex` library (written by Lawrence D'Anna / @smoofra) on Windows.
31
-
32
- In other words, `oslex` is to `shlex`/`mslex` what `os-path` is to `posixpath`/`ntpath`.
33
-
34
- ## Licensing
35
-
36
- This library itself is licensed under the MIT license.
37
-
38
- `oslex` uses the [`mslex`](https://pypi.org/project/mslex/) library, which is distributed under the Apache 2.0 license.
@@ -1,6 +0,0 @@
1
- oslex2/__init__.py,sha256=kVUF4amT10x17VEVoMhb43mFMaMr9xl-Kf9vpLVhPg8,2654
2
- oslex2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- oslex2-0.1.5.dist-info/METADATA,sha256=AyxwQEVrc02RP6AAnanOEj2E4pY8C4dDWjUB3YDlXaM,1787
4
- oslex2-0.1.5.dist-info/WHEEL,sha256=uNdcs2TADwSd5pVaP0Z_kcjcvvTUklh2S7bxZMF8Uj0,87
5
- oslex2-0.1.5.dist-info/licenses/LICENSE,sha256=ZXB8tGHQGN6AIY-xxMUcN60DM-WA5XusmM6JlArTpm0,1091
6
- oslex2-0.1.5.dist-info/RECORD,,