Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,21 @@ def _syscmd_file(target, default=''):

import subprocess
target = _follow_symlinks(target)
# "file" output is locale dependent: force the usage of the C locale
# to get deterministic behavior.
env = dict(os.environ, LC_ALL='C')
try:
output = subprocess.check_output(['file', target],
# -b: do not prepend filenames to output lines (brief mode)
output = subprocess.check_output(['file', '-b', target],
stderr=subprocess.DEVNULL,
encoding='latin-1')
env=env)
except (OSError, subprocess.CalledProcessError):
return default
return (output or default)
if not output:
return default
# With the C locale, the output should be mostly ASCII-compatible.
# Decode from Latin-1 to prevent Unicode decode error.
return output.decode('latin-1')

### Information about the used architecture

Expand Down Expand Up @@ -676,7 +684,7 @@ def architecture(executable=sys.executable, bits='', linkage=''):
linkage = l
return bits, linkage

if 'executable' not in fileout:
if 'executable' not in fileout and 'shared object' not in fileout:
# Format not supported
return bits, linkage

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Make :func:`platform.architecture` parsing of ``file`` command output more
reliable: add the ``-b`` option to the ``file`` command to omit the filename,
force the usage of the C locale, and search also the "shared object" pattern.