Skip to content

Commit

Permalink
did changes requested by isort and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
dutradda committed Apr 4, 2017
1 parent 96ba88a commit 3952ea2
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 73 deletions.
9 changes: 2 additions & 7 deletions connexion/apis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

def canonical_base_url(base_path):
"""
Make given "basePath" a canonical base URL which can be prepended to paths starting with "/".
"""
return base_path.rstrip('/')

from .abstract import AbstractAPI
from .flask_api import FlaskApi

__all__ = ['AbstractAPI', 'FlaskApi']
11 changes: 8 additions & 3 deletions connexion/apis/abstract.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import abc
import copy
import logging
import pathlib
import sys

import jinja2
import six
import abc

import yaml
from swagger_spec_validator.validator20 import validate_spec

from . import canonical_base_url
from .. import utils
from ..exceptions import ResolverError
from ..operation import Operation
from ..resolver import Resolver
Expand All @@ -25,6 +23,13 @@
logger = logging.getLogger('connexion.apis')


def canonical_base_url(base_path):
"""
Make given "basePath" a canonical base URL which can be prepended to paths starting with "/".
"""
return base_path.rstrip('/')


def compatibility_layer(spec):
"""Make specs compatible with older versions of Connexion."""
if not isinstance(spec, dict):
Expand Down
13 changes: 6 additions & 7 deletions connexion/apis/flask_api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import logging
import functools

import flask
import werkzeug.exceptions
import six
from connexion.handlers import AuthErrorHandler
import werkzeug.exceptions
from connexion import flask_utils
from connexion.apis.abstract import AbstractAPI
from connexion.response import ConnexionResponse
from connexion.request import ConnexionRequest
from connexion.decorators.produces import BaseSerializer, NoContent
from connexion.handlers import AuthErrorHandler
from connexion.request import ConnexionRequest
from connexion.response import ConnexionResponse
from connexion.utils import is_json_mimetype
from connexion import flask_utils

logger = logging.getLogger('connexion.apis.flask_api')

Expand Down Expand Up @@ -178,7 +177,7 @@ def _build_flask_response(cls, mimetype=None, content_type=None,
'content_type': content_type,
'headers': headers
}
kwargs = {k:v for k, v in six.iteritems(kwargs) if v is not None}
kwargs = {k: v for k, v in six.iteritems(kwargs) if v is not None}
flask_response = flask.current_app.response_class(**kwargs) # type: flask.Response

if status_code is not None:
Expand Down
2 changes: 2 additions & 0 deletions connexion/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .abstract import AbstractApp
from .flask_app import FlaskApp

__all__ = ['AbstractApp', 'FlaskApp']
28 changes: 14 additions & 14 deletions connexion/apps/abstract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import logging
import pathlib
import six
import abc

from ..resolver import Resolver

Expand Down Expand Up @@ -152,19 +152,19 @@ def add_api(self, specification, base_path=None, arguments=None,
specification = self.specification_dir / specification

api = self.api_cls(specification=specification,
base_url=base_path, arguments=arguments,
swagger_json=swagger_json,
swagger_ui=swagger_ui,
swagger_path=swagger_path,
swagger_url=swagger_url,
resolver=resolver,
resolver_error_handler=resolver_error_handler,
validate_responses=validate_responses,
strict_validation=strict_validation,
auth_all_paths=auth_all_paths,
debug=self.debug,
validator_map=self.validator_map,
pythonic_params=pythonic_params)
base_url=base_path, arguments=arguments,
swagger_json=swagger_json,
swagger_ui=swagger_ui,
swagger_path=swagger_path,
swagger_url=swagger_url,
resolver=resolver,
resolver_error_handler=resolver_error_handler,
validate_responses=validate_responses,
strict_validation=strict_validation,
auth_all_paths=auth_all_paths,
debug=self.debug,
validator_map=self.validator_map,
pythonic_params=pythonic_params)
return api

def _resolver_error_handler(self, *args, **kwargs):
Expand Down
34 changes: 19 additions & 15 deletions connexion/apps/flask_app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import datetime
import logging
import pathlib
import datetime
from decimal import Decimal

