cs.app.pilfer.pilfer: Pilfer: new .session field with a PilferSession; open/close it in __enter_exit__
1 files changed, 10 insertions(+), 5 deletions(-)

M lib/python/cs/app/pilfer/pilfer.py
M lib/python/cs/app/pilfer/pilfer.py +10 -5
@@ 218,6 218,8 @@ class Pilfer(HasThreadState, HasFSPath, 
       )
   )
   content_cache: ContentCache = None
+  # a session for storing cookies etc
+  session: PilferSession = None
   # for optional extra things hung on the Pilfer object
   state: NS = field(default_factory=NS)
   _diversion_tasks: dict = field(default_factory=dict)

          
@@ 236,6 238,8 @@ class Pilfer(HasThreadState, HasFSPath, 
       self.content_cache = ContentCache(
           expanduser(self.rc_map[None]['cache'] or self.pathto('cache'))
       )
+    if self.session is None:
+      self.session = PilferSession(P=self, key='_')
     ##self._lock = Lock()
     self._lock = RLock()
 

          
@@ 247,11 251,12 @@ class Pilfer(HasThreadState, HasFSPath, 
   def __enter_exit__(self):
     ''' Run both the inherited context managers.
     '''
-    for _ in zip_longest(
-        MultiOpenMixin.__enter_exit__(self),
-        HasThreadState.__enter_exit__(self) if self.default else (),
-    ):
-      yield
+    with self.session:
+      for _ in zip_longest(
+          MultiOpenMixin.__enter_exit__(self),
+          HasThreadState.__enter_exit__(self) if self.default else (),
+      ):
+        yield
 
   @contextmanager
   def startup_shutdown(self):