diff --git a/src/pyipp/serializer.py b/src/pyipp/serializer.py index 80ca2a436..2563c239b 100644 --- a/src/pyipp/serializer.py +++ b/src/pyipp/serializer.py @@ -1,6 +1,7 @@ """Data Serializer for IPP.""" from __future__ import annotations +import logging import random import struct from typing import Any @@ -9,8 +10,10 @@ from .enums import IppTag from .tags import ATTRIBUTE_TAG_MAP +_LOGGER = logging.getLogger(__name__) -def construct_attibute_values(tag: IppTag, value: Any) -> bytes: + +def construct_attribute_values(tag: IppTag, value: Any) -> bytes: """Serialize the attribute values into IPP format.""" byte_str = b"" @@ -32,13 +35,11 @@ def construct_attribute(name: str, value: Any, tag: IppTag | None = None) -> byt """Serialize the attribute into IPP format.""" byte_str = b"" - if not tag: - tag = ATTRIBUTE_TAG_MAP.get(name, None) - - if not tag: + if not tag and not (tag := ATTRIBUTE_TAG_MAP.get(name, None)): + _LOGGER.debug("Unknown IppTag for %s", name) return byte_str - if isinstance(value, (list, tuple, set)): + if isinstance(value, (list, tuple, set)): # noqa: UP038 for index, list_value in enumerate(value): byte_str += struct.pack(">b", tag.value) @@ -48,14 +49,14 @@ def construct_attribute(name: str, value: Any, tag: IppTag | None = None) -> byt else: byte_str += struct.pack(">h", 0) - byte_str += construct_attibute_values(tag, list_value) + byte_str += construct_attribute_values(tag, list_value) else: byte_str = struct.pack(">b", tag.value) byte_str += struct.pack(">h", len(name)) byte_str += name.encode("utf-8") - byte_str += construct_attibute_values(tag, value) + byte_str += construct_attribute_values(tag, value) return byte_str diff --git a/src/pyipp/tags.py b/src/pyipp/tags.py index f1e6d2d46..9d03fba17 100644 --- a/src/pyipp/tags.py +++ b/src/pyipp/tags.py @@ -13,13 +13,22 @@ "document-format": IppTag.MIME_TYPE, "last-document": IppTag.BOOLEAN, "copies": IppTag.INTEGER, + "job-cancel-after": IppTag.INTEGER, "job-hold-until": IppTag.KEYWORD, + "job-k-octets": IppTag.INTEGER, + "job-impressions-completed": IppTag.INTEGER, + "job-media-sheets-completed": IppTag.INTEGER, + "job-originating-host-name": IppTag.NAME, + "job-originating-user-name": IppTag.NAME, + "job-printer-state-message": IppTag.TEXT, + "job-printer-state-reasons": IppTag.KEYWORD, "job-priority": IppTag.INTEGER, "number-up": IppTag.INTEGER, "job-sheets": IppTag.NAME, "job-uri": IppTag.URI, "job-state": IppTag.ENUM, "job-state-reasons": IppTag.KEYWORD, + "job-uuid": IppTag.URI, "requested-attributes": IppTag.KEYWORD, "member-uris": IppTag.URI, "operations-supported": IppTag.ENUM, @@ -27,7 +36,10 @@ "printer-state-reason": IppTag.KEYWORD, "printer-is-shared": IppTag.BOOLEAN, "printer-error-policy": IppTag.NAME, + "printer-geo-location": IppTag.URI, "printer-info": IppTag.TEXT, + "printer-organization": IppTag.TEXT, + "printer-organizational-unit": IppTag.TEXT, "which-jobs": IppTag.KEYWORD, "my-jobs": IppTag.BOOLEAN, "purge-jobs": IppTag.BOOLEAN, @@ -44,4 +56,7 @@ "finishings": IppTag.ENUM, "orientation-requested": IppTag.ENUM, "print-quality": IppTag.ENUM, + "time-at-creation": IppTag.INTEGER, + "time-at-processing": IppTag.INTEGER, + "time-at-completed": IppTag.INTEGER, } diff --git a/tests/test_serializer.py b/tests/test_serializer.py index 4e14158de..eb00a61ec 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -8,12 +8,12 @@ def test_construct_attibute_values() -> None: """Test the __construct_attibute_values method.""" - result = serializer.construct_attibute_values( + result = serializer.construct_attribute_values( IppTag.INTEGER, IppOperation.GET_PRINTER_ATTRIBUTES ) assert result == b"\x00\x04\x00\x00\x00\x0b" - result = serializer.construct_attibute_values( + result = serializer.construct_attribute_values( IppTag.ENUM, IppOperation.GET_PRINTER_ATTRIBUTES ) assert result == b"\x00\x04\x00\x00\x00\x0b" @@ -31,6 +31,16 @@ def test_construct_attribute() -> None: assert result == b"#\x00\x14operations-supported\x00\x04\x00\x00\x00\x0b" +def test_construct_attribute_no_tag_unmapped() -> None: + """Test the construct_attribute method with no tag and unmapped attribute name.""" + result = serializer.construct_attribute( + "no-tag-unmapped", + None, + ) + + assert result == b"" + + def test_encode_dict() -> None: """Test the encode_dict method.""" result = serializer.encode_dict(