Make flags a set rather than a list

As this is essentially what it is, a set of values. This allows as
to do set arithmetics to see, e.g. the intersection of 2 flag sets
rather than clunkily having to do:

for flag in newflags:
  if flag not in oldflags:
    oldflags.append(flag)

Also some more code documenting.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth
2011-08-16 12:16:46 +02:00
committed by Nicolas Sebrecht
parent 373e7cdbc1
commit 466ded04d9
7 changed files with 89 additions and 64 deletions

View File

@ -23,6 +23,11 @@ try:
except:
pass #fail only if needed later on, not on import
try: # python 2.6 has set() built in
set
except NameError:
from sets import Set as set
class LocalStatusSQLiteFolder(LocalStatusFolder):
"""LocalStatus backend implemented with an SQLite database
@ -127,7 +132,6 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
for line in file.xreadlines():
uid, flags = line.strip().split(':')
uid = long(uid)
flags = list(flags)
flags = ''.join(sorted(flags))
data.append((uid,flags))
self.connection.executemany('INSERT INTO status (id,flags) VALUES (?,?)',
@ -167,7 +171,7 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
self.messagelist = {}
cursor = self.connection.execute('SELECT id,flags from status')
for row in cursor:
flags = [x for x in row[1]]
flags = set(row[1])
self.messagelist[row[0]] = {'uid': row[0], 'flags': flags}
def save(self):