[Python-bugs-list] [ python-Bugs-431597 ] Code being copied into shelve and UserDi
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 30 Aug 2001 14:15:36 -0700
Bugs item #431597, was opened at 2001-06-09 03:21
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=431597&group_id=5470
Category: Python Library
>Group: Not a Bug
>Status: Closed
Resolution: None
Priority: 5
Submitted By: Rick Jones (rjones33410)
Assigned to: Nobody/Anonymous (nobody)
Summary: Code being copied into shelve and UserDi
Initial Comment:
I've been writing a contacts program that uses a
UserDict as a direct interface to the record which is
then placed into a shelve. When I view the DB file
created by the shelve module I can see my code in the
Table.
This is a sample from the very start of the shelve
file, before the first record. This apears in the
begining like this no matter how many times I re-run
it with varying number of records.
•n}у Ў“Х}
€фЃt%vYачЃ€%v
CurKeys=db.keys()
Test=len(CurKeys)
Temp=1
NewList=[]
for list in CurKeys:
One=int(list)
NewList.append(One)
if Test in NewList:
Test=Test+1
Temp=Test
NextID='%s' % Temp
GetEntry=ThisEntry()
db[NextID]=GetEntry
print 'New Entry no.',NextID
db.close()
print 'Doneџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџ
џџџџџџџџџџџџџџџџџџџџџџ
This is the method that is actually being looped.
You'll note at the end the shelve is closed after each
record is added yet only a single copy of the code.
I'm baffled as to how this can be? Not to mention it
copied the entire document/module without regard to
scope.
I discovered this when I did a record loop test to
stuff 1000 records into the shelve. I opened the file
to see if there were any noticable problems since I
don't know what kind of density the shelve can handle
and saw my code in the table along with the record I
looped in.
Now I figured I had somehow made the module scope a
variable that was being looped in with the record so I
went through the entire 1000 record entries and my
code only apears once, although it is somewhat broken
up and much more binary looking than my record.
I'm sure you can understand how much of a problem this
can be in a comercial app.
----------------------------------------------------------------------
>Comment By: Jeremy Hylton (jhylton)
Date: 2001-08-30 14:15
Message:
Logged In: YES
user_id=31392
Okay. That's also what I expected, but wasn't sure if there
was some problem with database corruption. I'll close this
and let the user re-submit if he has a real problem.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-30 13:56
Message:
Logged In: YES
user_id=6380
I'm guessing that the shelf is using bsddb or gdbm.
These can leave some garbage in the file -- it is a binary
file
and you're not supposed to look at the DB file with a text
editor.
Due to reuse of I/O buffers, it's possible that the DB file
garbage
happens to be the contents of a file that was previously
read by
Python -- such as apparently the program source file.
The misunderstanding that the user expected the database
file
to be a text file, and opened it with a text editor.
This makes no sense.
----------------------------------------------------------------------
Comment By: Jeremy Hylton (jhylton)
Date: 2001-08-30 13:39
Message:
Logged In: YES
user_id=31392
What exactly is the bug that you are reporting? Was the
database created by shelve corrupted? Or were you just
surprised by the appeance of the bits in it? If there is
some functional problem, please provide a small reproducible
example.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=431597&group_id=5470