Browse Source

python 3.4 campat

Bastien Sevajol 6 years ago
parent
commit
19a0d968c7

+ 1 - 1
.gitignore View File

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

+ 1 - 0
.travis.yml View File

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

+ 4 - 1
example/example_a_bottle.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import json
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
 import bottle
8
 import bottle
6
 import time
9
 import time

+ 4 - 1
example/example_a_flask.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import json
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
 from flask import Flask
8
 from flask import Flask
6
 import hapic
9
 import hapic

+ 4 - 1
example/example_a_pyramid.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import json
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
 from pyramid.config import Configurator
8
 from pyramid.config import Configurator
6
 from wsgiref.simple_server import make_server
9
 from wsgiref.simple_server import make_server

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

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

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

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

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

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

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

2
 
2
 
3
 import bottle
3
 import bottle
4
 from datetime import datetime
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
 import json
9
 import json
7
 import time
10
 import time
8
 
11
 

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

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 
2
 
3
 from datetime import datetime
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
 import json
8
 import json
6
 import flask
9
 import flask
7
 import time
10
 import time

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

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 
2
 
3
 from datetime import datetime
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
 import json
8
 import json
6
 from pyramid.config import Configurator
9
 from pyramid.config import Configurator
7
 import time
10
 import time

+ 4 - 1
hapic/context.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import typing
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
 from hapic.processor import RequestParameters
8
 from hapic.processor import RequestParameters
6
 from hapic.processor import ProcessValidationError
9
 from hapic.processor import ProcessValidationError

+ 4 - 1
hapic/decorator.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import functools
2
 import functools
3
 import typing
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
 # TODO BS 20171010: bottle specific !  # see #5
9
 # TODO BS 20171010: bottle specific !  # see #5
7
 import marshmallow
10
 import marshmallow

+ 3 - 3
hapic/doc.py View File

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

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

2
 import json
2
 import json
3
 import re
3
 import re
4
 import typing
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
 import bottle
10
 import bottle
8
 from multidict import MultiDict
11
 from multidict import MultiDict

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

2
 import json
2
 import json
3
 import re
3
 import re
4
 import typing
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
 from hapic.context import ContextInterface
10
 from hapic.context import ContextInterface
8
 from hapic.context import RouteRepresentation
11
 from hapic.context import RouteRepresentation

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

2
 import json
2
 import json
3
 import re
3
 import re
4
 import typing
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
 from hapic.context import ContextInterface
10
 from hapic.context import ContextInterface
8
 from hapic.context import RouteRepresentation
11
 from hapic.context import RouteRepresentation

+ 5 - 1
hapic/hapic.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import typing
2
 import typing
3
 import uuid
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
 import functools
9
 import functools
6
 
10
 
7
 import marshmallow
11
 import marshmallow

+ 4 - 1
tests/base.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import typing
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
 from multidict import MultiDict
8
 from multidict import MultiDict
6
 
9
 

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

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

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

1
 # coding: utf-8
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
 import marshmallow
7
 import marshmallow
5
 
8
 

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

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import typing
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
 import marshmallow
8
 import marshmallow
6
 from multidict import MultiDict
9
 from multidict import MultiDict