Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#14 ip2cc: problem with Python 2.3

closed-wont-fix
PPA (5)
5
2004-01-27
2004-01-26
No

$ python ip2cc.py -update
Traceback (most recent call last):
File "ip2cc.py", line 434, in ?
db.fetch()
File "ip2cc.py", line 135, in fetch
self.add(first, last, parts[1].upper())
File "ip2cc.py", line 78, in add
db_first, record = self.__locate(last)
File "ip2cc.py", line 45, in __locate
assert first<=ip
AssertionError

Discussion

  • Logged In: YES
    user_id=63454

    It's a bug in bsddb module (SF bug #788421). Any ideas?
    Without proper set_location BTree databases are almost
    useless.

     
  • ys
    ys
    2004-01-27

    Logged In: YES
    user_id=961295

    An idea (I encounter the same problem): use db.cursor

    import bsddb
    import os

    os.chdir('/tmp')
    my_data = bsddb.btopen('testing', 'c')
    for i in range(10):
    if i == 5: pass
    else:
    my_data['%d'%i] = '%d'%(i*i)

    print my_data.keys()

    dbCursor = my_data.db.cursor()
    print dbCursor.get('5',None,bsddb._bsddb.DB_SET_RANGE)

    =>
    ['0', '1', '2', '3', '4', '6', '7', '8', '9']
    ('6', '36')

    YS.

     
  • Logged In: YES
    user_id=63454

    There is no cursor in Python 2.2, so I prefer switching to
    simple own database.

     
  • ys
    ys
    2004-01-27

    Logged In: YES
    user_id=961295

    Second Post: patch (not tested)

    $diff ip2cc.py ip2cc.py.ori

    3d2
    < import bsddb, sys
    33,53d31
    < def __locate(self, ip):
    < if sys.version[:3] < "2.3": return __locate(self,ip)
    < else: return __locate23(self,ip)
    <
    < def __locate23(self, ip):
    < '''Locate the last record for IP less or equal to ip.'''
    < db = self.__db
    < dbCursor = db.db.cursor()
    < try:
    < first, record =
    dbCursor.get(ip,None,bsddb._bsddb.DB_SET_RANGE)
    < except KeyError:
    < try:
    < first, record = db.last()
    < except KeyError:
    < raise KeyError(inet_ntoa(ip))
    < else:
    < if first!=ip:
    < first, record =
    dbCursor.get(bsddb._bsddb.DB_PREV)
    < assert first<=ip
    < return first, record
    <

    YS.

     
    • status: open --> closed-wont-fix
     
  • Logged In: YES
    user_id=63454

    Thank you for patch. But now I've rewritten ip2cc to use
    very simple own database with platform idependent format.
    Now it's easy to use database from any other language and
    I'm looking forward mod_ip2cc module for apache. If there is
    a reason to use old bsddb database, just drop me a note -
    I'll make 0.2.1 release with your patch applied.