Author vstinner
Recipients lemburg, pitrou, vstinner
Date 2010-08-10.17:21:30
SpamBayes Score 2.24656e-11
Marked as misclassified No
Message-id <>
Lib/ 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:
Date User Action Args
2010-08-10 17:21:34vstinnersetrecipients: + vstinner, lemburg, pitrou
2010-08-10 17:21:34vstinnersetmessageid: <>
2010-08-10 17:21:31vstinnerlinkissue9560 messages
2010-08-10 17:21:30vstinnercreate