Skip to content

Commit

Permalink
Support appending pre-encoded data when serializing (#510)
Browse files Browse the repository at this point in the history
* add print_job data

* Apply suggestions from code review

---------

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
  • Loading branch information
dellorogiulio and ctalkington authored May 18, 2024
1 parent e626e4e commit 2bfeafa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/print_example.py
Original file line number Diff line number Diff line change
@@ -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())
3 changes: 3 additions & 0 deletions src/pyipp/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2bfeafa

Please sign in to comment.