Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/pyipp/ipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions src/pyipp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_parse() -> None:
"printers": [],
"request-id": 1,
"status-code": IppOperation.GET_PRINTER_ATTRIBUTES,
"unsupported-attributes": [],
"version": DEFAULT_PROTO_VERSION,
}

Expand Down