Browse Source

Resolve import conflicts

Bastien Sevajol 6 years ago
parent
commit
1b0a105459

+ 1 - 1
.travis.yml View File

@@ -6,7 +6,7 @@ python:
6 6
 
7 7
 install:
8 8
   - python setup.py develop
9
-  - pip install pytest pytest-cov python-coveralls
9
+  - pip install -e ."[test]"
10 10
 
11 11
 script: 
12 12
   - pytest --cov=hapic tests

+ 0 - 1
hapic/__init__.py View File

@@ -1,7 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from hapic.hapic import Hapic
3 3
 from hapic.data import HapicData
4
-from hapic import ext
5 4
 
6 5
 _hapic_default = Hapic()
7 6
 

+ 9 - 0
hapic/context.py View File

@@ -52,3 +52,12 @@ class ContextInterface(object):
52 52
         :return: OpenAPI path
53 53
         """
54 54
         raise NotImplementedError()
55
+
56
+    def by_pass_output_wrapping(self, response: typing.Any) -> bool:
57
+        """
58
+        Return True if the controller response is in final state: we do not
59
+        have to apply output wrapper on it.
60
+        :param response: the original response of controller
61
+        :return:
62
+        """
63
+        raise NotImplementedError()

+ 1 - 2
hapic/decorator.py View File

@@ -5,7 +5,6 @@ from http import HTTPStatus
5 5
 
6 6
 # TODO BS 20171010: bottle specific !  # see #5
7 7
 import marshmallow
8
-from bottle import HTTPResponse
9 8
 from multidict import MultiDict
10 9
 
11 10
 from hapic.data import HapicData
@@ -215,7 +214,7 @@ class OutputControllerWrapper(InputOutputControllerWrapper):
215 214
 
216 215
     def after_wrapped_function(self, response: typing.Any) -> typing.Any:
217 216
         try:
218
-            if isinstance(response, HTTPResponse):
217
+            if self.context.by_pass_output_wrapping(response):
219 218
                 return response
220 219
 
221 220
             processed_response = self.processor.process(response)

+ 0 - 3
hapic/ext/__init__.py View File

@@ -1,4 +1 @@
1 1
 # -*- coding: utf-8 -*-
2
-from hapic.ext import bottle
3
-from hapic.ext import pyramid
4
-from hapic.ext import flask

+ 5 - 0
hapic/ext/bottle/context.py View File

@@ -112,3 +112,8 @@ class BottleContext(ContextInterface):
112 112
 
113 113
     def get_swagger_path(self, contextualised_rule: str) -> str:
114 114
         return BOTTLE_RE_PATH_URL.sub(r'{\1}', contextualised_rule)
115
+
116
+    def by_pass_output_wrapping(self, response: typing.Any) -> bool:
117
+        if isinstance(response, bottle.HTTPResponse):
118
+            return True
119
+        return False

+ 3 - 0
hapic/ext/flask/context.py View File

@@ -101,3 +101,6 @@ class FlaskContext(ContextInterface):
101 101
     def get_swagger_path(self, contextualised_rule: str) -> str:
102 102
         # TODO - G.M - 2017-12-05 Check if all route path are handled correctly
103 103
         return FLASK_RE_PATH_URL.sub(r'{\1}', contextualised_rule)
104
+
105
+    def by_pass_output_wrapping(self, response: typing.Any) -> bool:
106
+        return False

+ 3 - 0
hapic/ext/pyramid/context.py View File

@@ -120,3 +120,6 @@ class PyramidContext(ContextInterface):
120 120
         # TODO BS 20171110: Pyramid allow route like '/{foo:\d+}', so adapt
121 121
         # and USE regular expression (see https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/urldispatch.html#custom-route-predicates)  # nopep8
122 122
         return contextualised_rule
123
+
124
+    def by_pass_output_wrapping(self, response: typing.Any) -> bool:
125
+        return False

+ 1 - 5
setup.py View File

@@ -7,9 +7,6 @@ from os import path
7 7
 here = path.abspath(path.dirname(__file__))
8 8
 
9 9
 install_requires = [
10
-    # TODO: Bottle will be an extension in future, see #1
11
-    # TODO: marshmallow an extension too ? see #2
12
-    'bottle',
13 10
     'marshmallow',
14 11
     'apispec==0.27.1-algoo',
15 12
     'multidict'
@@ -25,8 +22,7 @@ tests_require = [
25 22
     'webtest',
26 23
 ]
27 24
 dev_require = [
28
-    'requests',
29
-]
25
+] + tests_require
30 26
 
31 27
 setup(
32 28
     name='hapic',