MCPcopy Index your code
hub / github.com/python/cpython / quote

Function quote

Lib/shlex.py:320–338  ·  view source on GitHub ↗

Return a shell-escaped version of the string *s*.

(s)

Source from the content-addressed store, hash-verified

318
319
320def quote(s):
321 """Return a shell-escaped version of the string *s*."""
322 if not s:
323 return "''"
324
325 if not isinstance(s, str):
326 raise TypeError(f"expected string object, got {type(s).__name__!r}")
327
328 # Use bytes.translate() for performance
329 safe_chars = (b'%+,-./0123456789:=@'
330 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
331 b'abcdefghijklmnopqrstuvwxyz')
332 # No quoting is needed if `s` is an ASCII string consisting only of `safe_chars`
333 if s.isascii() and not s.encode().translate(None, delete=safe_chars):
334 return s
335
336 # use single quotes, and put single quotes into double quotes
337 # the string $'b is then quoted as '$'"'"'b'
338 return "'" + s.replace("'", "'\"'\"'") + "'"
339
340
341def _print_tokens(lexer):

Callers 1

joinFunction · 0.70

Calls 4

isasciiMethod · 0.80
translateMethod · 0.45
encodeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…