Commit b8e689a6 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-35346, platform: import subprocess in _syscmd_file() (GH-10892)

Only platform._syscmd_file() uses subprocess. Move subprocess import
inside this function to reduce the number of imports at Python
startup.

Remove also warnings import which is no longer needed.
parent 4752e652
...@@ -113,9 +113,9 @@ __copyright__ = """ ...@@ -113,9 +113,9 @@ __copyright__ = """
__version__ = '1.0.8' __version__ = '1.0.8'
import collections import collections
import sys, os, re, subprocess import os
import re
import warnings import sys
### Globals & Constants ### Globals & Constants
...@@ -612,11 +612,13 @@ def _syscmd_file(target, default=''): ...@@ -612,11 +612,13 @@ def _syscmd_file(target, default=''):
if sys.platform in ('dos', 'win32', 'win16'): if sys.platform in ('dos', 'win32', 'win16'):
# XXX Others too ? # XXX Others too ?
return default return default
import subprocess
target = _follow_symlinks(target) target = _follow_symlinks(target)
try: try:
proc = subprocess.Popen(['file', target], proc = subprocess.Popen(['file', target],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
except (AttributeError, OSError): except (AttributeError, OSError):
return default return default
output = proc.communicate()[0].decode('latin-1') output = proc.communicate()[0].decode('latin-1')
......
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