Changeset c5e88d0


Ignore:
Timestamp:
Mar 5, 2011, 7:14:21 PM (13 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
16055f9
Parents:
574aee4
git-author:
Jessica B. Hamrick <jhamrick@…> (03/05/11 19:14:21)
git-committer:
Jessica B. Hamrick <jhamrick@…> (03/05/11 19:14:21)
Message:

get-jobs response in GutenbachIPPserver

Location:
server/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/lib/ipprequest.py

    r89fe6da rc5e88d0  
    6969    """
    7070
    71     def __init__(self, value_tag, value):
     71    def __init__(self, value_tag, value, unpack=True):
    7272        """
    7373        Initialize an IPPValue:
     
    8787        self.value_tag = value_tag
    8888        self.value = value
     89
     90        if not unpack: return
    8991
    9092        # out-of-band value tags
     
    378380        self.attributes = attributes
    379381
     382    def getAttribute(self, name):
     383        return filter(lambda x: x.name == name, self.attributes)
     384
    380385    def toBinaryData(self):
    381386        """
     
    462467            # make sure attribute_groups is a list of IPPAttributes
    463468            assert len(attribute_groups) > 0
    464             for a in attribute_groups: assert isinstance(a, IPPAttribute)
     469            for a in attribute_groups: assert isinstance(a, IPPAttributeGroup)
    465470           
    466471        # if the request isn't None, then we'll read directly from
     
    575580            self.data = data
    576581
     582    def getAttributeGroup(self, tag):
     583        return filter(lambda x: x.attribute_group_tag == tag,
     584                      self.attribute_groups)
     585
    577586    def toBinaryData(self):
    578587        """
  • server/lib/server.py

    r89fe6da rc5e88d0  
    22
    33import logging, BaseHTTPServer
    4 import ipprequest
     4from ipprequest import *
     5import ippconstants as const
    56
    67logging.basicConfig(level=logging.DEBUG)
     
    1718
    1819    def handle_ipp(self):
    19         req = ipprequest.IPPRequest(request=self.rfile,
    20                                     length=self.headers.getheader('content-length', 0))
     20        length = int(self.headers.getheader('content-length', 0))
     21        request = IPPRequest(request=self.rfile,
     22                             length=length)
     23
     24        response_kwargs = {}
     25        response_kwargs['version'] = request.version
     26        response_kwargs['request_id'] = request.request_id
     27        response_kwargs = self.get_jobs(request, response_kwargs)
     28        response = IPPRequest(**response_kwargs)
    2129
    2230        self.send_response(200, "o hai")
    23         self.send_header("Content-Type", "text/plain")
     31        self.send_header("Content-Type", "application/ipp")
    2432        self.send_header("Connection", "close")
    2533        self.end_headers()
    26         self.wfile.write("I got ur request")
     34        self.wfile.write(response.toBinaryData())
     35
     36    def get_jobs(self, request, response_kwargs):
     37        """get-jobs response"""
     38
     39        job_attributes = [IPPAttribute('job-id',
     40                                       [IPPValue(IPPTags.INTEGER,
     41                                                 12345,
     42                                                 unpack=False)]),
     43                          IPPAttribute('job-name',
     44                                       [IPPValue(IPPTags.NAME_WITHOUT_LANGUAGE,
     45                                                 'foo',
     46                                                 unpack=False)]),
     47                          IPPAttribute('job-originating-user-name',
     48                                       [IPPValue(IPPTags.NAME_WITHOUT_LANGUAGE,
     49                                                 'jhamrick',
     50                                                 unpack=False)]),
     51                          IPPAttribute('job-k-octets',
     52                                       [IPPValue(IPPTags.INTEGER,
     53                                                 1,
     54                                                 unpack=False)]),
     55                          IPPAttribute('job-state',
     56                                       [IPPValue(IPPTags.ENUM,
     57                                                 const.IPP_JOB_HELD,
     58                                                 unpack=False)]),
     59                          IPPAttribute('job-printer-uri',
     60                                       [IPPValue(IPPTags.URI,
     61                                                 'http://localhost:8000/printers/foo',
     62                                                 unpack=False)])]
     63
     64
     65        #req_op_attributes = request.getAttributeGroup(IPPTags.OPERATION_ATTRIBUTES_TAG)
     66        #print req_op_attributes
     67        #printer_uri = req_op_attributes[0].getAttribute('printer-uri')
     68
     69        op_attributes = [IPPAttribute('attributes-charset',
     70                                      [IPPValue(IPPTags.CHARSET,
     71                                                'utf-8',
     72                                                unpack=False)]),
     73                         IPPAttribute('attributes-natural-language',
     74                                      [IPPValue(IPPTags.NATURAL_LANGUAGE,
     75                                                'en-us',
     76                                                unpack=False)])]
     77       
     78        job_attribute_group = IPPAttributeGroup(IPPTags.JOB_ATTRIBUTES_TAG,
     79                                                job_attributes)
     80        op_attributes_group = IPPAttributeGroup(IPPTags.OPERATION_ATTRIBUTES_TAG,
     81                                                op_attributes)
     82        response_kwargs['attribute_groups'] = [op_attributes_group,job_attribute_group]
     83        response_kwargs['operation_id'] = const.IPP_OK
     84
     85        return response_kwargs
    2786
    2887if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.