Skip to content

Commit

Permalink
Add args & kwargs in Abort
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahad-10 committed Jul 3, 2024
1 parent 850dcd3 commit ee06830
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/messages/test_abort.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def test_parse_with_invalid_min_length():


def test_parse_with_invalid_max_length():
message = [1, {}, "io.xconn", 4]
message = [1, {}, "io.xconn", 4, 5, 6]
with pytest.raises(ValueError) as exc_info:
Abort.parse(message)

assert str(exc_info.value) == f"invalid message length {len(message)}, must be at most 3"
assert str(exc_info.value) == f"invalid message length {len(message)}, must be at most 5"


def test_parse_with_invalid_message_type():
Expand Down
32 changes: 30 additions & 2 deletions wampproto/messages/abort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ def details(self):
def reason(self):
raise NotImplementedError()

@property
def args(self):
raise NotImplementedError()

@property
def kwargs(self):
raise NotImplementedError()


class AbortFields(IAbortFields):
def __init__(self, details: dict, reason: str):
def __init__(self, details: dict, reason: str, args: list[Any] | None = None, kwargs: dict[str, Any] | None = None):
super().__init__()
self._details = details
self._reason = reason
self._args = args
self._kwargs = kwargs

@property
def details(self) -> dict[str, Any]:
Expand All @@ -31,18 +41,28 @@ def details(self) -> dict[str, Any]:
def reason(self) -> str:
return self._reason

@property
def args(self) -> list[Any] | None:
return self._args

@property
def kwargs(self) -> dict[str, Any] | None:
return self._kwargs


class Abort(Message):
TEXT = "ABORT"
TYPE = 3

VALIDATION_SPEC = ValidationSpec(
min_length=3,
max_length=3,
max_length=5,
message=TEXT,
spec={
1: util.validate_details,
2: util.validate_reason,
3: util.validate_args,
4: util.validate_kwargs,
},
)

Expand All @@ -58,6 +78,14 @@ def details(self) -> dict[str, Any]:
def reason(self) -> str:
return self._fields.reason

@property
def args(self) -> list[Any] | None:
return self._fields.args

@property
def kwargs(self) -> dict[str, Any] | None:
return self._fields.kwargs

@classmethod
def parse(cls, msg: list[Any]) -> Abort:
f = util.validate_message(msg, cls.TYPE, cls.TEXT, cls.VALIDATION_SPEC)
Expand Down

0 comments on commit ee06830

Please sign in to comment.