[New-bugs-announce] [issue9560] platform.py: use -b option for file command in _syscmd_file()

STINNER Victor report at bugs.python.org
Tue Aug 10 19:21:34 CEST 2010

New submission from STINNER Victor <victor.stinner at haypocalc.com>:

Lib/platform.py was created 7 years ago by r32391. _syscmd_file() docstring was never changed whereas it is inconsistent with the implementation:
def _syscmd_file(target,default=''):

    """ Interface to the system's file command.

        The function uses the -b option of the file command to have it
        ommit the filename in its output and if possible the -L option
        to have the command follow symlinks. It returns default in
        case the command should fail.

    target = _follow_symlinks(target).replace('"', '\\"')
    f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))

It doesn't use -L option but use Python to follow the link, and use an regex to remove the filename.

Attached patch enables -b option to avoid problem with non-ascii filenames but ascii locale encoding (see #8611 and #9425) and updates the docstring.


To fix the non-ascii problem, I tried a different approach by using subprocess API which gives a bytes version of stdout and so avoid the encoding issue. But I commited the patch on python trunk (2.7) which had a bootstrap issue. py3k had no bootstrap issue, but the new patch (use -b option) is simpler.

Commits: r80166 (trunk), r80167 (py3k). Reverted: r80171+r80189 (trunk) and r80190 (py3k).

More details in the following mail thread:

files: _syscmd_file.patch
keywords: patch
messages: 113549
nosy: haypo, lemburg, pitrou
priority: normal
severity: normal
status: open
title: platform.py: use -b option for file command in _syscmd_file()
versions: Python 3.2
Added file: http://bugs.python.org/file18470/_syscmd_file.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list