it doesn't work ;) [class recursive function]

E

Ethan Furman

I need some fresh eyes, or better brains, or both!

The expected debugging output is a list of names in alphabetical order
from each node (there are about 90 of them); what I am getting is this:

--> dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx')

starting next_item call for root
-----
<open file 'aad13658_last_name_for_state.idx', mode 'rb' at 0x013BD458>
512 30
-----
more nodes
CARNAHAN 1536
ENGLUND 1024
HOLSTEIN 2048
MATTHEWS 2560
ROSENFELD 3072
TERWILLIGER 3584
YAZZOLINO 4096

and then it stops. I should get about nine of these sections, and I'm
only getting one.

<code snippet>

class Index(object):
@classmethod
def from_file(cls, table, index_file):

def get_idx_records(data, length, howmany):
print "get_idx_records: keylen - %d; howmany - %d" %\
(length, howmany)
ptr = 0
current = 0
while current < howmany:
key = data[ptr:ptr+length].replace('\x00','')
rec = io.unpackLongInt(data[ptr+length:ptr+length+4],\
bigendian=True)
yield key, rec
ptr += length + 4
current += 1

def next_item(idx_file, node_loc, keylen):
print idx_file, node_loc, keylen, '\n','-----'
idx_file.seek(node_loc)
data_chunk = idx_file.read(512)
attributes = io.unpackShortInt(data_chunk[:2])
howmany = io.unpackShortInt(data_chunk[2:4])
if attributes in (2, 3):
print "actual records"
for key, rec in get_idx_records(data_chunk[12:512],\
keylen, howmany):
yield key, rec
else:
print "more nodes"
for ignore, next_node in \
get_idx_records(data_chunk[12:512],\
keylen, howmany):
print ignore, next_node
next_item(idx_file, next_node, keylen)


idx = object.__new__(cls)
#- idx.key = lambda rec: DoNotIndex
data = open(index_file, 'rb')
header = data.read(512)
rootnode = io.unpackLongInt(header[:4])
keylen = io.unpackShortInt(header[12:14])
idx.__doc__ = header[16:236].replace('\x00','')
for_expr = header[236:456].replace('\x00','')
if for_expr:
idx.__doc__ += ' for ' + for_expr.replace('=','==')
print "starting next_item call for root"
for rec in next_item(data, rootnode, keylen):
print rec

</code snippet>

Any ideas appreciated!

~Ethan~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top