Permalink
Browse files

session state load/save

  • Loading branch information...
1 parent a7e6ebf commit 5cc8962bd8d73854b80389d89ed5fddc6216d4b9 @baverman committed Mar 24, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 swoop/session.py
View
20 swoop/session.py
@@ -88,3 +88,23 @@ def request(self, url, baseurl=None):
def clear(self):
self._pool.clear()
self.cookies.clear()
+
+ def get_state(self):
+ result = {}
+ for domain, cookies in self.cookies.iteritems():
+ for cookie in cookies.itervalues():
+ result.setdefault(domain, []).append(
+ cookie.output(None, '').lstrip())
+
+ return result
+
+ def set_state(self, state):
+ self.cookies.clear()
+
+ for domain, values in state.iteritems():
+ c = SimpleCookie()
+ for v in values:
+ c.load(v)
+
+ for cookie in c.itervalues():
+ self.cookies[domain][cookie.key] = cookie

0 comments on commit 5cc8962

Please sign in to comment.