Skip to content

Expose contains_data parameter on ipp.execute #675

@ll3006

Description

@ll3006

Problem

Say I want to run a request that returns some data, e.g CUPS_Get_Document:

response = ipp.execute(
	IppOperation.CUPS_GET_DOCUMENT,
	  {
	      "operation-attributes-tag": {
	          "job-id": 1,
	          "document-number": 1,
	          "requesting-user-name": "root",
	      }
	  }
)

The response gets parsed but has on "data" field, even if it's been recieved. This is because the ipp.parser.parse function inside ipp.execute gets called without the contains_data parameter.

python-ipp/src/pyipp/ipp.py

Lines 195 to 198 in 3b560f2

try:
parsed = parse_response(response)
except (structerror, Exception) as exc: # disable=broad-except
raise IPPParseError from exc

def parse( # noqa: PLR0912, PLR0915
raw_data: bytes,
contains_data: bool = False, # noqa: FBT001, FBT002
) -> dict[str, Any]:

Current alternative approach

The only way around this is to manually parse the request, like this

from pyipp.parser import parse as parse_response

response = await ipp.raw(
    IppOperation.CUPS_GET_DOCUMENT,
    {
        "operation-attributes-tag": {
            "job-id": 1,
            "document-number": 1,
            "requesting-user-name": "root",
        }
    },
)
response = parse_response(response, contains_data=True)

Which works, but is harder than it needs to be

Proposal

How about exposing the contains_data parameter on ipp.execute? This way we can do something like

response = await ipp.execute(
    IppOperation.CUPS_GET_DOCUMENT,
    {
        "operation-attributes-tag": {
            "job-id": 1,
            "document-number": 1,
            "requesting-user-name": "root",
        }
    },
    contains_data=True,
)

To get the parsed data back

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions