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
					Sebastian Spaeth
				
			
				
					committed by
					
						 Nicolas Sebrecht
						Nicolas Sebrecht
					
				
			
			
				
	
			
			
			 Nicolas Sebrecht
						Nicolas Sebrecht
					
				
			
						parent
						
							373e7cdbc1
						
					
				
				
					commit
					466ded04d9
				
			| @@ -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): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user