Fix custom cookie jar bugs
authorJakob <jakob@jcornell.net>
Sat, 30 Nov 2019 23:44:27 +0000 (17:44 -0600)
committerJakob <jakob@jcornell.net>
Sat, 30 Nov 2019 23:44:27 +0000 (17:44 -0600)
auth.py

diff --git a/auth.py b/auth.py
index c305e4356593ffbe64c98efb1b4033d6ded6d920..299dd70d8fbe87e5c54e2ecd9f1b41f05393d166 100644 (file)
--- a/auth.py
+++ b/auth.py
@@ -241,16 +241,22 @@ def get_access_token(storage_mgr, api_iface):
 
 
 class StorageMgrCookieJar(http.cookiejar.CookieJar):
-       def __init__(self, storage_mgr):
+       def __init__(self, storage_mgr, *args):
+               super().__init__(*args)
                self.storage_mgr = storage_mgr
 
        def load(self):
                if 'cookies' not in self.storage_mgr.keys():
-                       self.storage_mgr['cookies'] = {}
-               self._cookies = self.storage_mgr['cookies']
+                       self.storage_mgr['cookies'] = []
+               with self._cookies_lock:
+                       self._cookies = {}
+               for dict_ in self.storage_mgr['cookies']:
+                       self.set_cookie(http.cookiejar.Cookie(**dict_))
 
        def save(self):
-               self.storage_mgr['cookies'] = self._cookies
+               lambda fix_dict = lambda d: {k.strip('_'): v for (k, v) in d.items()}
+               dicts = [fix_dict(c.__dict__) for c in self]
+               self.storage_mgr['cookies'] = dicts
 
 
 class CookieAuthHandler(urllib.request.HTTPCookieProcessor):