Skip to content

Commit

Permalink
pep-594: drop deprecated pipes module import
Browse files Browse the repository at this point in the history
python3.11 will deprecated pipes module 3.13 will drop it from main.

cloud-init only used the undocumented pipes.quote function,
which is actually only wrapper around shlex.quote[1].

Use shlex.quote instead.

[1] https://github.com/python/cpython/blob/3.11/Lib/pipes.py#L64-L66
  • Loading branch information
blackboxsw authored Aug 28, 2023
1 parent 3b58835 commit 72949ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cloudinit/distros/parsers/sys_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

import pipes
import re
import shlex
from io import StringIO

# This library is used to parse/write
Expand Down Expand Up @@ -82,7 +82,7 @@ def _quote(self, value, multiline=False):
if re.search(r"[\t\r\n ]", value):
if _contains_shell_variable(value):
# If it contains shell variables then we likely want to
# leave it alone since the pipes.quote function likes
# leave it alone since the shlex.quote function likes
# to use single quotes which won't get expanded...
if re.search(r"[\n\"']", value):
quot_func = (
Expand All @@ -93,7 +93,7 @@ def _quote(self, value, multiline=False):
lambda x: self._get_single_quote(x) % x
) # noqa: E731
else:
quot_func = pipes.quote
quot_func = shlex.quote
if not quot_func:
return value
return quot_func(value)
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/distros/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_parse_adjust(self):
conf["IPV6TO4_ROUTING"] = "blah \tblah"
contents2 = str(conf).strip()
# Should be requoted due to whitespace
self.assertRegex(contents2, r"IPV6TO4_ROUTING=[\']blah\s+blah[\']")
self.assertRegex(contents2, r"IPV6TO4_ROUTING='blah\s+blah'")

def test_parse_no_adjust_shell(self):
conf = SysConf("".splitlines())
Expand Down

0 comments on commit 72949ee

Please sign in to comment.