import flask
import werkzeug.exceptions
import six
from flask import json

from ..apis.flask_api import FlaskApi
from ..exceptions import ProblemException
from ..problem import problem
from ..resolver import Resolver
from ..apis.flask_api import FlaskApi
from .abstract import AbstractApp
from flask import json
from decimal import Decimal


logger = logging.getLogger('connexion.app')

Expand All @@ -23,11 +23,13 @@ def __init__(self, import_name, port=None, specification_dir='',
debug=False, swagger_json=True, swagger_ui=True, swagger_path=None,
swagger_url=None, host=None, validator_map=None):
server = server or 'flask'
super(FlaskApp, self).__init__(import_name, port=port, specification_dir=specification_dir,
server=server, arguments=arguments, auth_all_paths=auth_all_paths,
debug=debug, swagger_json=swagger_json, swagger_ui=swagger_ui,
swagger_path=swagger_path, swagger_url=swagger_url,
host=host, validator_map=validator_map, api_cls=FlaskApi)
super(FlaskApp, self).__init__(
import_name, port=port, specification_dir=specification_dir,
server=server, arguments=arguments, auth_all_paths=auth_all_paths,
debug=debug, swagger_json=swagger_json, swagger_ui=swagger_ui,
swagger_path=swagger_path, swagger_url=swagger_url,
host=host, validator_map=validator_map, api_cls=FlaskApi
)

def create_app(self):
app = flask.Flask(self.import_name)
Expand Down Expand Up @@ -66,11 +68,13 @@ def add_api(self, specification, base_path=None, arguments=None,
auth_all_paths=None, swagger_json=None, swagger_ui=None,
swagger_path=None, swagger_url=None, validate_responses=False,
strict_validation=False, resolver=Resolver(), resolver_error=None):
api = super(FlaskApp, self).add_api(specification, base_path=base_path,
arguments=arguments, auth_all_paths=auth_all_paths, swagger_json=swagger_json,
swagger_ui=swagger_ui, swagger_path=swagger_path, swagger_url=swagger_url,
validate_responses=validate_responses, strict_validation=strict_validation,
resolver=resolver, resolver_error=resolver_error)
api = super(FlaskApp, self).add_api(
specification, base_path=base_path,
arguments=arguments, auth_all_paths=auth_all_paths, swagger_json=swagger_json,
swagger_ui=swagger_ui, swagger_path=swagger_path, swagger_url=swagger_url,
validate_responses=validate_responses, strict_validation=strict_validation,
resolver=resolver, resolver_error=resolver_error
)
self.app.register_blueprint(api.blueprint)
return api

Expand Down
12 changes: 6 additions & 6 deletions connexion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ def run(spec_file,
api_extra_args['resolver'] = resolver

app = connexion.FlaskApp(__name__,
swagger_json=not hide_spec,
swagger_ui=not hide_console_ui,
swagger_path=console_ui_from or None,
swagger_url=console_ui_url or None,
auth_all_paths=auth_all_paths,
debug=debug)
swagger_json=not hide_spec,
swagger_ui=not hide_console_ui,
swagger_path=console_ui_from or None,
swagger_url=console_ui_url or None,
auth_all_paths=auth_all_paths,
debug=debug)

