Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1.     def get(self, *args, **kwargs):
  2.         action = self.application.params.get('action')
  3.         tokens_count = int(self.application.params.get('tokens_count')) \
  4.             if self.application.params.get('tokens_count') else 1
  5.         if action == 'get_token':
  6.             try:
  7.                 if tokens_count != 0:
  8.                     auth_response = self.parse_authentication_response()
  9.                     token_response = json.loads(self.make_token_request(auth_response).to_json())
  10.                     self.application.params['tokens_count'] = str(tokens_count - 1)
  11.                     if 'token_responses' in self.application.session:
  12.                         current_responses = json.loads(self.application.session['token_responses'])
  13.                         current_responses.append(token_response)
  14.                         self.application.session['token_responses'] = json.dumps(current_responses)
  15.                     else:
  16.                         token_responses = list()
  17.                         token_responses.append(token_response)
  18.                         self.application.session['token_responses'] = json.dumps(token_responses)
  19.                         str_params = urllib.parse.urlencode(self.application.params)
  20.  
  21.                         req = HTTPRequest(HOST+'/', 'POST', self.request.headers, body=str_params)
  22.                         resp = HTTPClient().fetch(req)
  23.                         return
  24.  
  25.                     # self.application.session['index_handler'].call_with_redirect(
  26.                     #     client=self.application.session['client'],
  27.                     #     params=self.application.params)
  28.                 else:
  29.                     self.set_header("Content-Type", "application/json")
  30.                     return self.write(self.application.session['token_responses'], indent=4, sort_keys=True)
  31.  
  32.             except Exception as e:
  33.                 return self.write(json.dumps(str(e)))
  34.  
  35.         return self.write('Test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement