Skip to content

Commit

Permalink
Merge pull request #6 from baking-bad/aux/websockets-11
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout authored Jun 2, 2023
2 parents f938bcc + 89351ff commit 591c4a7
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 349 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].

## [Unreleased]

### Other

- `websockets` library updated to 11.0.3.
- Use faster `orjson` library for JSON deserialization.

## [0.2.0] - 2023-04-07

### Added
Expand Down
702 changes: 363 additions & 339 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ packages = [

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
websockets = "^10.3"
websockets = "^11.0.3"
aiohttp = "^3.7.4"
msgpack = "^1.0.2"
orjson = "^3.9.0"

[tool.poetry.dev-dependencies]
black = "*"
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
aiohttp==3.8.4 ; python_version >= "3.8" and python_version < "3.12"
aiosignal==1.3.1 ; python_version >= "3.8" and python_version < "3.12"
async-timeout==4.0.2 ; python_version >= "3.8" and python_version < "3.12"
attrs==22.2.0 ; python_version >= "3.8" and python_version < "3.12"
attrs==23.1.0 ; python_version >= "3.8" and python_version < "3.12"
charset-normalizer==3.1.0 ; python_version >= "3.8" and python_version < "3.12"
frozenlist==1.3.3 ; python_version >= "3.8" and python_version < "3.12"
idna==3.4 ; python_version >= "3.8" and python_version < "3.12"
msgpack==1.0.5 ; python_version >= "3.8" and python_version < "3.12"
multidict==6.0.4 ; python_version >= "3.8" and python_version < "3.12"
websockets==10.4 ; python_version >= "3.8" and python_version < "3.12"
yarl==1.8.2 ; python_version >= "3.8" and python_version < "3.12"
websockets==11.0.3 ; python_version >= "3.8" and python_version < "3.12"
yarl==1.9.2 ; python_version >= "3.8" and python_version < "3.12"
7 changes: 4 additions & 3 deletions src/pysignalr/protocol/json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from json import JSONEncoder
from typing import Any
from typing import Dict
Expand All @@ -7,6 +6,8 @@
from typing import Tuple
from typing import Union

import orjson

from pysignalr.messages import CancelInvocationMessage # 5
from pysignalr.messages import CloseMessage # 7
from pysignalr.messages import CompletionMessage # 3
Expand Down Expand Up @@ -50,7 +51,7 @@ def decode(self, raw_message: Union[str, bytes]) -> List[Message]:
if item in ('', self.record_separator):
continue

dict_message = json.loads(item)
dict_message = orjson.loads(item)
if dict_message:
messages.append(self.parse_message(dict_message))

Expand All @@ -66,7 +67,7 @@ def decode_handshake(self, raw_message: Union[str, bytes]) -> Tuple[HandshakeRes
# TODO: Cleanup
messages = raw_message.split(self.record_separator)
messages = list(filter(bool, messages))
data = json.loads(messages[0])
data = orjson.loads(messages[0])
idx = raw_message.index(self.record_separator)
return (
HandshakeResponseMessage(data.get('error', None)),
Expand Down
4 changes: 2 additions & 2 deletions src/pysignalr/protocol/messagepack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TODO: Refactor this module
import json
from collections import deque
from typing import Any
from typing import Deque
Expand All @@ -11,6 +10,7 @@
from typing import cast

import msgpack # type: ignore[import]
import orjson

from pysignalr.messages import CancelInvocationMessage
from pysignalr.messages import CloseMessage
Expand Down Expand Up @@ -81,7 +81,7 @@ def decode_handshake(self, raw_message: Union[str, bytes]) -> Tuple[HandshakeRes
has_various_messages = 0x1E in raw_message
handshake_data = raw_message[0 : raw_message.index(0x1E)] if has_various_messages else raw_message
messages = self.decode(raw_message[raw_message.index(0x1E) + 1 :]) if has_various_messages else []
data = json.loads(handshake_data)
data = orjson.loads(handshake_data)
return HandshakeResponseMessage(data.get('error', None)), messages

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion src/pysignalr/transport/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from aiohttp import ServerConnectionError
from websockets.client import WebSocketClientProtocol
from websockets.client import connect
from websockets.connection import State
from websockets.exceptions import ConnectionClosed
from websockets.protocol import State

import pysignalr.exceptions as exceptions
from pysignalr import NegotiationTimeout
Expand Down

0 comments on commit 591c4a7

Please sign in to comment.