|
| 1 | +From: "Benjamin A. Beasley" < [email protected]> |
| 2 | +Date: Thu, 30 May 2024 23:05:14 -0400 |
| 3 | +Subject: Replace pipes.quote with shlex.quote on Python 3 |
| 4 | + |
| 5 | +The shlex.quote() API is available from Python 3.3 on; pipes.quote() was |
| 6 | +never documented, and is removed in Python 3.13. |
| 7 | + |
| 8 | +Fixes #73. |
| 9 | + |
| 10 | +Origin: other, https://github.com/xolox/python-humanfriendly/pull/75 |
| 11 | +Bug: https://github.com/xolox/python-humanfriendly/issues/73 |
| 12 | +Bug-Debian: https://bugs.debian.org/1084718 |
| 13 | +Last-Update: 2024-10-07 |
| 14 | +--- |
| 15 | + humanfriendly/cli.py | 8 ++++++-- |
| 16 | + humanfriendly/testing.py | 8 ++++++-- |
| 17 | + 2 files changed, 12 insertions(+), 4 deletions(-) |
| 18 | + |
| 19 | +diff --git a/humanfriendly/cli.py b/humanfriendly/cli.py |
| 20 | +index eb81db1..5dfc14a 100644 |
| 21 | +--- a/humanfriendly/cli.py |
| 22 | ++++ b/humanfriendly/cli.py |
| 23 | +@@ -79,10 +79,14 @@ Supported options: |
| 24 | + # Standard library modules. |
| 25 | + import functools |
| 26 | + import getopt |
| 27 | +-import pipes |
| 28 | + import subprocess |
| 29 | + import sys |
| 30 | + |
| 31 | ++try: |
| 32 | ++ from shlex import quote # Python 3 |
| 33 | ++except ImportError: |
| 34 | ++ from pipes import quote # Python 2 (removed in 3.13) |
| 35 | ++ |
| 36 | + # Modules included in our package. |
| 37 | + from humanfriendly import ( |
| 38 | + Timer, |
| 39 | +@@ -176,7 +180,7 @@ def main(): |
| 40 | + def run_command(command_line): |
| 41 | + """Run an external command and show a spinner while the command is running.""" |
| 42 | + timer = Timer() |
| 43 | +- spinner_label = "Waiting for command: %s" % " ".join(map(pipes.quote, command_line)) |
| 44 | ++ spinner_label = "Waiting for command: %s" % " ".join(map(quote, command_line)) |
| 45 | + with Spinner(label=spinner_label, timer=timer) as spinner: |
| 46 | + process = subprocess.Popen(command_line) |
| 47 | + while True: |
| 48 | +diff --git a/humanfriendly/testing.py b/humanfriendly/testing.py |
| 49 | +index f6abddf..f9d66e4 100644 |
| 50 | +--- a/humanfriendly/testing.py |
| 51 | ++++ b/humanfriendly/testing.py |
| 52 | +@@ -25,13 +25,17 @@ its much better error reporting) but I've yet to publish a test suite that |
| 53 | + import functools |
| 54 | + import logging |
| 55 | + import os |
| 56 | +-import pipes |
| 57 | + import shutil |
| 58 | + import sys |
| 59 | + import tempfile |
| 60 | + import time |
| 61 | + import unittest |
| 62 | + |
| 63 | ++try: |
| 64 | ++ from shlex import quote # Python 3 |
| 65 | ++except ImportError: |
| 66 | ++ from pipes import quote # Python 2 (removed in 3.13) |
| 67 | ++ |
| 68 | + # Modules included in our package. |
| 69 | + from humanfriendly.compat import StringIO |
| 70 | + from humanfriendly.text import random_string |
| 71 | +@@ -521,7 +525,7 @@ class MockedProgram(CustomSearchPath): |
| 72 | + pathname = os.path.join(directory, self.program_name) |
| 73 | + with open(pathname, 'w') as handle: |
| 74 | + handle.write('#!/bin/sh\n') |
| 75 | +- handle.write('echo > %s\n' % pipes.quote(self.program_signal_file)) |
| 76 | ++ handle.write('echo > %s\n' % quote(self.program_signal_file)) |
| 77 | + if self.program_script: |
| 78 | + handle.write('%s\n' % self.program_script.strip()) |
| 79 | + handle.write('exit %i\n' % self.program_returncode) |
0 commit comments