Codebase list jsonrpclib-pelix / 9569d6af-1295-4c89-869e-c75ae5127d2e/upstream
Import upstream version 0.4.3.1 Debian Janitor 2 years ago
16 changed file(s) with 204 addition(s) and 121 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 2.1
11 Name: jsonrpclib-pelix
2 Version: 0.4.2
2 Version: 0.4.3.1
33 Summary: This project is an implementation of the JSON-RPC v2.0 specification (backwards-compatible) as a client library, for Python 2.7 and Python 3. This version is a fork of jsonrpclib by Josh Marshall, made to be also usable with Pelix/iPOPO remote services.
44 Home-page: http://github.com/tcalmant/jsonrpclib/
55 Author: Thomas Calmant
7171
7272 ## Requirements
7373
74 This library supports `cjson` and `simplejson`, and looks for the parsers in
75 that order (searching first for `cjson`, then for the *built-in* `json` in 2.7+,
76 and then the `simplejson` external library).
74 This library supports `ujson`, `cjson` and `simplejson`, and looks for the
75 parsers in that order (searching first for `ujson`, `cjson`, `simplejson`
76 and finally for the *built-in* `json`).
7777 One of these must be installed to use this library, although if you have a
7878 standard distribution of 2.7+, you should already have one.
79 Keep in mind that `cjson` is supposed to be the quickest, I believe, so if you
79 Keep in mind that `ujson` is supposed to be the quickest, I believe, so if you
8080 are going for full-on optimization you may want to pick it up.
8181
8282 ## Installation
6363
6464 ## Requirements
6565
66 This library supports `cjson` and `simplejson`, and looks for the parsers in
67 that order (searching first for `cjson`, then for the *built-in* `json` in 2.7+,
68 and then the `simplejson` external library).
66 This library supports `ujson`, `cjson` and `simplejson`, and looks for the
67 parsers in that order (searching first for `ujson`, `cjson`, `simplejson`
68 and finally for the *built-in* `json`).
6969 One of these must be installed to use this library, although if you have a
7070 standard distribution of 2.7+, you should already have one.
71 Keep in mind that `cjson` is supposed to be the quickest, I believe, so if you
71 Keep in mind that `ujson` is supposed to be the quickest, I believe, so if you
7272 are going for full-on optimization you may want to pick it up.
7373
7474 ## Installation
44 CGI request handler.
55
66 :authors: Josh Marshall, Thomas Calmant
7 :copyright: Copyright 2020, Thomas Calmant
7 :copyright: Copyright 2021, Thomas Calmant
88 :license: Apache License 2.0
9 :version: 0.4.2
9 :version: 0.4.3.1
1010
1111 ..
1212
13 Copyright 2020 Thomas Calmant
13 Copyright 2021 Thomas Calmant
1414
1515 Licensed under the Apache License, Version 2.0 (the "License");
1616 you may not use this file except in compliance with the License.
8282 # ------------------------------------------------------------------------------
8383
8484 # Module version
85 __version_info__ = (0, 4, 2)
85 __version_info__ = (0, 4, 3, 1)
8686 __version__ = ".".join(str(x) for x in __version_info__)
8787
8888 # Documentation strings format
33 Aliases to ease access to jsonrpclib classes
44
55 :authors: Josh Marshall, Thomas Calmant
6 :copyright: Copyright 2020, Thomas Calmant
6 :copyright: Copyright 2021, Thomas Calmant
77 :license: Apache License 2.0
8 :version: 0.4.2
8 :version: 0.4.3.1
99
1010 ..
1111
12 Copyright 2020 Thomas Calmant
12 Copyright 2021 Thomas Calmant
1313
1414 Licensed under the Apache License, Version 2.0 (the "License");
1515 you may not use this file except in compliance with the License.
4242
4343
4444 # Module version
45 __version_info__ = (0, 4, 2)
45 __version_info__ = (0, 4, 3, 1)
4646 __version__ = ".".join(str(x) for x in __version_info__)
4747
4848 # Documentation strings format
22 """
33 The configuration module.
44
5 :copyright: Copyright 2020, Thomas Calmant
5 :copyright: Copyright 2021, Thomas Calmant
66 :license: Apache License 2.0
7 :version: 0.4.2
7 :version: 0.4.3.1
88
99 ..
1010
11 Copyright 2020 Thomas Calmant
11 Copyright 2021 Thomas Calmant
1212
1313 Licensed under the Apache License, Version 2.0 (the "License");
1414 you may not use this file except in compliance with the License.
2828 # ------------------------------------------------------------------------------
2929
3030 # Module version
31 __version_info__ = (0, 4, 2)
31 __version_info__ = (0, 4, 3, 1)
3232 __version__ = ".".join(str(x) for x in __version_info__)
3333
3434 # Documentation strings format
33 The history module.
44
55 :authors: Josh Marshall, Thomas Calmant
6 :copyright: Copyright 2020, Thomas Calmant
6 :copyright: Copyright 2021, Thomas Calmant
77 :license: Apache License 2.0
8 :version: 0.4.2
8 :version: 0.4.3.1
99
1010 ..
1111
12 Copyright 2020 Thomas Calmant
12 Copyright 2021 Thomas Calmant
1313
1414 Licensed under the Apache License, Version 2.0 (the "License");
1515 you may not use this file except in compliance with the License.
2525 """
2626
2727 # Module version
28 __version_info__ = (0, 4, 2)
28 __version_info__ = (0, 4, 3, 1)
2929 __version__ = ".".join(str(x) for x in __version_info__)
3030
3131 # Documentation strings format
33 The serialization module
44
55 :authors: Josh Marshall, Thomas Calmant
6 :copyright: Copyright 2020, Thomas Calmant
6 :copyright: Copyright 2021, Thomas Calmant
77 :license: Apache License 2.0
8 :version: 0.4.2
8 :version: 0.4.3.1
99
1010 ..
1111
12 Copyright 2020 Thomas Calmant
12 Copyright 2021 Thomas Calmant
1313
1414 Licensed under the Apache License, Version 2.0 (the "License");
1515 you may not use this file except in compliance with the License.
3535 # ------------------------------------------------------------------------------
3636
3737 # Module version
38 __version_info__ = (0, 4, 2)
38 __version_info__ = (0, 4, 3, 1)
3939 __version__ = ".".join(str(x) for x in __version_info__)
4040
4141 # Documentation strings format
0 #!/usr/bin/python
1 # -- Content-Encoding: UTF-8 --
2 """
3 Loads the "best" Python library available for the current interpreter and
4 provides a single interface for all
5
6 :authors: Thomas Calmant
7 :copyright: Copyright 2021, Thomas Calmant
8 :license: Apache License 2.0
9 :version: 0.4.3.1
10
11 ..
12
13 Copyright 2021 Thomas Calmant
14
15 Licensed under the Apache License, Version 2.0 (the "License");
16 you may not use this file except in compliance with the License.
17 You may obtain a copy of the License at
18
19 http://www.apache.org/licenses/LICENSE-2.0
20
21 Unless required by applicable law or agreed to in writing, software
22 distributed under the License is distributed on an "AS IS" BASIS,
23 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 See the License for the specific language governing permissions and
25 limitations under the License.
26 """
27
28 # Standard library
29 import json
30 import sys
31
32 # ------------------------------------------------------------------------------
33
34 # Module version
35 __version_info__ = (0, 4, 3, 1)
36 __version__ = ".".join(str(x) for x in __version_info__)
37
38 # Documentation strings format
39 __docformat__ = "restructuredtext en"
40
41 # Python version flag
42 PYTHON_2 = sys.version_info[0] < 3
43
44 # ------------------------------------------------------------------------------
45
46
47 class JsonHandler(object):
48 """
49 Parent class for JSON handlers
50 """
51
52 def get_methods(self):
53 """
54 Returns the loads and dumps methods
55 """
56 if PYTHON_2:
57 # We use the Py2 API with an encoding argument
58 return json.loads, json.dumps
59
60 def dumps_py3(obj, encoding="utf-8"):
61 return json.dumps(obj)
62
63 return json.loads, dumps_py3
64
65
66 class CJsonHandler(JsonHandler):
67 """
68 Handler based on cjson
69 """
70
71 def get_methods(self):
72 import cjson
73
74 def dumps_cjson(obj, encoding="utf-8"):
75 return cjson.encode(obj)
76
77 return cjson.decode, dumps_cjson
78
79
80 class SimpleJsonHandler(JsonHandler):
81 """
82 Handler based on simplejson
83 """
84
85 def get_methods(self):
86 import simplejson
87
88 return simplejson.loads, simplejson.dumps
89
90
91 class UJsonHandler(JsonHandler):
92 """
93 Handler based on ujson
94 """
95
96 def get_methods(self):
97 import ujson
98
99 def dumps_ujson(obj, encoding="utf-8"):
100 return ujson.dumps(obj)
101
102 return ujson.loads, dumps_ujson
103
104
105 def get_handler():
106 # type: () -> JsonHandler
107 """
108 Returns the best available Json parser
109 """
110 for handler_class in (UJsonHandler, SimpleJsonHandler, CJsonHandler):
111 handler = handler_class()
112 try:
113 loader, dumper = handler.get_methods()
114 except ImportError:
115 # Library is missing
116 pass
117 else:
118 try:
119 # Check if the library really works
120 loader(dumper({"answer": 42}))
121 break
122 except Exception:
123 pass
124 else:
125 handler = JsonHandler()
126
127 return handler
128
129
130 def get_handler_methods():
131 """
132 Returns the load and dump methods of the best Json handler
133 """
134 return get_handler().get_methods()
3535 See https://github.com/tcalmant/jsonrpclib for more info.
3636
3737 :authors: Josh Marshall, Thomas Calmant
38 :copyright: Copyright 2020, Thomas Calmant
38 :copyright: Copyright 2021, Thomas Calmant
3939 :license: Apache License 2.0
40 :version: 0.4.2
40 :version: 0.4.3.1
4141
4242 ..
4343
44 Copyright 2020 Thomas Calmant
44 Copyright 2021 Thomas Calmant
4545
4646 Licensed under the Apache License, Version 2.0 (the "License");
4747 you may not use this file except in compliance with the License.
6161 import logging
6262 import os
6363 import socket
64 import sys
6564 import uuid
6665
6766 try:
9392
9493 # Library includes
9594 import jsonrpclib.config
95 import jsonrpclib.jsonlib as jsonlib
9696 import jsonrpclib.jsonclass as jsonclass
9797 import jsonrpclib.utils as utils
9898
9999 # ------------------------------------------------------------------------------
100100
101101 # Module version
102 __version_info__ = (0, 4, 2)
102 __version_info__ = (0, 4, 3, 1)
103103 __version__ = ".".join(str(x) for x in __version_info__)
104104
105105 # Documentation strings format
109109 _logger = logging.getLogger(__name__)
110110
111111 # ------------------------------------------------------------------------------
112 # JSON library import
113
114 try:
115 # pylint: disable=F0401,E0611
116 # Using cjson
117 import cjson # type: ignore
118
119 _logger.debug("Using cjson as JSON library")
120
121 # Declare cjson methods
122 def jdumps(obj, encoding="utf-8"): # pylint: disable=unused-argument
123 """
124 Serializes ``obj`` to a JSON formatted string, using cjson.
125 """
126 return cjson.encode(obj)
127
128 def jloads(json_string):
129 """
130 Deserializes ``json_string`` (a string containing a JSON document)
131 to a Python object, using cjson.
132 """
133 return cjson.decode(json_string)
134
135
136 except ImportError:
137 # pylint: disable=F0401,E0611
138 # Use json or simplejson
139 try:
140 import json
141
142 _logger.debug("Using json as JSON library")
143 except ImportError:
144 try:
145 import simplejson as json # type: ignore
146
147 _logger.debug("Using simplejson as JSON library")
148 except ImportError:
149 _logger.error("No supported JSON library found")
150 raise ImportError(
151 "You must have the cjson, json, or simplejson "
152 "module(s) available."
153 )
154
155 # Declare json methods
156 if sys.version_info[0] < 3:
157
158 def jdumps(obj, encoding="utf-8"):
159 """
160 Serializes ``obj`` to a JSON formatted string.
161 """
162 # Python 2 (explicit encoding)
163 return json.dumps(obj, encoding=encoding)
164
165 else:
166 # Python 3
167 def jdumps(obj, encoding="utf-8"): # pylint: disable=unused-argument
168 """
169 Serializes ``obj`` to a JSON formatted string.
170 """
171 # Python 3 (the encoding parameter has been removed)
172 return json.dumps(obj)
173
174 def jloads(json_string):
175 """
176 Deserializes ``json_string`` (a string containing a JSON document)
177 to a Python object.
178 """
179 return json.loads(json_string)
180
112 # JSON library selection
113
114 jloads, jdumps = jsonlib.get_handler_methods()
181115
182116 # ------------------------------------------------------------------------------
183117 # XMLRPClib re-implementations
628562 schema = su.scheme
629563 self.__host = su.netloc
630564 self.__handler = su.path
565 self.__query_string = su.query
631566
632567 use_unix = False
633568 if schema.startswith("unix+"):
726661 if self.__history is not None:
727662 self.__history.add_request(request)
728663
664 # Add the query string to the path
665 if not self.__query_string:
666 path_qs = self.__handler
667 else:
668 path_qs = "{}?{}".format(self.__handler, self.__query_string)
669
729670 response = self.__transport.request(
730 self.__host, self.__handler, request, verbose=self.__verbose
671 self.__host, path_qs, request, verbose=self.__verbose
731672 )
732673
733674 # Here, the XMLRPC library translates a single list
33 Cached thread pool, inspired from Pelix/iPOPO Thread Pool
44
55 :author: Thomas Calmant
6 :copyright: Copyright 2020, Thomas Calmant
6 :copyright: Copyright 2021, Thomas Calmant
77 :license: Apache License 2.0
8 :version: 0.4.2
8 :version: 0.4.3.1
99
1010 ..
1111
12 Copyright 2020 Thomas Calmant
12 Copyright 2021 Thomas Calmant
1313
1414 Licensed under the Apache License, Version 2.0 (the "License");
1515 you may not use this file except in compliance with the License.
3838 # ------------------------------------------------------------------------------
3939
4040 # Module version
41 __version_info__ = (0, 4, 2)
41 __version_info__ = (0, 4, 3, 1)
4242 __version__ = ".".join(str(x) for x in __version_info__)
4343
4444 # Documentation strings format
33 Utility methods, for compatibility between Python version
44
55 :author: Thomas Calmant
6 :copyright: Copyright 2020, Thomas Calmant
6 :copyright: Copyright 2021, Thomas Calmant
77 :license: Apache License 2.0
8 :version: 0.4.2
8 :version: 0.4.3.1
99
1010 ..
1111
12 Copyright 2020 Thomas Calmant
12 Copyright 2021 Thomas Calmant
1313
1414 Licensed under the Apache License, Version 2.0 (the "License");
1515 you may not use this file except in compliance with the License.
2929 # ------------------------------------------------------------------------------
3030
3131 # Module version
32 __version_info__ = (0, 4, 2)
32 __version_info__ = (0, 4, 3, 1)
3333 __version__ = ".".join(str(x) for x in __version_info__)
3434
3535 # Documentation strings format
00 Metadata-Version: 2.1
11 Name: jsonrpclib-pelix
2 Version: 0.4.2
2 Version: 0.4.3.1
33 Summary: This project is an implementation of the JSON-RPC v2.0 specification (backwards-compatible) as a client library, for Python 2.7 and Python 3. This version is a fork of jsonrpclib by Josh Marshall, made to be also usable with Pelix/iPOPO remote services.
44 Home-page: http://github.com/tcalmant/jsonrpclib/
55 Author: Thomas Calmant
7171
7272 ## Requirements
7373
74 This library supports `cjson` and `simplejson`, and looks for the parsers in
75 that order (searching first for `cjson`, then for the *built-in* `json` in 2.7+,
76 and then the `simplejson` external library).
74 This library supports `ujson`, `cjson` and `simplejson`, and looks for the
75 parsers in that order (searching first for `ujson`, `cjson`, `simplejson`
76 and finally for the *built-in* `json`).
7777 One of these must be installed to use this library, although if you have a
7878 standard distribution of 2.7+, you should already have one.
79 Keep in mind that `cjson` is supposed to be the quickest, I believe, so if you
79 Keep in mind that `ujson` is supposed to be the quickest, I believe, so if you
8080 are going for full-on optimization you may want to pick it up.
8181
8282 ## Installation
00 LICENSE
11 MANIFEST.in
22 README.md
3 pyproject.toml
34 setup.cfg
45 setup.py
56 jsonrpclib/SimpleJSONRPCServer.py
78 jsonrpclib/config.py
89 jsonrpclib/history.py
910 jsonrpclib/jsonclass.py
11 jsonrpclib/jsonlib.py
1012 jsonrpclib/jsonrpc.py
1113 jsonrpclib/threadpool.py
1214 jsonrpclib/utils.py
0 [tool.black]
1 line-length = 80
33 [flake8]
44 max-line-length = 80
55
6 [nosetests]
7 traverse-namespace = 1
8
69 [egg_info]
710 tag_build =
811 tag_date = 0
33 Installation script
44
55 :authors: Josh Marshall, Thomas Calmant
6 :copyright: Copyright 2020, Thomas Calmant
6 :copyright: Copyright 2021, Thomas Calmant
77 :license: Apache License 2.0
8 :version: 0.4.2
8 :version: 0.4.3.1
99
1010 ..
1111
12 Copyright 2020 Thomas Calmant
12 Copyright 2021 Thomas Calmant
1313
1414 Licensed under the Apache License, Version 2.0 (the "License");
1515 you may not use this file except in compliance with the License.
2525 """
2626
2727 # Module version
28 __version_info__ = (0, 4, 2)
28 __version_info__ = (0, 4, 3, 1)
2929 __version__ = ".".join(str(x) for x in __version_info__)
3030
3131 # Documentation strings format