Skip to main content

OS-independent wrapper for shlex and mslex

Project description

oslex2

CI PyPI version

oslex2 is an OS-independent wrapper for Python's shlex (POSIX) and mslex (Windows) modules.

Like os.path abstracts over posixpath and ntpath, oslex2 abstracts over shlex and mslex for shell-quoting and splitting.

Features

  • Unified API for shell quoting, splitting, and joining on all platforms
  • Automatically uses shlex on POSIX and mslex on Windows
  • Drop-in replacement for shlex in cross-platform code

Installation

pip install oslex2

Usage

import oslex2

# Safely quote a string for the shell
cmd = oslex2.quote('foo; rm -rf /')

# Split a shell command into arguments
args = oslex2.split('python -m pip install "oslex2>=1.0.0"')

# Join arguments into a shell command
command = oslex2.join(["python", "-m", "pip", "install", "oslex2>=1.0.0"])

API

  • oslex2.quote(s: str, **kwargs) -> str: Shell-escape a string for safe use as a single token.
  • oslex2.split(s: str, **kwargs) -> List[str]: Split a shell command string into arguments.
  • oslex2.join(args: List[str]) -> str: Join arguments into a shell-escaped command string.

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.

Platform Detection

  • On Windows, uses mslex for Windows shell syntax.
  • On all other platforms, uses the standard library shlex.

License

  • MIT License (this library)
  • mslex is Apache 2.0

Links

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

oslex2-1.0.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oslex2-1.0.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file oslex2-1.0.0.tar.gz.

File metadata

  • Download URL: oslex2-1.0.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oslex2-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f85ade0d6594e77b4388105c45de7880c7ec57ef018a6ff80088cd392bcd1876
MD5 1910a9f13a2ba837757d98b1d7a77d76
BLAKE2b-256 c65dfaf8eff4efea3e55ce6cc597ab777af4c9d5a5b3f21dba3224729a7e8bc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for oslex2-1.0.0.tar.gz:

Publisher: pypi.yml on jessielw/oslex2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oslex2-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: oslex2-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oslex2-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2db57a36da65b83b482ff140f7637a02249fc324ba23189b1ed64bd7b928151
MD5 7c1ceba808e0d6462ffb6ee4530018bb
BLAKE2b-256 ae33671e0118ee490cd4be9e9674d94aa483dccb66ba37b8a440ca1951b4e2ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for oslex2-1.0.0-py3-none-any.whl:

Publisher: pypi.yml on jessielw/oslex2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page