diff options
author | Mike Frysinger <vapier@google.com> | 2023-06-08 15:06:39 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2023-06-08 23:08:49 -0400 |
commit | 6391d356469ebc79312898ae8bb995f600a2137f (patch) | |
tree | 98b74fc67f48946e618be25f07abcfdccf3709f0 | |
parent | fed77e7ee9e3efe59f77db0d50d31fe8b14a3012 (diff) | |
download | repohooks-6391d356469ebc79312898ae8bb995f600a2137f.tar.gz |
shell: drop redundant prefix
Since the module is named "shell", we don't need to also prefix the
function names with "shell_" otherwise we end up with usage like
rh.shell.shell_quote(...).
Bug: None
Test: unittests
Change-Id: I144d0e814da4e6f6844360da061a4dd52b6c8cb3
-rw-r--r-- | rh/shell.py | 6 | ||||
-rwxr-xr-x | rh/shell_unittest.py | 12 |
2 files changed, 9 insertions, 9 deletions
diff --git a/rh/shell.py b/rh/shell.py index bece0b2..bc66f37 100644 --- a/rh/shell.py +++ b/rh/shell.py @@ -39,7 +39,7 @@ _SHELL_QUOTABLE_CHARS = frozenset('[|&;()<> \t!{}[]=*?~$"\'\\#^') _SHELL_ESCAPE_CHARS = r'\"`$' -def shell_quote(s): +def quote(s): """Quote |s| in a way that is safe for use in a shell. We aim to be safe, but also to produce "nice" output. That means we don't @@ -93,7 +93,7 @@ def shell_quote(s): return f'"{s}"' -def shell_unquote(s): +def unquote(s): """Do the opposite of ShellQuote. This function assumes that the input is a valid escaped string. @@ -148,7 +148,7 @@ def cmd_to_str(cmd): String representing full command. """ # Use str before repr to translate unicode strings to regular strings. - return ' '.join(shell_quote(arg) for arg in cmd) + return ' '.join(quote(arg) for arg in cmd) def boolean_shell_value(sval, default): diff --git a/rh/shell_unittest.py b/rh/shell_unittest.py index f7d2bba..fec8710 100755 --- a/rh/shell_unittest.py +++ b/rh/shell_unittest.py @@ -59,7 +59,7 @@ class DiffTestCase(unittest.TestCase): class ShellQuoteTest(DiffTestCase): - """Test the shell_quote & shell_unquote functions.""" + """Test the quote & unquote functions.""" def testShellQuote(self): """Basic ShellQuote tests.""" @@ -86,10 +86,10 @@ class ShellQuoteTest(DiffTestCase): } def aux(s): - return rh.shell.shell_unquote(rh.shell.shell_quote(s)) + return rh.shell.unquote(rh.shell.quote(s)) - self._testData(rh.shell.shell_quote, tests_quote) - self._testData(rh.shell.shell_unquote, tests_unquote) + self._testData(rh.shell.quote, tests_quote) + self._testData(rh.shell.unquote, tests_unquote) # Test that the operations are reversible. self._testData(aux, {k: k for k in tests_quote.values()}, False) @@ -97,7 +97,7 @@ class ShellQuoteTest(DiffTestCase): def testPathlib(self): """Verify pathlib is handled.""" - self.assertEqual(rh.shell.shell_quote(Path('/')), '/') + self.assertEqual(rh.shell.quote(Path('/')), '/') def testBadInputs(self): """Verify bad inputs do not crash.""" @@ -105,7 +105,7 @@ class ShellQuoteTest(DiffTestCase): (1234, '1234'), (Exception('hi'), "Exception('hi')"), ): - self.assertEqual(rh.shell.shell_quote(arg), exp) + self.assertEqual(rh.shell.quote(arg), exp) class CmdToStrTest(DiffTestCase): |