Show More
@@ -53,6 +53,7 b' class SessionManager(LoggingConfigurable):' | |||||
53 | """Start a database connection""" |
|
53 | """Start a database connection""" | |
54 | if self._connection is None: |
|
54 | if self._connection is None: | |
55 | self._connection = sqlite3.connect(':memory:') |
|
55 | self._connection = sqlite3.connect(':memory:') | |
|
56 | self._connection.row_factory = sqlite3.Row | |||
56 | return self._connection |
|
57 | return self._connection | |
57 |
|
58 | |||
58 | def __del__(self): |
|
59 | def __del__(self): | |
@@ -141,18 +142,19 b' class SessionManager(LoggingConfigurable):' | |||||
141 |
|
142 | |||
142 | self.cursor.execute(query, list(kwargs.values())) |
|
143 | self.cursor.execute(query, list(kwargs.values())) | |
143 | try: |
|
144 | try: | |
144 |
|
|
145 | row = self.cursor.fetchone() | |
145 | except KeyError: |
|
146 | except KeyError: | |
146 | # The kernel is missing, so the session just got deleted. |
|
147 | # The kernel is missing, so the session just got deleted. | |
147 |
|
|
148 | row = None | |
148 |
|
149 | |||
149 |
if |
|
150 | if row is None: | |
150 | q = [] |
|
151 | q = [] | |
151 | for key, value in kwargs.items(): |
|
152 | for key, value in kwargs.items(): | |
152 | q.append("%s=%r" % (key, value)) |
|
153 | q.append("%s=%r" % (key, value)) | |
153 |
|
154 | |||
154 | raise web.HTTPError(404, u'Session not found: %s' % (', '.join(q))) |
|
155 | raise web.HTTPError(404, u'Session not found: %s' % (', '.join(q))) | |
155 | return model |
|
156 | ||
|
157 | return self.row_to_model(row) | |||
156 |
|
158 | |||
157 | def update_session(self, session_id, **kwargs): |
|
159 | def update_session(self, session_id, **kwargs): | |
158 | """Updates the values in the session database. |
|
160 | """Updates the values in the session database. | |
@@ -183,9 +185,8 b' class SessionManager(LoggingConfigurable):' | |||||
183 | query = "UPDATE session SET %s WHERE session_id=?" % (', '.join(sets)) |
|
185 | query = "UPDATE session SET %s WHERE session_id=?" % (', '.join(sets)) | |
184 | self.cursor.execute(query, list(kwargs.values()) + [session_id]) |
|
186 | self.cursor.execute(query, list(kwargs.values()) + [session_id]) | |
185 |
|
187 | |||
186 |
def row_to_model(self, |
|
188 | def row_to_model(self, row): | |
187 | """Takes sqlite database session row and turns it into a dictionary""" |
|
189 | """Takes sqlite database session row and turns it into a dictionary""" | |
188 | row = sqlite3.Row(cursor, row) |
|
|||
189 | if row['kernel_id'] not in self.kernel_manager: |
|
190 | if row['kernel_id'] not in self.kernel_manager: | |
190 | # The kernel was killed without deleting the session. Should never occur. |
|
191 | # The kernel was killed without deleting the session. Should never occur. | |
191 | self.delete_session(row['session_id']) |
|
192 | self.delete_session(row['session_id']) | |
@@ -208,7 +209,7 b' class SessionManager(LoggingConfigurable):' | |||||
208 | result = [] |
|
209 | result = [] | |
209 | for row in c: |
|
210 | for row in c: | |
210 | try: |
|
211 | try: | |
211 |
result.append(self.row_to_model( |
|
212 | result.append(self.row_to_model(row)) | |
212 | except KeyError: |
|
213 | except KeyError: | |
213 | pass |
|
214 | pass | |
214 | return result |
|
215 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now