Beispiel #1
0
 def setdefault(self, key, value=None):
     real_value = self.__get_helper(key)
     if real_value is None:
         self.__setitem__(key, value)
         return value
     else:
         return from_db(real_value[0])
Beispiel #2
0
 def __getitem__(self, index):
     if index < 0:
         sql = self.__get_element_from_back
     else:
         sql = self.__get_element_from_front
     cursor = self.conn.execute(sql, (index,))
     result = cursor.fetchone()
     if result is None:
         raise IndexError, index
     return from_db(result[0])
Beispiel #3
0
 def __getitem__(self, key):
     result = self.__get_helper(key)
     if result is None:
         raise KeyError(key)
     return from_db(result[0])
Beispiel #4
0
 def transform(self, result):
     return from_db(result[0])
Beispiel #5
0
 def get(self, key, defaultval=None):
     result = self.__get_helper(key)
     if result is None:
         return defaultval
     return from_db(result[0])
Beispiel #6
0
 def __get_helper(self, sql, *args):
     cursor = self.conn.execute(sql, args)
     result = cursor.fetchone()
     if result is None:
         raise IndexError, index
     return from_db(result[0])
Beispiel #7
0
 def next(self):
     result = self.cursor.fetchone()
     if result is None:
         raise StopIteration
     else:
         return from_db(result[0])