Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get(self, *args, **kwargs):
- action = self.application.params.get('action')
- tokens_count = int(self.application.params.get('tokens_count')) \
- if self.application.params.get('tokens_count') else 1
- if action == 'get_token':
- try:
- if tokens_count != 0:
- auth_response = self.parse_authentication_response()
- token_response = json.loads(self.make_token_request(auth_response).to_json())
- self.application.params['tokens_count'] = str(tokens_count - 1)
- if 'token_responses' in self.application.session:
- current_responses = json.loads(self.application.session['token_responses'])
- current_responses.append(token_response)
- self.application.session['token_responses'] = json.dumps(current_responses)
- else:
- token_responses = list()
- token_responses.append(token_response)
- self.application.session['token_responses'] = json.dumps(token_responses)
- str_params = urllib.parse.urlencode(self.application.params)
- req = HTTPRequest(HOST+'/', 'POST', self.request.headers, body=str_params)
- resp = HTTPClient().fetch(req)
- return
- # self.application.session['index_handler'].call_with_redirect(
- # client=self.application.session['client'],
- # params=self.application.params)
- else:
- self.set_header("Content-Type", "application/json")
- return self.write(self.application.session['token_responses'], indent=4, sort_keys=True)
- except Exception as e:
- return self.write(json.dumps(str(e)))
- return self.write('Test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement