Python dbm.gnu() Examples

The following are 1 code examples of dbm.gnu(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dbm , or try the search function .
Example #1
Source File: cmd_dumpdb.py    From doit with MIT License 6 votes vote down vote up
def dbm_iter(db):
    # try dictionary interface - ok in python2 and dumbdb
    try:
        return db.items()
    except: # pragma: no cover
        pass

    # try firstkey/nextkey - ok for py3 dbm.gnu
    try: # pragma: no cover
        db.firstkey
        def iter_gdbm(db):
            k = db.firstkey()
            while k != None:
                yield k, db[k]
                k = db.nextkey(k)
        return iter_gdbm(db)
    except: # pragma: no cover
        raise InvalidCommand("It seems your DB backend doesn't support "
                             "iterating through all elements")