From c01438f77ef0c775e5dd3156bd63b37c53b02808 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 16 Aug 2021 13:48:22 +0100 Subject: [PATCH] companion: Move start_frontier_auth() above login() The former will be used by the latter, so this makes more sense when reading the code. In general I'm going to ensure there are two sections to this Session class: 1. Frontier Auth code. 2. CAPI query code. Yes, ideally I'd split it into two classes. But that kind of refactoring isn't for *this* branch. I just want things straight in my head for the "make CAPI queries run in a thread" changes. --- companion.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/companion.py b/companion.py index 8f0633c1..c96b84d4 100644 --- a/companion.py +++ b/companion.py @@ -476,6 +476,14 @@ class Session(object): self.auth: Optional[Auth] = None self.retrying = False # Avoid infinite loop when successful auth / unsuccessful query + def start_frontier_auth(self, access_token: str) -> None: + """Start an oAuth2 session.""" + logger.debug('Starting session') + self.session = requests.Session() + self.session.headers['Authorization'] = f'Bearer {access_token}' + self.session.headers['User-Agent'] = USER_AGENT + self.state = Session.STATE_OK + def login(self, cmdr: str = None, is_beta: Union[None, bool] = None) -> bool: """ Attempt oAuth2 login. @@ -545,14 +553,6 @@ class Session(object): self.auth = None raise # Bad thing happened - def start_frontier_auth(self, access_token: str) -> None: - """Start an oAuth2 session.""" - logger.debug('Starting session') - self.session = requests.Session() - self.session.headers['Authorization'] = f'Bearer {access_token}' - self.session.headers['User-Agent'] = USER_AGENT - self.state = Session.STATE_OK - def query(self, endpoint: str) -> CAPIData: # noqa: CCR001, C901 """Perform a query against the specified CAPI endpoint.""" logger.trace_if('capi.query', f'Performing query for endpoint "{endpoint}"')