Kaydet (Commit) 42dd86b8 authored tarafından Neal Norwitz's avatar Neal Norwitz

Deprecate os.popen* and popen2 module in favor of the subprocess module.

üst 82be218e
......@@ -666,9 +666,15 @@ if _exists("fork"):
is a string it will be passed to the shell (as with os.system()). If
'bufsize' is specified, it sets the buffer size for the I/O pipes. The
file objects (child_stdin, child_stdout) are returned."""
import popen2
stdout, stdin = popen2.popen2(cmd, bufsize)
return stdin, stdout
import warnings
msg = "os.popen2 is deprecated. Use the subprocess module."
warnings.warn(msg, DeprecationWarning, stacklevel=2)
import subprocess
PIPE = subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, close_fds=True)
return p.stdin, p.stdout
__all__.append("popen2")
if not _exists("popen3"):
......@@ -679,9 +685,16 @@ if _exists("fork"):
is a string it will be passed to the shell (as with os.system()). If
'bufsize' is specified, it sets the buffer size for the I/O pipes. The
file objects (child_stdin, child_stdout, child_stderr) are returned."""
import popen2
stdout, stdin, stderr = popen2.popen3(cmd, bufsize)
return stdin, stdout, stderr
import warnings
msg = "os.popen3 is deprecated. Use the subprocess module."
warnings.warn(msg, DeprecationWarning, stacklevel=2)
import subprocess
PIPE = subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, stderr=PIPE,
close_fds=True)
return p.stdin, p.stdout, p.stderr
__all__.append("popen3")
if not _exists("popen4"):
......@@ -692,9 +705,16 @@ if _exists("fork"):
is a string it will be passed to the shell (as with os.system()). If
'bufsize' is specified, it sets the buffer size for the I/O pipes. The
file objects (child_stdin, child_stdout_stderr) are returned."""
import popen2
stdout, stdin = popen2.popen4(cmd, bufsize)
return stdin, stdout
import warnings
msg = "os.popen4 is deprecated. Use the subprocess module."
warnings.warn(msg, DeprecationWarning, stacklevel=2)
import subprocess
PIPE = subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE,
stderr=subprocess.STDOUT, close_fds=True)
return p.stdin, p.stdout
__all__.append("popen4")
import copy_reg as _copy_reg
......
......@@ -14,7 +14,7 @@ intention is that the end user will use this through a GUI.
"""
import sys
import os
import popen2
import subprocess
import urllib
import urllib2
import urlparse
......@@ -101,10 +101,11 @@ def _cmd(output, dir, *cmditems):
output.write("+ %s\n" % cmd)
if NO_EXECUTE:
return 0
child = popen2.Popen4(cmd)
child.tochild.close()
child = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
child.stdin.close()
while 1:
line = child.fromchild.readline()
line = child.stdout.readline()
if not line:
break
if output:
......
......@@ -8,6 +8,9 @@ and popen3(cmd) which return two or three pipes to the spawned command.
import os
import sys
import warnings
warnings.warn("The popen2 module is deprecated. Use the subprocess module.",
DeprecationWarning, stacklevel=2)
__all__ = ["popen2", "popen3", "popen4"]
......
......@@ -9,6 +9,8 @@ warnings.filterwarnings("ignore",
"<string>")
warnings.filterwarnings("ignore", "the sets module is deprecated",
DeprecationWarning, "<string>")
warnings.filterwarnings("ignore", ".*popen2 module is deprecated.*",
DeprecationWarning)
class AllTest(unittest.TestCase):
......
......@@ -5,7 +5,7 @@ from test.test_support import TESTFN
import unittest
from cStringIO import StringIO
import os
import popen2
import subprocess
import sys
import bz2
......@@ -21,18 +21,20 @@ class BaseTest(unittest.TestCase):
if has_cmdline_bunzip2:
def decompress(self, data):
pop = popen2.Popen3("bunzip2", capturestderr=1)
pop.tochild.write(data)
pop.tochild.close()
ret = pop.fromchild.read()
pop.fromchild.close()
pop = subprocess.Popen("bunzip2", shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
pop.stdin.write(data)
pop.stdin.close()
ret = pop.stdout.read()
pop.stdout.close()
if pop.wait() != 0:
ret = bz2.decompress(data)
return ret
else:
# popen2.Popen3 doesn't exist on Windows, and even if it did, bunzip2
# isn't available to run.
# bunzip2 isn't available to run on Windows.
def decompress(self, data):
return bz2.decompress(data)
......
import test.test_support, unittest
import sys
import popen2
import subprocess
class CmdLineTest(unittest.TestCase):
def start_python(self, cmd_line):
outfp, infp = popen2.popen4('"%s" %s' % (sys.executable, cmd_line))
infp.close()
data = outfp.read()
outfp.close()
cmd = '"%s" %s' % (sys.executable, cmd_line)
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.stdin.close()
data = p.stdout.read()
p.stdout.close()
# try to cleanup the child so we don't appear to leak when running
# with regrtest -R. This should be a no-op on Windows.
popen2._cleanup()
subprocess._cleanup()
return data
def exit_code(self, *args):
......
#! /usr/bin/env python
"""Test script for popen2.py"""
import warnings
warnings.filterwarnings("ignore", ".*popen2 module is deprecated.*",
DeprecationWarning)
warnings.filterwarnings("ignore", "os\.popen. is deprecated.*",
DeprecationWarning)
import os
import sys
import unittest
......
......@@ -207,6 +207,8 @@ Core and builtins
Library
-------
- The popen2 module and os.popen* are deprecated. Use the subprocess module.
- Added an optional credentials argument to SMTPHandler, for use with SMTP
servers which require authentication.
......
......@@ -5,7 +5,7 @@ import win32com.client.gencache
import win32com.client
import pythoncom, pywintypes
from win32com.client import constants
import re, string, os, sets, glob, popen2, sys, _winreg, struct
import re, string, os, sets, glob, subprocess, sys, _winreg, struct
try:
basestring
......@@ -388,8 +388,10 @@ class CAB:
else:
print "WARNING: cabarc.exe not found in registry"
cabarc = "cabarc.exe"
f = popen2.popen4(r'"%s" -m lzx:21 n %s.cab @%s.txt' % (cabarc, self.name, self.name))[0]
for line in f:
cmd = r'"%s" -m lzx:21 n %s.cab @%s.txt' % (cabarc, self.name, self.name)
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)[0]
for line in (p.stdout, p.stdin):
if line.startswith(" -- adding "):
sys.stdout.write(".")
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment