Browse Source

python 3.4 campat

Bastien Sevajol 3 years ago
parent
commit
19a0d968c7

+ 1 - 1
.gitignore View File

@@ -2,7 +2,7 @@
2 2
 *.pyc
3 3
 __pycache__
4 4
 *~
5
-/venv
5
+/venv*
6 6
 .cache
7 7
 *.egg-info
8 8
 .coverage

+ 1 - 0
.travis.yml View File

@@ -1,6 +1,7 @@
1 1
 sudo: false
2 2
 language: python
3 3
 python:
4
+  - "3.4"
4 5
   - "3.5"
5 6
   - "3.6"
6 7
 

+ 4 - 1
example/example_a_bottle.py View File

@@ -1,6 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import json
3
-from http import HTTPStatus
3
+try:  # Python 3.5+
4
+    from http import HTTPStatus
5
+except ImportError:
6
+    from http import client as HTTPStatus
4 7
 
5 8
 import bottle
6 9
 import time

+ 4 - 1
example/example_a_flask.py View File

@@ -1,6 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import json
3
-from http import HTTPStatus
3
+try:  # Python 3.5+
4
+    from http import HTTPStatus
5
+except ImportError:
6
+    from http import client as HTTPStatus
4 7
 
5 8
 from flask import Flask
6 9
 import hapic

+ 4 - 1
example/example_a_pyramid.py View File

@@ -1,6 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import json
3
-from http import HTTPStatus
3
+try:  # Python 3.5+
4
+    from http import HTTPStatus
5
+except ImportError:
6
+    from http import client as HTTPStatus
4 7
 
5 8
 from pyramid.config import Configurator
6 9
 from wsgiref.simple_server import make_server

+ 0 - 1
example/fake_api/bottle_api.py View File

@@ -1,6 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import json
3
-from http import HTTPStatus
4 3
 
5 4
 import bottle
6 5
 import time

+ 0 - 1
example/fake_api/flask_api.py View File

@@ -1,6 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import json
3
-from http import HTTPStatus
4 3
 
5 4
 import flask
6 5
 import time

+ 0 - 2
example/fake_api/pyramid_api.py View File

@@ -1,7 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import json
3
-from http import HTTPStatus
4
-from pyramid.response import Response
5 3
 from pyramid.config import Configurator
6 4
 from wsgiref.simple_server import make_server
7 5
 import time

+ 4 - 1
example/usermanagement/serve_bottle.py View File

@@ -2,7 +2,10 @@
2 2
 
3 3
 import bottle
4 4
 from datetime import datetime
5
-from http import HTTPStatus
5
+try:  # Python 3.5+
6
+    from http import HTTPStatus
7
+except ImportError:
8
+    from http import client as HTTPStatus
6 9
 import json
7 10
 import time
8 11
 

+ 4 - 1
example/usermanagement/serve_flask.py View File

@@ -1,7 +1,10 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3 3
 from datetime import datetime
4
-from http import HTTPStatus
4
+try:  # Python 3.5+
5
+    from http import HTTPStatus
6
+except ImportError:
7
+    from http import client as HTTPStatus
5 8
 import json
6 9
 import flask
7 10
 import time

+ 4 - 1
example/usermanagement/serve_pyramid.py View File

@@ -1,7 +1,10 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3 3
 from datetime import datetime
4
-from http import HTTPStatus
4
+try:  # Python 3.5+
5
+    from http import HTTPStatus
6
+except ImportError:
7
+    from http import client as HTTPStatus
5 8
 import json
6 9
 from pyramid.config import Configurator
7 10
 import time

+ 4 - 1
hapic/context.py View File

@@ -1,6 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import typing
3
-from http import HTTPStatus
3
+try:  # Python 3.5+
4
+    from http import HTTPStatus
5
+except ImportError:
6
+    from http import client as HTTPStatus
4 7
 
5 8
 from hapic.processor import RequestParameters
6 9
 from hapic.processor import ProcessValidationError

+ 4 - 1
hapic/decorator.py View File

@@ -1,7 +1,10 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import functools
3 3
 import typing
4
-from http import HTTPStatus
4
+try:  # Python 3.5+
5
+    from http import HTTPStatus
6
+except ImportError:
7
+    from http import client as HTTPStatus
5 8
 
6 9
 # TODO BS 20171010: bottle specific !  # see #5
7 10
 import marshmallow

+ 3 - 3
hapic/doc.py View File

@@ -33,7 +33,7 @@ def bottle_generate_operations(
33 33
         schema_class = type(description.output_body.wrapper.processor.schema)
34 34
         method_operations.setdefault('responses', {})\
35 35
             [int(description.output_body.wrapper.default_http_code)] = {
36
-                'description': str(description.output_body.wrapper.default_http_code),  # nopep8
36
+                'description': int(description.output_body.wrapper.default_http_code),  # nopep8
37 37
                 'schema': {
38 38
                     '$ref': '#/definitions/{}'.format(schema_class.__name__)
39 39
                 }
@@ -45,7 +45,7 @@ def bottle_generate_operations(
45 45
         )
46 46
         method_operations.setdefault('responses', {})\
47 47
             [int(description.output_file.wrapper.default_http_code)] = {
48
-            'description': str(description.output_file.wrapper.default_http_code),  # nopep8
48
+            'description': int(description.output_file.wrapper.default_http_code),  # nopep8
49 49
         }
50 50
 
51 51
     if description.errors:
@@ -53,7 +53,7 @@ def bottle_generate_operations(
53 53
             schema_class = type(error.wrapper.schema)
54 54
             method_operations.setdefault('responses', {})\
55 55
                 [int(error.wrapper.http_code)] = {
56
-                    'description': str(error.wrapper.http_code),
56
+                    'description': int(error.wrapper.http_code),
57 57
                     'schema': {
58 58
                         '$ref': '#/definitions/{}'.format(schema_class.__name__)  # nopep8
59 59
                     }

+ 4 - 1
hapic/ext/bottle/context.py View File

@@ -2,7 +2,10 @@
2 2
 import json
3 3
 import re
4 4
 import typing
5
-from http import HTTPStatus
5
+try:  # Python 3.5+
6
+    from http import HTTPStatus
7
+except ImportError:
8
+    from http import client as HTTPStatus
6 9
 
7 10
 import bottle
8 11
 from multidict import MultiDict

+ 4 - 1
hapic/ext/flask/context.py View File

@@ -2,7 +2,10 @@
2 2
 import json
3 3
 import re
4 4
 import typing
5
-from http import HTTPStatus
5
+try:  # Python 3.5+
6
+    from http import HTTPStatus
7
+except ImportError:
8
+    from http import client as HTTPStatus
6 9
 
7 10
 from hapic.context import ContextInterface
8 11
 from hapic.context import RouteRepresentation

+ 4 - 1
hapic/ext/pyramid/context.py View File

@@ -2,7 +2,10 @@
2 2
 import json
3 3
 import re
4 4
 import typing
5
-from http import HTTPStatus
5
+try:  # Python 3.5+
6
+    from http import HTTPStatus
7
+except ImportError:
8
+    from http import client as HTTPStatus
6 9
 
7 10
 from hapic.context import ContextInterface
8 11
 from hapic.context import RouteRepresentation

+ 5 - 1
hapic/hapic.py View File

@@ -1,7 +1,11 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import typing
3 3
 import uuid
4
-from http import HTTPStatus
4
+try:  # Python 3.5+
5
+    from http import HTTPStatus
6
+except ImportError:
7
+    from http import client as HTTPStatus
8
+
5 9
 import functools
6 10
 
7 11
 import marshmallow

+ 4 - 1
tests/base.py View File

@@ -1,6 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import typing
3
-from http import HTTPStatus
3
+try:  # Python 3.5+
4
+    from http import HTTPStatus
5
+except ImportError:
6
+    from http import client as HTTPStatus
4 7
 
5 8
 from multidict import MultiDict
6 9
 

+ 5 - 5
tests/func/fake_api/common.py View File

@@ -51,13 +51,13 @@ SWAGGER_DOC_API = {
51 51
          'get': {
52 52
            'description': 'General information about this API.',
53 53
            'responses': {200: {
54
-               'description': 'HTTPStatus.OK',
54
+               'description': 200,
55 55
                'schema': {'$ref': '#/definitions/AboutResponseSchema'}}}}}),
56 56
       ('/users', {
57 57
          'get': {
58 58
            'description': 'Obtain users list.',
59 59
            'responses': {200: {
60
-               'description': 'HTTPStatus.OK',
60
+               'description': 200,
61 61
                'schema': {'$ref': '#/definitions/ListsUserSchema'}}}}}),
62 62
       ('/users/{id}', {
63 63
          'delete': {
@@ -67,7 +67,7 @@ SWAGGER_DOC_API = {
67 67
                            'required': True,
68 68
                            'type': 'integer'}],
69 69
            'responses': {204: {
70
-               'description': '204',
70
+               'description': 204,
71 71
                'schema': {'$ref': '#/definitions/NoContentSchema'}}}},
72 72
          'get': {
73 73
              'description': 'Obtain one user',
@@ -76,7 +76,7 @@ SWAGGER_DOC_API = {
76 76
                              'required': True,
77 77
                              'type': 'integer'}],
78 78
              'responses': {200: {
79
-                 'description': 'HTTPStatus.OK',
79
+                 'description': 200,
80 80
                  'schema': {'$ref': '#/definitions/UserSchema'}}}}}),
81 81
       ('/users/', {
82 82
          'post': {
@@ -85,7 +85,7 @@ SWAGGER_DOC_API = {
85 85
                              'name': 'body',
86 86
                              'schema': {'$ref': '#/definitions/UserSchema'}}],
87 87
              'responses': {200: {
88
-                 'description': 'HTTPStatus.OK',
88
+                 'description': 200,
89 89
                  'schema': {'$ref': '#/definitions/UserSchema'}}}}})]),
90 90
  'swagger': '2.0',
91 91
  'tags': []

+ 4 - 1
tests/func/test_marshmallow_decoration.py View File

@@ -1,5 +1,8 @@
1 1
 # coding: utf-8
2
-from http import HTTPStatus
2
+try:  # Python 3.5+
3
+    from http import HTTPStatus
4
+except ImportError:
5
+    from http import client as HTTPStatus
3 6
 
4 7
 import marshmallow
5 8
 

+ 4 - 1
tests/unit/test_decorator.py View File

@@ -1,6 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import typing
3
-from http import HTTPStatus
3
+try:  # Python 3.5+
4
+    from http import HTTPStatus
5
+except ImportError:
6
+    from http import client as HTTPStatus
4 7
 
5 8
 import marshmallow
6 9
 from multidict import MultiDict