Skip to content

modeling: Python hooks for IPP requests/responses (like the eSCL ones) #141

Backlog

Description

@atharrva01

@alexpevzner I'd like to work on the // Load IPP hooks // TODO in modeling/ipp.go and wanted to check the approach with you before writing any code.

Why

Static model attributes can't express a lot of real device quirks. A few from ipp-usb's quirks database:

What I'd add

def ipp_onIPPRequest(q: query.Query, msg: ipp.MESSAGE): ...
def ipp_onIPPResponse(q: query.Query, rq: ipp.MESSAGE, rsp: ipp.MESSAGE): ...

ipp.MESSAGE would have version, code, request_id and an ordered list of ipp.GROUPs. Each group works like COLLECTION, plus add() for duplicate names, and the list keeps repeated job groups. I'd also add an ipp.STATUS enum and an ipp.Reject(status, msg) exception for the request hook.

Things I measured that shape the design

  1. Cost. Running a Get-Printer-Attributes reply through the existing converters takes about 300 ms for the Xerox B235 model and about 1.5 s for the HP M426fdn. A request takes about 1 ms. So I'd export requests fully, but treat replies as patches: the hook gets the header and operation group, other groups load only when the hook reads them, and Go applies only what changed to the original message. With no hook defined, ServerHooks stays nil, so it costs nothing.
  2. Fidelity. The converters lose three things: non-UTF-8 octetStrings (export fails), dateTime deciseconds, and duplicate attribute names. If the hook changes nothing, the original message goes out untouched, so it's byte-identical. I'd fix those three for when it does.
  3. Concurrency. Unlike eSCL, IPP requests run in parallel, so the wrappers keep no state on Model. I'd avoid a global lock so one slow hook doesn't block everything.

Faster, per-attribute loading would need argument support in cpython callbacks (the TODO in callback.go). I'd leave that to you as a separate change.

Plan

Following your advice on #139, I'd start with tests, in two PRs:

  1. Converter fixes, plus tests showing the round trip is byte-identical.
  2. The hooks: a no-op hook gives an identical reply, plus a status-rewrite test, an exception test, a parallel-requests test with -race, and an end-to-end check with mfp-virtual and ipptool.

Does this sound right to you? I'm especially unsure about the API names and the lazy reply groups.

Activity

  1. atharrva01 commented on Nov 25, 2026

    @atharrva01
    ContributorAuthor

    Hi @alexpevzner , can u please take a look at this , whenever u have a chance
    Thanks...

  2. alexpevzner commented on Nov 26, 2026

    @alexpevzner
    Member

    Hi!

    These hooks are planned, but not implemented yet.

    I think I'll refactor eSCL hooks a little bit to be more Python-idiomatic before implementing IPP/WSD hooks.

    For example, there should be a method to cancel HTTP query from the Python hook, returning the appropriate HTTP status, not only 503, as now. Looks like throwing Python exception is the most natural method to express it at the Python side.

    The result should be simple, convenient and idiomatic at the Python side. Otherwise, nobody will use this functionality.

    Regarding simulation of delays, lets put it at the end. This is rarely required and in most cases will be annoying, so I think when delays will be implemented, there are should be playback modes "time-accurate (with delays)" and "ignore delays", and the second mode should be default

    I'm open to any ideas here, but please discuss them first, before implementing, and concentrating on the usage convenience

  3. atharrva01 commented on Nov 26, 2026

    @atharrva01
    ContributorAuthor

    @alexpevzner , do we have any communication channel, where we can discuss about this?

  4. alexpevzner commented on Nov 26, 2026

    @alexpevzner
    Member

    Yes, Telegram: @a_pevzner

  5. atharrva01 commented on Nov 26, 2026

    @atharrva01
    ContributorAuthor

    i tried reahng out to you on 23rd on this ID, but i think i didnt get through

  6. alexpevzner commented on Nov 26, 2026

    @alexpevzner
    Member

    I'm here. Just not always respond quickly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions