diff --git a/examples/print_example.py b/examples/print_example.py new file mode 100644 index 00000000..2f005559 --- /dev/null +++ b/examples/print_example.py @@ -0,0 +1,34 @@ +# pylint: disable=W0621 +"""Asynchronous Python client for IPP.""" +import asyncio + +from pyipp import IPP +from pyipp.enums import IppOperation + + +async def main() -> None: + + pdf_file = '/path/to/pdf.pfd' + with open(pdf_file, 'rb') as f: + content = f.read() + + """Show example of executing operation against your IPP print server.""" + async with IPP("ipp://192.168.1.92:631/ipp/print") as ipp: + response = await ipp.execute( + IppOperation.PRINT_JOB, + { + "operation-attributes-tag": { + "requesting-user-name": "Me", + "job-name": "My Test Job", + "document-format": "application/pdf", + }, + 'data': content, + }, + ) + + print(response) + + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/src/pyipp/serializer.py b/src/pyipp/serializer.py index e22311fd..3a9df1b6 100644 --- a/src/pyipp/serializer.py +++ b/src/pyipp/serializer.py @@ -93,4 +93,7 @@ def encode_dict(data: dict[str, Any]) -> bytes: encoded += struct.pack(">b", IppTag.END.value) + if "data" in data: + encoded += data["data"] + return encoded