Move body of Client._get to State

This commit is contained in:
Mads Marquart
2019-07-25 20:33:20 +02:00
parent 513bc6eadf
commit 8d237ea4ef
2 changed files with 16 additions and 13 deletions

View File

@@ -108,19 +108,8 @@ class Client(object):
INTERNAL REQUEST METHODS
"""
def _get(self, url, params, error_retries=3):
params.update(self._state.get_params())
r = self._state._session.get(prefix_url(url), params=params)
content = check_request(r)
j = to_json(content)
try:
handle_payload_error(j)
except FBchatPleaseRefresh:
if error_retries > 0:
self._state._do_refresh()
return self._get(url, params, error_retries=error_retries - 1)
raise
return j
def _get(self, url, params):
return self._state._get(url, params)
def _post(self, url, data, files=None, as_graphql=False, error_retries=3):
data.update(self._state.get_params())

View File

@@ -201,3 +201,17 @@ class State(object):
self._revision = new._revision
self._counter = new._counter
self._logout_h = new._logout_h or self._logout_h
def _get(self, url, params, error_retries=3):
params.update(self.get_params())
r = self._session.get(_util.prefix_url(url), params=params)
content = _util.check_request(r)
j = _util.to_json(content)
try:
_util.handle_payload_error(j)
except _exception.FBchatPleaseRefresh:
if error_retries > 0:
self._do_refresh()
return self._get(url, params, error_retries=error_retries - 1)
raise
return j