Skip to content

Commit

Permalink
General clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcaricio committed Oct 14, 2016
1 parent 5892feb commit de93b7e
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ htmlcov/
.cache/
*.swp
.tox/
.idea/
15 changes: 0 additions & 15 deletions connexion/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion connexion/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions connexion/decorators/decorator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 0 additions & 13 deletions connexion/decorators/produces.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 0 additions & 13 deletions connexion/decorators/response.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 0 additions & 14 deletions connexion/decorators/security.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 18 additions & 23 deletions connexion/decorators/validation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
"""
Expand All @@ -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']
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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'):
Expand Down
14 changes: 0 additions & 14 deletions connexion/exceptions.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion connexion/handlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import logging

from .operation import Operation, SecureOperation
Expand Down
13 changes: 0 additions & 13 deletions connexion/operation.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 0 additions & 12 deletions connexion/problem.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 0 additions & 13 deletions connexion/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit de93b7e

Please sign in to comment.