if not s:
return "''"
+ if not isinstance(s, str):
+ raise TypeError(f"expected string object, got {type(s).__name__!r}")
+
# Use bytes.translate() for performance
safe_chars = (b'%+,-./0123456789:=@'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
unsafe = '"`$\\!' + unicode_sample
self.assertEqual(shlex.quote(''), "''")
+ self.assertEqual(shlex.quote(None), "''")
self.assertEqual(shlex.quote(safeunquoted), safeunquoted)
self.assertEqual(shlex.quote('test file name'), "'test file name'")
for u in unsafe:
for u in unsafe:
self.assertEqual(shlex.quote("test%s'name'" % u),
"'test%s'\"'\"'name'\"'\"''" % u)
+ self.assertRaises(TypeError, shlex.quote, 42)
+ self.assertRaises(TypeError, shlex.quote, b"abc")
def testJoin(self):
for split_command, command in [