From de93b7e37947c88cd960c4fadb7b51d16886b5e6 Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Fri, 14 Oct 2016 16:20:19 +0200 Subject: [PATCH] General clean up --- .gitignore | 1 + connexion/__init__.py | 15 ----------- connexion/app.py | 3 ++- connexion/decorators/decorator.py | 12 --------- connexion/decorators/produces.py | 13 ---------- connexion/decorators/response.py | 13 ---------- connexion/decorators/security.py | 14 ---------- connexion/decorators/validation.py | 41 +++++++++++++----------------- connexion/exceptions.py | 14 ---------- connexion/handlers.py | 1 - connexion/operation.py | 13 ---------- connexion/problem.py | 12 --------- connexion/utils.py | 13 ---------- 13 files changed, 21 insertions(+), 144 deletions(-) diff --git a/.gitignore b/.gitignore index d1c5e3dc4..48a3e5daa 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ htmlcov/ .cache/ *.swp .tox/ +.idea/ diff --git a/connexion/__init__.py b/connexion/__init__.py index f79821d84..f66f3635d 100755 --- a/connexion/__init__.py +++ b/connexion/__init__.py @@ -1,18 +1,3 @@ -#!/usr/bin/env python3 - -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - from flask import (abort, request, send_file, send_from_directory, # NOQA render_template, render_template_string, url_for) import werkzeug.exceptions as exceptions # NOQA diff --git a/connexion/app.py b/connexion/app.py index ed0117565..d83bd1c63 100644 --- a/connexion/app.py +++ b/connexion/app.py @@ -74,6 +74,7 @@ def __init__(self, import_name, port=None, specification_dir='', self.swagger_path = swagger_path self.swagger_url = swagger_url self.auth_all_paths = auth_all_paths + self.resolver_error = None @staticmethod def common_error_handler(exception): @@ -120,7 +121,7 @@ def add_api(self, swagger_file, base_path=None, arguments=None, auth_all_paths=N # Turn the resolver_error code into a handler object self.resolver_error = resolver_error resolver_error_handler = None - if resolver_error is not None: + if self.resolver_error is not None: resolver_error_handler = self._resolver_error_handler resolver = Resolver(resolver) if hasattr(resolver, '__call__') else resolver diff --git a/connexion/decorators/decorator.py b/connexion/decorators/decorator.py index bfb833ab3..3809ca9d1 100644 --- a/connexion/decorators/decorator.py +++ b/connexion/decorators/decorator.py @@ -1,15 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" import logging import flask diff --git a/connexion/decorators/produces.py b/connexion/decorators/produces.py index 420af56a1..06147f364 100644 --- a/connexion/decorators/produces.py +++ b/connexion/decorators/produces.py @@ -1,16 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - # Decorators to change the return type of endpoints import datetime import functools diff --git a/connexion/decorators/response.py b/connexion/decorators/response.py index 63e70a921..ef552c0b8 100644 --- a/connexion/decorators/response.py +++ b/connexion/decorators/response.py @@ -1,16 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - # Decorators to change the return type of endpoints import functools import logging diff --git a/connexion/decorators/security.py b/connexion/decorators/security.py index 44f86564f..59e0cd55c 100644 --- a/connexion/decorators/security.py +++ b/connexion/decorators/security.py @@ -1,18 +1,4 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - # Authentication and authorization related decorators - import functools import logging import os diff --git a/connexion/decorators/validation.py b/connexion/decorators/validation.py index 0006a0bee..a738b034d 100644 --- a/connexion/decorators/validation.py +++ b/connexion/decorators/validation.py @@ -1,16 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - import collections import copy import functools @@ -35,6 +22,11 @@ } +def make_type(value, type_literal): + type_func = TYPE_MAP.get(type_literal) + return type_func(value) + + class TypeValidationError(Exception): def __init__(self, schema_type, parameter_type, parameter_name): """ @@ -54,11 +46,6 @@ def __str__(self): return msg.format(**vars(self)) -def make_type(value, type): - type_func = TYPE_MAP.get(type) # convert value to right type - return type_func(value) - - def validate_type(param, value, parameter_type, parameter_name=None): param_type = param.get('type') parameter_name = parameter_name if parameter_name else param['name'] @@ -101,7 +88,7 @@ def __init__(self, schema, consumes, is_null_value_valid=False): """ :param schema: The schema of the request body :param consumes: The list of content types the operation consumes - :param is_nullable: Flag to indicate if null is accepted as valid value. + :param is_null_value_valid: Flag to indicate if null is accepted as valid value. """ self.schema = schema self.consumes = consumes @@ -131,7 +118,7 @@ def wrapper(*args, **kwargs): def validate_schema(self, data): """ - :type schema: dict + :type data: dict :rtype: flask.Response | None """ if self.is_null_value_valid and is_null(data): @@ -158,7 +145,7 @@ def __init__(self, schema, has_default=False): def validate_schema(self, data): """ - :type schema: dict + :type data: dict :rtype: flask.Response | None """ try: @@ -175,7 +162,7 @@ class ParameterValidator(object): def __init__(self, parameters, strict_validation=False): """ :param parameters: List of request parameter dictionaries - :param strict_validation: Flag indicating if parametrs not in spec are allowed + :param strict_validation: Flag indicating if parameters not in spec are allowed """ self.parameters = collections.defaultdict(list) for p in parameters: @@ -206,7 +193,15 @@ def validate_parameter(parameter_type, value, param): else: validate(converted_value, param, format_checker=draft4_format_checker) except ValidationError as exception: - print(converted_value, type(converted_value), param.get('type'), param, '<--------------------------') + debug_msg = 'Error while converting value {converted_value} from param ' \ + '{type_converted_value} of type real type {param_type} to the declared type {param}' + fmt_params = dict( + converted_value=str(converted_value), + type_converted_value=type(converted_value), + param_type=param.get('type'), + param=param + ) + logger.info(debug_msg.format_map(fmt_params)) return str(exception) elif param.get('required'): diff --git a/connexion/exceptions.py b/connexion/exceptions.py index 79c0edaa5..9cbc58c3d 100644 --- a/connexion/exceptions.py +++ b/connexion/exceptions.py @@ -1,17 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - - class ConnexionException(Exception): pass diff --git a/connexion/handlers.py b/connexion/handlers.py index e9931b54e..ac9e13564 100644 --- a/connexion/handlers.py +++ b/connexion/handlers.py @@ -1,4 +1,3 @@ - import logging from .operation import Operation, SecureOperation diff --git a/connexion/operation.py b/connexion/operation.py index 43d2f27a8..23d100eba 100644 --- a/connexion/operation.py +++ b/connexion/operation.py @@ -1,16 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - import functools import logging from copy import deepcopy diff --git a/connexion/problem.py b/connexion/problem.py index c7b3b574f..07f2d362a 100644 --- a/connexion/problem.py +++ b/connexion/problem.py @@ -1,15 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" import json import flask diff --git a/connexion/utils.py b/connexion/utils.py index e2b5d550e..da09a813b 100644 --- a/connexion/utils.py +++ b/connexion/utils.py @@ -1,16 +1,3 @@ -""" -Copyright 2015 Zalando SE - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the -License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. -""" - import functools import importlib import random