@@ -82,6 +82,21 @@ async def wrapper(self, n=-1):
8282 return wrapper
8383
8484
85+ def ensure_session (func ):
86+ def wrapper (self , * args , ** kwargs ):
87+ if self ._session is not None and not self ._session .closed : #pylint: disable=protected-access
88+ return func (self , * args , ** kwargs )
89+ return None
90+ return wrapper
91+
92+
93+ def update_session (func ):
94+ def wrapper (self , * args , ** kwargs ):
95+ func (self , * args , ** kwargs )
96+ self .update_cookie_jar ()
97+ return wrapper
98+
99+
85100class CachedCookieJar :
86101
87102 def __init__ (self ):
@@ -91,25 +106,12 @@ def __init__(self):
91106 def register (self , session ):
92107 self ._session = session
93108
94- def ensure_session (func ):
95- def wrapper (self , * args , ** kwargs ):
96- if self ._session is not None and not self ._session .closed :
97- return func (self , * args , ** kwargs )
98- return None
99- return wrapper
100-
101109 @ensure_session
102110 def update_cookie_jar (self ):
103111 for response_url , cookies in self ._cache .items ():
104112 self ._session .cookie_jar .update_cookies (cookies , URL (response_url ))
105113 self ._cache .clear ()
106114
107- def update_session (func ):
108- def wrapper (self , * args , ** kwargs ):
109- func (self , * args , ** kwargs )
110- self .update_cookie_jar ()
111- return wrapper
112-
113115 @update_session
114116 def update_cookies (self , cookies , response_url = None ):
115117 logger .debug ('Cookie update. Scope: %s' , response_url )
0 commit comments