[ python-Bugs-861340 ] UnboundLocalError in cgitb.py

SourceForge.net noreply at sourceforge.net
Thu Dec 18 12:31:22 EST 2003


Bugs item #861340, was opened at 2003-12-16 17:09
Message generated for change (Comment added) made by montanaro
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: Skip Montanaro (montanaro)
Date: 2003-12-18 11: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 10: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 09: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