diff options
Diffstat (limited to 'opendc/util')
| -rw-r--r-- | opendc/util/exceptions.py | 23 | ||||
| -rw-r--r-- | opendc/util/parameter_checker.py | 22 | ||||
| -rw-r--r-- | opendc/util/rest.py | 20 |
3 files changed, 14 insertions, 51 deletions
diff --git a/opendc/util/exceptions.py b/opendc/util/exceptions.py index 8eea268a..caf6dd8e 100644 --- a/opendc/util/exceptions.py +++ b/opendc/util/exceptions.py @@ -27,11 +27,8 @@ class ForeignKeyError(Exception): class RowNotFoundError(Exception): """Raised when a database row is not found.""" - def __init__(self, table_name): - super(RowNotFoundError, self).__init__( - 'Row in `{}` table not found.'.format(table_name) - ) + super(RowNotFoundError, self).__init__('Row in `{}` table not found.'.format(table_name)) self.table_name = table_name @@ -42,14 +39,9 @@ class ParameterError(Exception): class IncorrectParameterError(ParameterError): """Raised when a parameter is of the wrong type.""" - def __init__(self, parameter_name, parameter_location): - super(IncorrectParameterError, self).__init__( - 'Incorrectly typed `{}` {} parameter.'.format( - parameter_name, - parameter_location - ) - ) + super(IncorrectParameterError, + self).__init__('Incorrectly typed `{}` {} parameter.'.format(parameter_name, parameter_location)) self.parameter_name = parameter_name self.parameter_location = parameter_location @@ -57,14 +49,9 @@ class IncorrectParameterError(ParameterError): class MissingParameterError(ParameterError): """Raised when a parameter is missing.""" - def __init__(self, parameter_name, parameter_location): - super(MissingParameterError, self).__init__( - 'Missing required `{}` {} parameter.'.format( - parameter_name, - parameter_location - ) - ) + super(MissingParameterError, + self).__init__('Missing required `{}` {} parameter.'.format(parameter_name, parameter_location)) self.parameter_name = parameter_name self.parameter_location = parameter_location diff --git a/opendc/util/parameter_checker.py b/opendc/util/parameter_checker.py index c60d26d3..561ed497 100644 --- a/opendc/util/parameter_checker.py +++ b/opendc/util/parameter_checker.py @@ -14,11 +14,7 @@ def _missing_parameter(params_required, params_actual, parent=''): if isinstance(param_required, dict): - param_missing = _missing_parameter( - param_required, - param_actual, - param_name - ) + param_missing = _missing_parameter(param_required, param_actual, param_name) if param_missing is not None: return '{}.{}'.format(parent, param_missing) @@ -36,11 +32,7 @@ def _incorrect_parameter(params_required, params_actual, parent=''): if isinstance(param_required, dict): - param_incorrect = _incorrect_parameter( - param_required, - param_actual, - param_name - ) + param_incorrect = _incorrect_parameter(param_required, param_actual, param_name) if param_incorrect is not None: return '{}.{}'.format(parent, param_incorrect) @@ -80,14 +72,8 @@ def check(request, **kwargs): missing_parameter = _missing_parameter(params_required, params_actual) if missing_parameter is not None: - raise exceptions.MissingParameterError( - _format_parameter(missing_parameter), - location - ) + raise exceptions.MissingParameterError(_format_parameter(missing_parameter), location) incorrect_parameter = _incorrect_parameter(params_required, params_actual) if incorrect_parameter is not None: - raise exceptions.IncorrectParameterError( - _format_parameter(incorrect_parameter), - location - ) + raise exceptions.IncorrectParameterError(_format_parameter(incorrect_parameter), location) diff --git a/opendc/util/rest.py b/opendc/util/rest.py index 85da4eaa..d5df5306 100644 --- a/opendc/util/rest.py +++ b/opendc/util/rest.py @@ -12,7 +12,6 @@ with open(sys.argv[1]) as f: class Request(object): """WebSocket message to REST request mapping.""" - def __init__(self, message=None): """"Initialize a Request from a socket message.""" @@ -52,9 +51,7 @@ class Request(object): raise exceptions.UnimplementedEndpointError('Non-ASCII path') except ImportError: - raise exceptions.UnimplementedEndpointError( - 'Unimplemented endpoint: {}.'.format(self.path) - ) + raise exceptions.UnimplementedEndpointError('Unimplemented endpoint: {}.'.format(self.path)) # Check the method @@ -62,8 +59,8 @@ 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 @@ -118,23 +115,16 @@ class Request(object): class Response(object): """Response to websocket mapping""" - def __init__(self, status_code, status_description, content=None): """Initialize a new Response.""" - self.status = { - 'code': status_code, - 'description': status_description - } + self.status = {'code': status_code, 'description': status_description} self.content = content def to_JSON(self): """"Return a JSON representation of this Response""" - data = { - 'id': self.id, - 'status': self.status - } + data = {'id': self.id, 'status': self.status} if self.content is not None: data['content'] = self.content |
