'Helper function for restoring session data from HashDB'

def hashDBRetrieve(self, key, unserialize=False, db=False):

    key = ('%s%s%s' % ((self.url or ('%s%s' % (self.hostname, self.port))), key, self.HASHDB_MILESTONE_VALUE))
    retVal = ''
    hash_ = self.hashKey(key)
    if (not retVal):
        while True:
            try:
                for row in db.execute('SELECT    value    FROM    storage    WHERE    id=?', (hash_,)):
                    retVal = row[0]
            except sqlite3.OperationalError as ex:
                if (not ('locked' in ex.message)):
                    raise
            else:
                break
    return (retVal if (not unserialize) else self.base64unpickle(retVal))
