A readable, reliable, reviewable solution for escaping NT command-line arguments with explicit, single-pass state machine logic.
Project description
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.
Project details
Release history Release notifications | RSS feed
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 escape_nt_command_line_argument-0.1.0a0.tar.gz.
File metadata
- Download URL: escape_nt_command_line_argument-0.1.0a0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25849f1b3367f7e90ed20e8ebf690302c6889c3a1e26422b127b0e31161a681a
|
|
| MD5 |
da94194c15f727c630edb9676385d26d
|
|
| BLAKE2b-256 |
4eb4413a6753c92a0bf72c1244151d17cfb688cb753c3edaed4a4102cbf0cae9
|
File details
Details for the file escape_nt_command_line_argument-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: escape_nt_command_line_argument-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a9e43adfaedfb320aaa8f730862ac2259eea8ce7d1d542f0816b1a1b83a82da
|
|
| MD5 |
7f705fc093a4fb9bdc784bacaedfc0bf
|
|
| BLAKE2b-256 |
e786367fc5551212b7010abf28794f9cc5e75c5c8340bdf7a7b4277e3b99a5f0
|