Skip to content

Commit

Permalink
Fix import error on Python 3.13
Browse files Browse the repository at this point in the history
Rework `escape_param` to work on Python 3.13.  One of `shlex.quote` or
`pipes.quote` exists on all Python versions (back to Python 0.9.8!), so
the fallback code for systems that have neither is unnecessary.
  • Loading branch information
cjwatson committed Oct 29, 2024
1 parent 751de1b commit f4b34f5
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions plugins/module_utils/mongodb_shell.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

# DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
# Ignore for now
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

import shlex
import pipes
import re
import json
import os

try:
from shlex import quote
except ImportError:
from pipes import quote

Check warning on line 11 in plugins/module_utils/mongodb_shell.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/mongodb_shell.py#L10-L11

Added lines #L10 - L11 were not covered by tests


def escape_param(param):
'''
Escapes the given parameter
@param - The parameter to escape
'''
escaped = None
if hasattr(shlex, 'quote'):
escaped = shlex.quote(param)
elif hasattr(pipes, 'quote'):
escaped = pipes.quote(param)
else:
escaped = "'" + param.replace("'", "'\\''") + "'"
return escaped
return quote(param)


def add_arg_to_cmd(cmd_list, param_name, param_value, is_bool=False, omit=None):
Expand Down

0 comments on commit f4b34f5

Please sign in to comment.