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