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 4096and 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~
aad13658_last_name_for_state.idx
Description: Binary data
-- http://mail.python.org/mailman/listinfo/python-list
