Mercurial > hg > ltpdarepo
changeset 23:05ab4b93f132
Make load() method of the Database class into a static method.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Mon, 27 Jun 2011 16:15:57 +0200 |
parents | f27d3de11568 |
children | e02c16da590d |
files | src/ltpdarepo/database.py |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/database.py Mon Jun 27 15:52:18 2011 +0200 +++ b/src/ltpdarepo/database.py Mon Jun 27 16:15:57 2011 +0200 @@ -22,22 +22,25 @@ __slots__ = ('id', 'name', 'description') def __init__(self, id='', name='', description=''): - self.id = None - self.name = None - self.description = None + self.id = id + self.name = name + self.description = description - def load(self, id): + @staticmethod + def load(id): curs = g.db.cursor(DictCursor) curs.execute("""SELECT db_name AS id, name, description FROM available_dbs WHERE db_name=%s""", id) db = curs.fetchone() if db is None: return None - self.update(db) - return self + obj = Database() + obj.update(db) + return obj - def update(self, vals): - for key, value in vals.iteritems(): + def update(self, vals=None, **kwargs): + kwargs.update(vals or {}) + for key, value in kwargs.iteritems(): setattr(self, key, value) def create(self):