httpdis 0.6.27__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- httpdis/__init__.py +1 -0
- httpdis/config.py +24 -0
- httpdis/ext/__init__.py +1 -0
- httpdis/ext/httpdis_json.py +73 -0
- httpdis/httpdis.py +1254 -0
- httpdis-0.6.27.dist-info/METADATA +150 -0
- httpdis-0.6.27.dist-info/RECORD +10 -0
- httpdis-0.6.27.dist-info/WHEEL +6 -0
- httpdis-0.6.27.dist-info/licenses/LICENSE +674 -0
- httpdis-0.6.27.dist-info/top_level.txt +1 -0
httpdis/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__ = []
|
httpdis/config.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2008-2019 The Wazo Authors
|
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
"""httpsdis.config"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
BUFFER_SIZE = 65536
|
|
8
|
+
DEFAULT_CHARSET = 'utf-8'
|
|
9
|
+
|
|
10
|
+
DEFAULT_OPTIONS = {'auth_basic': None,
|
|
11
|
+
'auth_basic_file': None,
|
|
12
|
+
'testmethods': False,
|
|
13
|
+
'max_body_size': 1 * 1024 * 1024,
|
|
14
|
+
'max_workers': 1,
|
|
15
|
+
'max_requests': 0,
|
|
16
|
+
'max_life_time': 0,
|
|
17
|
+
'listen_addr': None,
|
|
18
|
+
'listen_port': None,
|
|
19
|
+
'server_version': None,
|
|
20
|
+
'sys_version': None}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_default_options():
|
|
24
|
+
return DEFAULT_OPTIONS.copy()
|
httpdis/ext/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__ = []
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2018-2019 Adrien Delle Cave
|
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
+
"""httpdis.ext.json"""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
from six import (binary_type,
|
|
10
|
+
ensure_str,
|
|
11
|
+
ensure_text,
|
|
12
|
+
iteritems,
|
|
13
|
+
text_type)
|
|
14
|
+
|
|
15
|
+
from httpdis import httpdis
|
|
16
|
+
# pylint: disable=unused-import
|
|
17
|
+
from httpdis.httpdis import (init,
|
|
18
|
+
HttpReqError,
|
|
19
|
+
HttpReqErrJson,
|
|
20
|
+
HttpResponse,
|
|
21
|
+
HttpResponseJson,
|
|
22
|
+
KillableThreadingHTTPServer,
|
|
23
|
+
register,
|
|
24
|
+
sigterm_handler,
|
|
25
|
+
stop)
|
|
26
|
+
|
|
27
|
+
from httpdis.config import (DEFAULT_CHARSET,
|
|
28
|
+
get_default_options)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
LOG = logging.getLogger('httpdis.ext.json') # pylint: disable-msg=C0103
|
|
32
|
+
CONTENT_TYPE = 'application/json'
|
|
33
|
+
|
|
34
|
+
HTTP_RESPONSE_CLASS = HttpResponseJson
|
|
35
|
+
HTTP_REQERROR_CLASS = HttpReqErrJson
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _encode_if(value, encoding=DEFAULT_CHARSET):
|
|
39
|
+
# transform value returned by json.loads to something similar to what
|
|
40
|
+
# cjson.decode would have returned
|
|
41
|
+
if isinstance(value, (text_type, binary_type)):
|
|
42
|
+
return ensure_str(value, encoding)
|
|
43
|
+
if isinstance(value, list):
|
|
44
|
+
return [_encode_if(v, encoding) for v in value]
|
|
45
|
+
if isinstance(value, dict):
|
|
46
|
+
return dict((_encode_if(k, encoding), _encode_if(v, encoding)) for
|
|
47
|
+
(k, v) in iteritems(value))
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class HttpReqHandler(httpdis.HttpReqHandler):
|
|
52
|
+
_DEFAULT_CONTENT_TYPE = CONTENT_TYPE
|
|
53
|
+
_ALLOWED_CONTENT_TYPES = [CONTENT_TYPE,
|
|
54
|
+
'application/x-www-form-urlencoded']
|
|
55
|
+
_FUNC_SEND_ERROR = 'send_error_json'
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def parse_payload(data, charset):
|
|
59
|
+
return _encode_if(json.loads(ensure_text(data, charset)), charset)
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def response_dumps(data, charset):
|
|
63
|
+
return json.dumps(_encode_if(data, charset))
|
|
64
|
+
|
|
65
|
+
def _mk_error_explain_data(self, code, message, explain, charset):
|
|
66
|
+
return self.response_dumps({'code': code,
|
|
67
|
+
'message': message,
|
|
68
|
+
'explain': explain},
|
|
69
|
+
charset)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def run(options, http_req_handler = HttpReqHandler, http_server_class = KillableThreadingHTTPServer):
|
|
73
|
+
return httpdis.run(options, http_req_handler, http_server_class)
|