Move Client._do_refresh to State
This commit is contained in:
@@ -108,12 +108,6 @@ class Client(object):
|
||||
INTERNAL REQUEST METHODS
|
||||
"""
|
||||
|
||||
def _do_refresh(self):
|
||||
# TODO: Raise the error instead, and make the user do the refresh manually
|
||||
# It may be a bad idea to do this in an exception handler, if you have a better method, please suggest it!
|
||||
log.warning("Refreshing state and resending request")
|
||||
self._state = State.from_session(session=self._state._session)
|
||||
|
||||
def _get(self, url, params, error_retries=3):
|
||||
params.update(self._state.get_params())
|
||||
r = self._state._session.get(prefix_url(url), params=params)
|
||||
@@ -123,7 +117,7 @@ class Client(object):
|
||||
handle_payload_error(j)
|
||||
except FBchatPleaseRefresh:
|
||||
if error_retries > 0:
|
||||
self._do_refresh()
|
||||
self._state._do_refresh()
|
||||
return self._get(url, params, error_retries=error_retries - 1)
|
||||
raise
|
||||
return j
|
||||
@@ -143,7 +137,7 @@ class Client(object):
|
||||
return j
|
||||
except FBchatPleaseRefresh:
|
||||
if error_retries > 0:
|
||||
self._do_refresh()
|
||||
self._state._do_refresh()
|
||||
return self._post(
|
||||
url,
|
||||
data,
|
||||
|
@@ -191,3 +191,13 @@ class State(object):
|
||||
session = session_factory(user_agent=user_agent)
|
||||
session.cookies = requests.cookies.merge_cookies(session.cookies, cookies)
|
||||
return cls.from_session(session=session)
|
||||
|
||||
def _do_refresh(self):
|
||||
# TODO: Raise the error instead, and make the user do the refresh manually
|
||||
# It may be a bad idea to do this in an exception handler, if you have a better method, please suggest it!
|
||||
_util.log.warning("Refreshing state and resending request")
|
||||
new = State.from_session(session=self._session)
|
||||
self.fb_dtsg = new.fb_dtsg
|
||||
self._revision = new._revision
|
||||
self._counter = new._counter
|
||||
self._logout_h = new._logout_h or self._logout_h
|
||||
|
Reference in New Issue
Block a user