From a1589e75358558eada7ffc2efc7e3fa7160d233e Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Mon, 25 Sep 2017 13:50:49 +0200 Subject: Reformat codebase and fix spelling errors --- opendc/util/rest.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'opendc/util/rest.py') diff --git a/opendc/util/rest.py b/opendc/util/rest.py index ad53f084..7cf2d0b3 100644 --- a/opendc/util/rest.py +++ b/opendc/util/rest.py @@ -1,6 +1,5 @@ import importlib import json -import os import sys from oauth2client import client, crypt @@ -10,6 +9,7 @@ from opendc.util import exceptions, parameter_checker with open(sys.argv[1]) as file: KEYS = json.load(file) + class Request(object): """WebSocket message to REST request mapping.""" @@ -23,16 +23,16 @@ class Request(object): try: self.message = message - + self.id = message['id'] - + self.path = message['path'] self.method = message['method'] - + self.params_body = message['parameters']['body'] self.params_path = message['parameters']['path'] self.params_query = message['parameters']['query'] - + self.token = message['token'] except KeyError as exception: @@ -40,9 +40,9 @@ class Request(object): # Parse the path and import the appropriate module - try: + try: self.path = message['path'].encode('ascii', 'ignore').strip('/') - + module_base = 'opendc.api.{}.endpoint' module_path = self.path.translate(None, '{}').replace('/', '.') @@ -62,10 +62,11 @@ class Request(object): raise exceptions.UnsupportedMethodError('Non-rest method: {}'.format(self.method)) if not hasattr(self.module, self.method): - raise exceptions.UnsupportedMethodError('Unimplemented method at endpoint {}: {}'.format(self.path, self.method)) + raise exceptions.UnsupportedMethodError( + 'Unimplemented method at endpoint {}: {}'.format(self.path, self.method)) # Verify the user - + try: self.google_id = self._verify_token(self.token) @@ -87,7 +88,7 @@ class Request(object): raise crypt.AppIdentityError('Unrecognized client.') if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']: - raise crypt.AppIdentityError('Wrong issuer.') + raise crypt.AppIdentityError('Wrong issuer.') return idinfo['sub'] @@ -114,6 +115,7 @@ class Request(object): return json.dumps(self.message) + class Response(object): """Response to websocket mapping""" @@ -125,7 +127,7 @@ class Response(object): 'description': status_description } self.content = content - + def to_JSON(self): """"Return a JSON representation of this Response""" -- cgit v1.2.3