From e02a11b1bd78bc89aab9c2d668aaa6fe985ed16d Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 3 Oct 2022 02:32:40 -0500 Subject: [PATCH] work --- src/pyipp/ipp.py | 11 +++++------ src/pyipp/parser.py | 11 +++++++++++ tests/test_parser.py | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/pyipp/ipp.py b/src/pyipp/ipp.py index b82f0d997..7029c5f0e 100644 --- a/src/pyipp/ipp.py +++ b/src/pyipp/ipp.py @@ -161,7 +161,7 @@ def _build_printer_uri(self) -> str: scheme=scheme, host=self.host, port=self.port, path=self.base_path ).human_repr() - def _message(self, operation: IppOperation, msg: dict) -> dict: + def _message(self, operation: IppOperation, msg: dict[str, Any]) -> dict[str, Any]: """Build a request message to be sent to the server.""" base = { "version": DEFAULT_PROTO_VERSION, @@ -175,12 +175,11 @@ def _message(self, operation: IppOperation, msg: dict) -> dict: }, } - if msg is not dict: - msg = {} - return always_merger.merge(base, msg) - async def execute(self, operation: IppOperation, message: dict) -> dict: + async def execute( + self, operation: IppOperation, message: dict[str, Any] + ) -> dict[str, Any]: """Send a request message to the server.""" message = self._message(operation, message) response = await self._request(data=message) @@ -201,7 +200,7 @@ async def execute(self, operation: IppOperation, message: dict) -> dict: return parsed - async def raw(self, operation: IppOperation, message: dict) -> bytes: + async def raw(self, operation: IppOperation, message: dict[str, Any]) -> bytes: """Send a request message to the server and return raw response.""" message = self._message(operation, message) diff --git a/src/pyipp/parser.py b/src/pyipp/parser.py index 01744fd43..17e7d90f0 100644 --- a/src/pyipp/parser.py +++ b/src/pyipp/parser.py @@ -169,6 +169,7 @@ def parse(raw_data: bytes, contains_data=False): offset += 4 data["operation-attributes"] = [] + data["unsupported-attributes"] = [] data["jobs"] = [] data["printers"] = [] data["data"] = b"" @@ -202,6 +203,16 @@ def parse(raw_data: bytes, contains_data=False): attribute_key = "printers" offset += 1 + elif ( + struct.unpack_from("b", raw_data, offset)[0] + == IppTag.UNSUPPORTED_GROUP.value + ): + if tmp_data and attribute_key: + data[attribute_key].append(tmp_data) + tmp_data = {} + + attribute_key = "unsupported-attributes" + offset += 1 attribute, new_offset = parse_attribute(raw_data, offset) diff --git a/tests/test_parser.py b/tests/test_parser.py index 7b54ca114..e2c8576d0 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -27,6 +27,7 @@ def test_parse() -> None: "printers": [], "request-id": 1, "status-code": IppOperation.GET_PRINTER_ATTRIBUTES, + "unsupported-attributes": [], "version": DEFAULT_PROTO_VERSION, }