diff --git a/examples/langserver.py b/examples/langserver.py index a1ddc8f..5a40f1c 100644 --- a/examples/langserver.py +++ b/examples/langserver.py @@ -5,8 +5,8 @@ from pylsp_jsonrpc import dispatchers, endpoint try: - import ujson as json -except Exception: # pylint: disable=broad-except + import orjson as json +except ImportError: import json log = logging.getLogger(__name__) diff --git a/examples/langserver_ext.py b/examples/langserver_ext.py index 3371a20..19d227c 100644 --- a/examples/langserver_ext.py +++ b/examples/langserver_ext.py @@ -7,8 +7,8 @@ from pylsp_jsonrpc import streams try: - import ujson as json -except Exception: # pylint: disable=broad-except + import orjson as json +except ImportError: import json log = logging.getLogger(__name__) diff --git a/pylsp_jsonrpc/streams.py b/pylsp_jsonrpc/streams.py index 40048a9..0a85a19 100644 --- a/pylsp_jsonrpc/streams.py +++ b/pylsp_jsonrpc/streams.py @@ -5,8 +5,8 @@ import threading try: - import ujson as json -except Exception: # pylint: disable=broad-except + import orjson as json +except ImportError: import json log = logging.getLogger(__name__) diff --git a/pyproject.toml b/pyproject.toml index 376785c..2c4d196 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ authors = [{name = "Python Language Server Contributors"}] description = "JSON RPC 2.0 server library" license = {text = "MIT"} requires-python = ">=3.8" -dependencies = ["ujson>=3.0.0"] +dependencies = ["orjson>=3.10.0"] dynamic = ["version"] classifiers = [ "License :: OSI Approved :: MIT License", diff --git a/test/test_streams.py b/test/test_streams.py index 14fe1bb..4dde134 100644 --- a/test/test_streams.py +++ b/test/test_streams.py @@ -77,25 +77,20 @@ def test_reader_bad_json(rfile, reader): def test_writer(wfile, writer): - writer.write({ + data = { 'id': 'hello', 'method': 'method', 'params': {} - }) - if 'ujson' in sys.modules: - assert wfile.getvalue() == ( - b'Content-Length: 44\r\n' - b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n' - b'\r\n' - b'{"id":"hello","method":"method","params":{}}' - ) - else: - assert wfile.getvalue() == ( - b'Content-Length: 49\r\n' - b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n' - b'\r\n' - b'{"id": "hello", "method": "method", "params": {}}' - ) + } + writer.write(data) + + raw_result = wfile.getvalue().decode() + raw_result_lines = raw_result.split() + + assert raw_result_lines[0].split(":") == "Content-Length" + assert raw_result_lines[1] == 'Content-Type: application/vscode-jsonrpc; charset=utf8' + assert raw_result_lines[2] == '' + assert json.loads(raw_result_lines[3]) == data class JsonDatetime(datetime.datetime):