OS-independent wrapper for shlex and mslex
Project description
oslex
oslex is an OS-independent wrapper for shlex and mslex.
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.
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.
In other words, oslex is to shlex/mslex what os.path is to posixpath/ntpath.
Reference
The three main interface functions are oslex.join(), oslex.quote() and oslex.split().
They all support taking a single positional argument, and a variety of optional keyword arguments. Keyword arguments starting with ms_ are passed to the underlying mslex function on Windows, and are ignored on non-Windows platforms. Keyword arguments starting with sh_ are passed to the underlying shlex function on non-Windows platforms, and are ignored on Windows. The default values of keyword arguments are the same as for the underlying libraries.
In addition, each function has two extra variants: one with the suffix _sh, and one with the suffix _ms. They have the exact same interface as the main variants, except they always call the shlex or mslex library functions instead of deciding based on platform. They can be useful in situations when a specific implementation is needed regardless of platform, but support for Path arguments is desirable.
oslex.join()
Quote arguments according to platform-specific rules, then join them to form a full command line. Returns str.
Calls mslex.join() on Windows, and shlex.join() on non-Windows platforms.
Arguments:
| Name | Type | Default | Kind | Description |
|---|---|---|---|---|
command |
Sequence[str|Path] |
required | positional-only | Argument list to quote. Supports mixing str and Path arguments.Paths are converted to str before passing to the underlying join() function. |
ms_for_cmd |
bool |
True |
keyword-only | Passed to mslex.join() as for_cmd argument on Windows.Ignored on non-Windows platforms. See mslex.join()'s documentation for more details. |
oslex.quote()
Quote argument according to platform-specific rules. Returns str.
Calls mslex.quote() on Windows, and shlex.quote() on non-Windows platforms.
Arguments:
| Name | Type | Default | Kind | Description |
|---|---|---|---|---|
arg |
str|Path |
required | positional-only | Argument to quote.Paths are converted to str before passing to the underlying quote() function. |
ms_for_cmd |
bool |
True |
keyword-only | Passed to mslex.quote() as for_cmd argument on Windows.Ignored on non-Windows platforms. See mslex.quote()'s documentation for more details. |
oslex.split()
Split command line into arguments according to platform-specific rules. Returns list[str].
Calls mslex.split() on Windows, and shlex.split() on non-Windows platforms.
Arguments:
| Name | Type | Default | Kind | Description |
|---|---|---|---|---|
command_str |
str |
required | positional-only | Command string to split. |
ms_like_cmd |
bool |
True |
keyword-only | Passed to mslex.split() as like_cmd argument on Windows.Ignored on non-Windows platforms. See mslex.split()'s documentation for more details. |
ms_check |
bool |
True |
keyword-only | Passed to mslex.split() as check argument on Windows.Ignored on non-Windows platforms. See mslex.split()'s documentation for more details. |
ms_ucrt |
bool | None |
None |
keyword-only | Passed to mslex.split() as ucrt argument on Windows.Ignored on non-Windows platforms. See mslex.split()'s documentation for more details. |
sh_comments |
bool |
False |
keyword-only | Passed to shlex.split() as comments argument on non-Windows platforms.Ignored on Windows. See shlex.split()'s documentation for more details. |
sh_posix |
bool |
True |
keyword-only | Passed to shlex.split() as posix argument on non-Windows platforms.Ignored on Windows. Ignored on Windows. See shlex.split()'s documentation for more details. |
oslex.join_ms(), oslex.quote_ms(), oslex.split_ms()
Same as oslex.join(), oslex.quote() and oslex.split(), except they always call mslex regardless of platform.
See documentation of arguments at the respective function. (Keyword arguments starting with sh_ are always ignored.)
oslex.join_sh(), oslex.quote_sh(), oslex.split_sh()
Same as oslex.join(), oslex.quote() and oslex.split(), except they always call shlex regardless of platform.
See documentation of arguments at the respective function. (Keyword arguments starting with ms_ are always ignored.)
Licensing
This library itself is licensed under the MIT license.
oslex uses the mslex library, which is distributed under the Apache 2.0 license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oslex-2.0.0.tar.gz.
File metadata
- Download URL: oslex-2.0.0.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30d9f4a7201bdce3ab7d9cfc0f9ee9e18c423b2b1d1668141b0dd3594b368ffe
|
|
| MD5 |
ac9b59a5f3dbcbe287a064b0c7962945
|
|
| BLAKE2b-256 |
2419b74ea9590378a35014acf72f221e84c5980aa7531d1852ef961764e7d3a6
|
File details
Details for the file oslex-2.0.0-py3-none-any.whl.
File metadata
- Download URL: oslex-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1c2944072aafcb06b6ee8a6c018d9ebb8a7f43d7cf0b6630b4f5d7be45f6ae4
|
|
| MD5 |
d8b64319c992d14ced67a5cb0ccce9ee
|
|
| BLAKE2b-256 |
b1d13c0bad919598c4216944934db565ed9834ad5b792e1b5e67e911bb2976d2
|