[cups.development] IPP + Python : comments and contributors welcome

Jerome Alet alet at librelogiciel.com
Tue Jun 14 02:14:47 PDT 2005


Hi there,

I've upgraded my Python module which can parse CUPS' IPP requests
files (of the form /var/spool/cups/c????? where ????? is the job id).

Now it can also generate such files with an easy interface, for
example :

--- CUT ---
def getJobs(queuename) :            
    """Just an example showing how to construct an IPP request from scratch."""
    msg = IPPRequest(version="1.1", operation_id=0x0a, request_id=1)
    msg.operation_attributes["attributes-charset"] = ('charset', 'iso-8859-15')
    msg.operation_attributes["attributes-natural-language"] = ('naturalLanguage', 'fr')
    msg.operation_attributes["printer-uri"] = ('uri', 'ipp://localhost:631/printers/%s' % queuename)
    # ... add more code here
    return msg.dump() # the result can be parsed again
--- CUT ---
    
in addition to the request parsing which it did before :    

--- CUT ---
def parseRequest(filename) :    
    """An example of IPP request parsing."""
    fp = open(filename, "rb")
    message = IPPRequest(fp.read())
    fp.close()
    message.parse()
    # print message.dump() # dumps an equivalent to the original IPP message
    # print str(message)   # returns a string of text with the same content as below
    print "IPP version : %s.%s" % message.version
    print "IPP operation Id : 0x%04x" % message.operation_id
    print "IPP request Id : 0x%08x" % message.request_id
    for attrtype in message.attributes_types :
        attrdict = getattr(message, "%s_attributes" % attrtype)
        if attrdict :
            print "%s attributes :" % attrtype.title()
            for key in attrdict.keys() :
                print "  %s : %s" % (key, attrdict[key])
    if message.data :            
        print "IPP datas : ", repr(message.data)            
--- CUT ---

The ultimate (distant) goal might be a 100% pure Python 
implementation of the CUPS' API, without having to link to the CUPS 
library. 

I've also added basic recognition for tags defined in RFCs post 2910.

People who want to try this can grab the (GPLed) module at :

  http://www.librelogiciel.com/software/ipp.py
  
Comments and contributions are more than welcome !  

bye

Jerome Alet





More information about the cups mailing list