From bd4562386799d6b4a4987fe4aa6f5f4ef75d4a8e Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 19:24:41 -0500 Subject: [PATCH 01/11] Update parser.py --- pyipp/parser.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyipp/parser.py b/pyipp/parser.py index db7b196ca..debb5c358 100644 --- a/pyipp/parser.py +++ b/pyipp/parser.py @@ -3,7 +3,13 @@ import struct from typing import Any, Dict, Tuple, cast -from .enums import IppDocumentState, IppJobState, IppPrinterState, IppTag +from .enums import ( + IppDocumentState, + IppJobState, + IppPrinterState, + IppStatus, + IppTag, +) _LOGGER = logging.getLogger(__name__) From ff5f6d32049931730343b915b0183bdee1608d8d Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 19:27:15 -0500 Subject: [PATCH 02/11] Update parser.py --- pyipp/parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyipp/parser.py b/pyipp/parser.py index debb5c358..348b0d368 100644 --- a/pyipp/parser.py +++ b/pyipp/parser.py @@ -75,6 +75,8 @@ def parse_attribute(data: bytes, offset: int): attribute["value"] = IppPrinterState(attribute["value"]) elif attribute["name"] == "document-state": attribute["value"] = IppDocumentState(attribute["value"]) + elif attribute["name"] == "status-code": + attribute["value"] = IppStatus(attribute["value"]) offset += 4 _LOGGER.debug("Attribute Value: %s", attribute["value"]) From 1ed111d8500b4a010c53aba838a8882658fcda54 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:04:01 -0500 Subject: [PATCH 03/11] Update ipp.py --- pyipp/ipp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyipp/ipp.py b/pyipp/ipp.py index 600221e43..970fdd231 100644 --- a/pyipp/ipp.py +++ b/pyipp/ipp.py @@ -16,13 +16,14 @@ DEFAULT_PRINTER_ATTRIBUTES, DEFAULT_PROTO_VERSION, ) -from .enums import IppOperation +from .enums import IppOperation, IppStatus from .exceptions import ( IPPConnectionError, IPPConnectionUpgradeRequired, IPPError, IPPParseError, IPPResponseError, + IPPVersionNotSupportedError, ) from .models import Printer from .parser import parse as parse_response @@ -180,7 +181,9 @@ async def execute(self, operation: IppOperation, message: dict) -> dict: except (StructError, Exception) as exc: # disable=broad-except raise IPPParseError from exc - if parsed["status-code"] != 0: + if parsed["status-code"] == IppStatus.ERROR_VERSION_NOT_SUPPORTED: + raise IPPVersionNotSupported("IPP version not supported by server") + elif parsed["status-code"] != IppStatus.OK: raise IPPError( "Unexpected printer status code", {"status-code": parsed["status-code"]}, From 3193ff14664c45ace2e37d16382122cafe7e52f9 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:04:22 -0500 Subject: [PATCH 04/11] Update __init__.py --- pyipp/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyipp/__init__.py b/pyipp/__init__.py index 1926dfe22..bfc3b28eb 100644 --- a/pyipp/__init__.py +++ b/pyipp/__init__.py @@ -6,5 +6,6 @@ IPPError, IPPParseError, IPPResponseError, + IPPVersionNotSupportedError, ) from .models import Printer # noqa From 72113af547211da8782ac7b335a9294cfdf0edaf Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:07:21 -0500 Subject: [PATCH 05/11] Add files via upload --- .../get-printer-attributes-error-0x0503.bin | Bin 0 -> 75 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fixtures/get-printer-attributes-error-0x0503.bin diff --git a/tests/fixtures/get-printer-attributes-error-0x0503.bin b/tests/fixtures/get-printer-attributes-error-0x0503.bin new file mode 100644 index 0000000000000000000000000000000000000000..c92134b9e3bc72859ffd410f8235e36622c2d57f GIT binary patch literal 75 zcmZQ%WMyVxk7is_i literal 0 HcmV?d00001 From 0855ffe29498bfd4c6ede0d02766f44c468d2f2e Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:11:45 -0500 Subject: [PATCH 06/11] Update test_client.py --- tests/test_client.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index c6dde93da..09a81339f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -11,6 +11,7 @@ IPPConnectionUpgradeRequired, IPPError, IPPParseError, + IPPVersionNotSupportedError, ) from . import ( @@ -255,3 +256,30 @@ async def test_unexpected_response(aresponses): }, }, ) + + +@pytest.mark.asyncio +async def test_ipp_error_0x0503(aresponses): + """Test IPP Error 0x0503 response handling.""" + aresponses.add( + MATCH_DEFAULT_HOST, + DEFAULT_PRINTER_PATH, + "POST", + aresponses.Response( + status=200, + headers={"Content-Type": "application/ipp"}, + body=load_fixture_binary("get-printer-attributes-error-0x0503.bin"), + ), + ) + + async with ClientSession() as session: + ipp = IPP(DEFAULT_PRINTER_URI, session=session) + with pytest.raises(IPPVersionNotSupportedError): + assert await ipp.execute( + IppOperation.GET_PRINTER_ATTRIBUTES, + { + "operation-attributes-tag": { + "requested-attributes": DEFAULT_PRINTER_ATTRIBUTES, + }, + }, + ) From b7106c4036e738a13305e00403df2fec5ac80c4c Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:13:56 -0500 Subject: [PATCH 07/11] Update exceptions.py --- pyipp/exceptions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyipp/exceptions.py b/pyipp/exceptions.py index 79e803501..c4ace9271 100644 --- a/pyipp/exceptions.py +++ b/pyipp/exceptions.py @@ -29,3 +29,9 @@ class IPPResponseError(IPPError): """IPP response exception.""" pass + + +class IPPVersionNotSupportedError(IPPError) + """IPP version not supported.""" + + pass From 5a1c56ba4bfcf026c6c4771fddb0a0401b229c8a Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:14:17 -0500 Subject: [PATCH 08/11] Update exceptions.py --- pyipp/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyipp/exceptions.py b/pyipp/exceptions.py index c4ace9271..053b56d91 100644 --- a/pyipp/exceptions.py +++ b/pyipp/exceptions.py @@ -31,7 +31,7 @@ class IPPResponseError(IPPError): pass -class IPPVersionNotSupportedError(IPPError) +class IPPVersionNotSupportedError(IPPError): """IPP version not supported.""" pass From 0b5d7faaa2752bdfc913fb34348a6a924f2115cc Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:18:48 -0500 Subject: [PATCH 09/11] Update ipp.py --- pyipp/ipp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyipp/ipp.py b/pyipp/ipp.py index 970fdd231..d815b2b43 100644 --- a/pyipp/ipp.py +++ b/pyipp/ipp.py @@ -182,7 +182,7 @@ async def execute(self, operation: IppOperation, message: dict) -> dict: raise IPPParseError from exc if parsed["status-code"] == IppStatus.ERROR_VERSION_NOT_SUPPORTED: - raise IPPVersionNotSupported("IPP version not supported by server") + raise IPPVersionNotSupportedError("IPP version not supported by server") elif parsed["status-code"] != IppStatus.OK: raise IPPError( "Unexpected printer status code", From d9f1682eda3ea0301c61f9cc8bab291b34c4eeca Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:22:48 -0500 Subject: [PATCH 10/11] Update parser.py --- pyipp/parser.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pyipp/parser.py b/pyipp/parser.py index 348b0d368..ff9aafcd5 100644 --- a/pyipp/parser.py +++ b/pyipp/parser.py @@ -3,13 +3,7 @@ import struct from typing import Any, Dict, Tuple, cast -from .enums import ( - IppDocumentState, - IppJobState, - IppPrinterState, - IppStatus, - IppTag, -) +from .enums import IppDocumentState, IppJobState, IppPrinterState, IppStatus, IppTag _LOGGER = logging.getLogger(__name__) From 618ee757b1c8ab38b977c3f4ac48656982b4e5b2 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 20:24:45 -0500 Subject: [PATCH 11/11] Update ipp.py --- pyipp/ipp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyipp/ipp.py b/pyipp/ipp.py index d815b2b43..66434acc2 100644 --- a/pyipp/ipp.py +++ b/pyipp/ipp.py @@ -183,7 +183,8 @@ async def execute(self, operation: IppOperation, message: dict) -> dict: if parsed["status-code"] == IppStatus.ERROR_VERSION_NOT_SUPPORTED: raise IPPVersionNotSupportedError("IPP version not supported by server") - elif parsed["status-code"] != IppStatus.OK: + + if parsed["status-code"] != IppStatus.OK: raise IPPError( "Unexpected printer status code", {"status-code": parsed["status-code"]},