This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Log._log needs to be more forgiving...
Type: Stage:
Components: Distutils Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, skip.montanaro, splitscreen
Priority: normal Keywords:

Created on 2006-03-24 21:17 by skip.montanaro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg27872 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2006-03-24 21:17
The _log method of distutils' Log class executes

    print msg % args

where args might be an empty tuple (the methods that
call _log all
have varargs signatures).  If that's the case and msg
happens to
contain a % sign, it barfs.  It should be more
forgiving, for
instance:

    def _log(self, level, msg, args):
        if level >= self.threshold:
            try:
                print msg % args
            except TypeError:
                if not args:
                    print msg
                else:
                    raise
            sys.stdout.flush()

I just corrected this locally for our 2.3 and 2.4
installations.  The
above is a bit ugly, but it does allow the common case
(msg contains a
% but an empty args list) to pass while still catching
most programmer
errors.  Distutils is trying to log this message (wrapped):

  gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes
  -fPIC -I/opt/app/mysql-5.0.19/include
  -I/opt/app/mysql-5.0.19/include
-I/opt/lang/python/include/python2.3
  -c _mysql.c -o build/temp.solaris-2.8-i86pc-2.3/_mysql.o
  -I/opt/app/mysql-5.0.19/include -xO3 -mt -fsimple=1
-ftrap=%none
  -nofstore -xbuiltin=%all -xlibmil -xlibmopt
-xtarget=generic

I suppose it would be better if all the places in
distutils which log
compiler commands without extra args escaped their %
signs.  This
seems like an acceptable compromise though.

Skip
msg27873 - (view) Author: Matt Fleming (splitscreen) Date: 2006-03-27 21:27
Logged In: YES 
user_id=1126061

I can't reproduce on 2.4.2. Although maybe I misunderstood...

Are you saying that _log() barfs when you pass an empty tuple?

Passing an empty tuple to _log() works fine here..

I can understand it breaking when you pass some format
string to args and the msg contains an '%', that's the
developer's fault for not escaping the precentage sign.

Could you clarify? Or am I totally wrong?

Thanks
msg27874 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2006-03-28 03:58
Logged In: YES 
user_id=44345

It barfs if you pass an empty tuple and the msg argument contains a % escape.
For example, try:

    print "%s" % ()

In the particular case that tripped me up, it's trying to print a (bogus) gcc
command which contains % escapes while passing no args to map them.
msg27875 - (view) Author: Matt Fleming (splitscreen) Date: 2006-03-28 17:45
Logged In: YES 
user_id=1126061

Oh right, I understand now.

Yeah the fix seems fine to me.

Although, would it be more appropriate to check 

if not args:

is True?

So the _log() function would be something more like this:

def _log(self, level, msg, args):
    if level >= self.threshold:
        if not args:
            print msg
        else:
            print msg % args
         sys.stdout.flush()

Just thinking out-loud really.. not sure the check for the
raised exception is really necessary.

Thanks, Matt
msg27876 - (view) Author: Matt Fleming (splitscreen) Date: 2006-03-31 22:13
Logged In: YES 
user_id=1126061

This bug report should be closed. See patch #1462414
msg27877 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-04-01 07:47
Logged In: YES 
user_id=849994

Fixed in rev. 43529, 43530.
History
Date User Action Args
2022-04-11 14:56:16adminsetgithub: 43087
2006-03-24 21:17:23skip.montanarocreate