[ python-Bugs-861340 ] UnboundLocalError in cgitb.py
SourceForge.net
noreply at sourceforge.net
Thu Dec 18 18:32:58 EST 2003
Bugs item #861340, was opened at 2003-12-16 18:09
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=861340&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Skip Montanaro (montanaro)
Summary: UnboundLocalError in cgitb.py
Initial Comment:
Here's the exception:
Exception
return cgitb.text((E, e, tb)).rstrip('\r\n')
File "/usr/lib/python2.3/cgitb.py", line 197, in text
vars = scanvars(reader, frame, locals)
File "/usr/lib/python2.3/cgitb.py", line 76, in scanvars
parent = value
UnboundLocalError: local variable 'value' referenced
before assignment
And here's the code:
if lasttoken == '.':
if parent is not __UNDEF__:
value = getattr(parent, token, __UNDEF__)
vars.append((prefix + token, prefix, value))
else:
where, value = lookup(token, frame, locals)
vars.append((token, where, value))
elif token == '.':
prefix += lasttoken + '.'
parent = value
If lasttoken is '.' and parent is __UNDEF__, value doesn't
get set. I'd offer a patch, but I really have no idea what this
code is doing and so don't know what to set value to.
----------------------------------------------------------------------
>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-12-18 18:32
Message:
Logged In: YES
user_id=33168
Jeremy, that's still not enough to reproduce the bug. What
exception was thrown by the code below and from where? What
were the values of bugs, searchstr, and keywords? What are
the definitions for utils.pluralize() and utils.commaAndify()?
----------------------------------------------------------------------
Comment By: Jeremy Fincher (jemfinch)
Date: 2003-12-18 18:02
Message:
Logged In: YES
user_id=99508
The code that caused the raised exception (which subsequently
triggered the exception in cgitb) was this:
outputstr = '%d %s match \'%s\' (%s):' % (len(bugs), \
utils.pluralize(len(bugs), 'bug'),
searchstr, utils.commaAndify(keywords, And='AND'))
That's actually from the diff where I changed it to be a bit more
idiomatic :) It wasn't my code, I promise!
----------------------------------------------------------------------
Comment By: Jeremy Fincher (jemfinch)
Date: 2003-12-18 17:56
Message:
Logged In: YES
user_id=99508
To be honest, it's just something I ran into in my own test suite
when my exception-handling logging code caught an exception I
didn't expect to get raised. Since I have no idea what the code in
cgitb that's raising the exception is actually doing, I really don't
know how to begin to try and narrow it down to a test case.
----------------------------------------------------------------------
Comment By: Skip Montanaro (montanaro)
Date: 2003-12-18 12:31
Message:
Logged In: YES
user_id=44345
I pulled scanvars() and lookup() out into a separate file and
instrumented things a little. From staring at the code I thought
that perhaps it didn't handle the case where the line starts with
a dot separating an object and its attribute. I can't provoke a
failure in that situation though. See attached lookup.py.
Jeremy, can you fiddle it to make it fail?
----------------------------------------------------------------------
Comment By: Skip Montanaro (montanaro)
Date: 2003-12-18 11:13
Message:
Logged In: YES
user_id=44345
Sorry, I have no idea what it does either. I'll look into it a bit,
but don't expect a miracle. :-(
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2003-12-18 10:02
Message:
Logged In: YES
user_id=33168
Jeremy, can you attach a complete test case?
Skip, I realize you didn't write the scanvars code (Ping
did), but you did add text. So maybe you have an idea.
>From a brief scan, it looks like if value is initialized to
None, the code might work.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=861340&group_id=5470
More information about the Python-bugs-list
mailing list