我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用db.DB。
def __init__(self, dbenv=None): self.db = db.DB(dbenv) self._closed = True if HIGHEST_PROTOCOL: self.protocol = HIGHEST_PROTOCOL else: self.protocol = 1
def __getattr__(self, name): """Many methods we can just pass through to the DB object. (See below) """ return getattr(self.db, name) #----------------------------------- # Dictionary access methods
def __iter__(self) : # XXX: Load all keys in memory :-( for k in self.db.keys() : yield k # Do this when "DB" support iteration # Or is it enough to pass thru "getattr"? # # def __iter__(self) : # return self.db.__iter__()
def __init__(self, dbenv, *args, **kwargs): # give it the proper DBEnv C object that its expecting self._cobj = db.DB(*((dbenv._cobj,) + args), **kwargs) # TODO are there other dict methods that need to be overridden?
def run(*args, **kw): db = DB(name=config.DB_NAME, user=config.DB_USER) db.execute("""SELECT * from actor""")
def __init__(self, connection): threading.Thread.__init__(self) self.connection = connection # establish a database connection self.db = DB()
def __init__(self): self.events = [] self.year = 1 self.month = 1 self.day = 1 self.hour = 0 self.minute = 0 self.parent = Tk() self.parent.title('Year: 0') self.parent.geometry("{}x{}+0+0".format(utility.DISPLAY_WIDTH, utility.DISPLAY_HEIGHT)) self.parent.config(background='white') self.after_id = 0 self.advance_num = 0 self.ids = {} self.battles = [] self.battle_history = [] self.treaties = [] self.cells = [] self.nations = [] self.religions = [] self.is_continuous = False self.run_until_battle = False self.advancing = False self.graphical_battles = True self.fast_battles = False self.clear_gen_log() self.world_name = '' self.db = None # The DB connection. Will be created after setup so we can give it a real name. self.setup()
def setup(self): self.create_gui() # Clear out the event log with open('event_log.txt', 'w') as f: f.write('') size = utility.S_WIDTH // utility.CELL_SIZE data = noise.generate_noise(size, 'Generating terrain: ') print('') cells_x = utility.S_WIDTH // utility.CELL_SIZE cells_y = utility.S_HEIGHT // utility.CELL_SIZE for x in xrange(cells_x): self.cells.append([]) for y in xrange(cells_y): utility.show_bar(x * cells_y + y, cells_x * cells_y, message='Generating world: ', number_limit=True) self.cells[-1].append(terrain.Cell(self, '', x, y, data[x][y], random.random()**6, 0, None)) print('') self.weather = terrain.Weather(self.cells, self) self.weather.run(10) for x, row in enumerate(self.cells): for y, cell in enumerate(row): cell.terrain.setup() cell.reset_color() print('') self.nations = [] self.religions = [] self.old_nations = {} for new_nation in xrange(self.nation_count): self.add_nation(Nation(self)) # Initially create one new religion for every nation for i in xrange(self.nation_count): new_religion = Religion(self.nations[i].language, self.nations[i].language.make_name_word()) new_religion.adherents[self.nations[i].cities[0].name] = self.nations[i].cities[0].population self.religions.append(new_religion) # Choose a random nation to generate our world's name with lang = random.choice(self.nations).language self.world_name = lang.translateTo('world') self.db = db.DB(self.world_name) self.db.setup() events.main = self