Marc-Andre Lemburg <m...@egenix.com> added the comment:

STINNER Victor wrote:
> 
> New submission from STINNER Victor <victor.stin...@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.

The patch looks good. Just one nit: could you please indent the doc-string
to match the original indentation ?

BTW: I had a look in my archive for platform.py, but couldn't find
where the symlink logic was changed to use Python's APIs instead.

> --
> 
> 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:
> http://mail.python.org/pipermail/python-checkins/2010-April/092092.html

The main reason why this doesn't work on trunk is that platform.py is
supposed to work for many different Python versions, since it's
original use case was to provide platform information to build systems
targeting multiple Python versions.

On Python3, the same is true, but only for the 3.x versions.

----------
title: platform.py: use -b option for file command in _syscmd_file() -> 
platform.py: use -b option for file command in  _syscmd_file()

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9560>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to