oslex2 0.1.5__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 ADDED
@@ -0,0 +1,69 @@
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)
oslex2/py.typed ADDED
File without changes
@@ -0,0 +1,38 @@
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.
@@ -0,0 +1,6 @@
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,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.22.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +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.