-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathshlex_posix.py
38 lines (32 loc) · 955 Bytes
/
shlex_posix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
#
# Copyright 2007 Doug Hellmann.
"""Differences between POSIX and non-POSIX parsing.
"""
#end_pymotw_header
import shlex
examples = [
'Do"Not"Separate',
'"Do"Separate',
'Escaped \e Character not in quotes',
'Escaped "\e" Character in double quotes',
"Escaped '\e' Character in single quotes",
r"Escaped '\'' \"\'\" single quote",
r'Escaped "\"" \'\"\' double quote',
"\"'Strip extra layer of quotes'\"",
]
for s in examples:
print('ORIGINAL : {!r}'.format(s))
print('non-POSIX: ', end='')
non_posix_lexer = shlex.shlex(s, posix=False)
try:
print('{!r}'.format(list(non_posix_lexer)))
except ValueError as err:
print('error({})'.format(err))
print('POSIX : ', end='')
posix_lexer = shlex.shlex(s, posix=True)
try:
print('{!r}'.format(list(posix_lexer)))
except ValueError as err:
print('error({})'.format(err))
print()