app.add_api(spec_file_full_path,
base_path=base_path,
Expand Down
1 change: 0 additions & 1 deletion connexion/decorators/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import re
import six
import werkzeug.exceptions as exceptions

from ..utils import all_json, boolean, is_null, is_nullable

Expand Down
1 change: 0 additions & 1 deletion connexion/decorators/produces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Decorators to change the return type of endpoints
import datetime
import functools
import logging

Expand Down
2 changes: 0 additions & 2 deletions connexion/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def handle(self, *args, **kwargs):
"""
Actual handler for the execution after authentication.
"""
request = self.api.get_request(**kwargs)
response = problem(
title=self.exception.name,
detail=self.exception.description,
Expand All @@ -68,7 +67,6 @@ def function(self):
return self.handle

def handle(self, *args, **kwargs):
request = self.api.get_request(**kwargs)
response = problem(
title='Not Implemented',
detail=self.exception.reason,
Expand Down
3 changes: 2 additions & 1 deletion connexion/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from jsonschema import ValidationError

from .decorators import validation
from .decorators.decorator import BeginOfRequestLifecycleDecorator, EndOfRequestLifecycleDecorator
from .decorators.decorator import (BeginOfRequestLifecycleDecorator,
EndOfRequestLifecycleDecorator)
from .decorators.metrics import UWSGIMetricsCollector
from .decorators.parameter import parameter_to_arg
from .decorators.produces import BaseSerializer, Produces
Expand Down
4 changes: 2 additions & 2 deletions connexion/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ def problem(status, title, detail, type=None, instance=None, headers=None, ext=N
# return a problem payload in JSON format.
mimetype = content_type = 'application/problem+json'
return ConnexionResponse(status, mimetype, content_type,
body=problem_response,
headers=headers)
body=problem_response,
headers=headers)
2 changes: 1 addition & 1 deletion connexion/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

_ConnexionRequest = namedtuple('SwaggerRequest', [
'url', 'method', 'path_params', 'query', 'headers',
'form', 'body', 'json', 'files', 'context'
'form', 'body', 'json', 'files', 'context'
])


Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pytest
from conftest import TEST_FOLDER, build_app_from_fixture
from connexion.apps import FlaskApp
from connexion.apis import FlaskApi
from connexion.apps import FlaskApp
from connexion.exceptions import InvalidSpecification


Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_secure_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from connexion.apps import FlaskApp
from connexion.apis import FlaskApi
from connexion.apps import FlaskApp


def test_security_over_inexistent_endpoints(oauth_requests, secure_api_spec_dir):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pathlib

import pytest
from connexion.apps import FlaskApp
from connexion.apis import FlaskApi
from connexion.apps import FlaskApp

logging.basicConfig(level=logging.DEBUG)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from yaml import YAMLError

import pytest
from connexion.apis import FlaskApi, canonical_base_url
from connexion.apis import FlaskApi
from connexion.apis.abstract import canonical_base_url
from connexion.apis.flask_api import FlaskApi
from connexion.exceptions import InvalidSpecification, ResolverError

Expand Down
2 changes: 1 addition & 1 deletion tests/test_flask_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import math

import connexion.apps
import connexion.utils as utils
import connexion.flask_utils as flask_utils
import connexion.utils as utils
import pytest
from mock import MagicMock

Expand Down
8 changes: 5 additions & 3 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json

import flask

import connexion
from connexion.decorators.metrics import UWSGIMetricsCollector
from connexion.apis import FlaskApi
from connexion.decorators.metrics import UWSGIMetricsCollector
from mock import MagicMock
import json
import flask


def test_timer(monkeypatch):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

import mock
import pytest
from connexion.decorators.security import security_passthrough, verify_oauth

from connexion.apis.flask_api import Jsonifier
from connexion.decorators.security import security_passthrough, verify_oauth
from connexion.exceptions import InvalidSpecification
from connexion.operation import Operation
from connexion.resolver import Resolver
Expand Down
3 changes: 2 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import math

import connexion.apps
import connexion.utils as utils
import connexion.flask_utils as flask_utils
import connexion.utils as utils
import pytest

from mock import MagicMock


Expand Down
4 changes: 2 additions & 2 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import flask

from connexion.decorators.validation import ParameterValidator
from connexion.apis.flask_api import FlaskApi
from connexion.decorators.validation import ParameterValidator
# we are using "mock" module here for Py 2.7 support
from mock import MagicMock

import flask


def test_parameter_validator(monkeypatch):
Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pathlib

import pytest
from connexion.apps import FlaskApp
from connexion.apis import FlaskApi
from connexion.apps import FlaskApp

logging.basicConfig(level=logging.DEBUG)

Expand Down

0 comments on commit 3952ea2

Please sign in to comment.