This release is a pre-release and may not be stable for production use.
escape-nt-command-line-argument
A readable, reliable, reviewable solution for escaping NT command-line arguments with explicit, single-pass state machine logic.
Features
- Correctly escapes any argument for safe use with
CreateProcessW, including all tricky cases (backslashes, quotes, whitespace, trailing slashes, etc.) - Explicit, single-pass state machine logic: readable, reliable, reviewable.
- Immutable, functional programming style: each character is processed atomically, ensuring precise and predictable results.
- Supports Python 2+.
Installation
pip install escape-nt-command-line-argument
Usage
# coding=utf-8
from __future__ import print_function
import sys
from typing import Text
from escape_nt_command_line_argument import escape_nt_command_line_argument
if sys.version_info < (3,):
def raw_unicode_input(prompt):
# type: (Text) -> Text
return raw_input(prompt.encode(sys.stdout.encoding)).decode(sys.stdin.encoding)
else:
def raw_unicode_input(prompt):
# type: (Text) -> Text
return input(prompt)
while True:
to_escape = raw_unicode_input(u'Enter an NT command-line argument: ')
print(escape_nt_command_line_argument(to_escape))
Enter an NT command-line argument: C:\Users
C:\Users
Enter an NT command-line argument: C:\Program Files
"C:\Program Files"
Enter an NT command-line argument: \
"\\"
Enter an NT command-line argument: \\
"\\\\"
Enter an NT command-line argument: \\\
"\\\\\\"
Enter an NT command-line argument: "
"\""
Enter an NT command-line argument: ""
"\"\""
Enter an NT command-line argument: \"
"\\\""
Enter an NT command-line argument: \\"
"\\\\\""
Enter an NT command-line argument: "\"
"\"\\\""
Enter an NT command-line argument: \\""
"\\\\\"\""
Enter an NT command-line argument: C:\Users\
"C:\Users\\"
Enter an NT command-line argument: "abc" & "def"
"\"abc\" & \"def\""
Enter an NT command-line argument: "a&"b"c"d""
"\"a&\"b\"c\"d\"\""
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Metadata
Release files for escape-nt-command-line-argument 0.1.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| escape_nt_command_line_argument-0.1.0a0.tar.gz | 3.5 kB | Without provenance | Details for escape_nt_command_line_argument-0.1.0a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| escape_nt_command_line_argument-0.1.0a0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for escape_nt_command_line_argument-0.1.0a0-py2.py3-none-any.whl |
Total release size: 7.6 kB
Release files / escape_nt_command_line_argument-0.1.0a0.tar.gz
| Download URL | escape_nt_command_line_argument-0.1.0a0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25849f1b3367f7e90ed20e8ebf690302c6889c3a1e26422b127b0e31161a681a
|
|
BLAKE2b-256 checksum How to use checksums |
4eb4413a6753c92a0bf72c1244151d17cfb688cb753c3edaed4a4102cbf0cae9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / escape_nt_command_line_argument-0.1.0a0-py2.py3-none-any.whl
| Download URL | escape_nt_command_line_argument-0.1.0a0-py2.py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
8a9e43adfaedfb320aaa8f730862ac2259eea8ce7d1d542f0816b1a1b83a82da
|
|
BLAKE2b-256 checksum How to use checksums |
e786367fc5551212b7010abf28794f9cc5e75c5c8340bdf7a7b4277e3b99a5f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for escape-nt-command-line-argument 0.1.0a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.