Ignore:
Timestamp:
Dec 27, 2011, 7:03:46 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
7c143c9
Parents:
1037115
git-author:
Jessica B. Hamrick <jhamrick@…> (12/27/11 19:03:46)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/27/11 19:03:46)
Message:

Fix error with HTTP server recreating printer objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/server/requests.py

    r1037115 ree8e6d0  
    4141
    4242    def __init__(self):
     43        print "init"
    4344        self.printers = {
    4445            "test": GutenbachPrinter(name="test")
     
    227228        jobs = self.printers[printer_name].get_jobs()
    228229
    229         # requesting username
    230         if 'requesting-user-name' in operation:
    231             username_attr = operation['requesting-user-name']
    232             username = username_attr.values[0].value
    233             if username_attr != ipp.RequestingUserName(username):
    234                 raise ipp.errors.ClientErrorBadRequest(str(username_attr))
    235 
    236230        # get the job attributes and add them to the response
    237231        for job in self.printers[printer_name].get_jobs():
    238             attrs = job.get_job_attributes(request)
     232            attrs = job.get_job_attributes(operation)
    239233            response.attribute_groups.append(ipp.AttributeGroup(
    240234                ipp.AttributeTags.JOB, attrs))
     
    260254        in the multi-document Job object.
    261255
    262         Group 1: Operation Attributes
     256        Request
     257        -------
     258        Group 1: Operation Attributes
     259            REQUIRED 'attributes-charset'
     260            REQUIRED 'attributes-natural-language'
     261            REQUIRED 'printer-uri' (uri)
     262            OPTIONAL 'requesting-user-name' (name(MAX))
     263            OPTIONAL 'job-name' (name(MAX))
     264            OPTIONAL 'ipp-attribute-fidelity' (boolean)
     265            OPTIONAL 'job-k-octets' (integer(0:MAX))
     266            OPTIONAL 'job-impressions' (integer(0:MAX))
     267            OPTIONAL 'job-media-sheets' (integer(0:MAX))
     268        Group 2: Job Template Attributes
     269
     270        Response
     271        --------
     272        Group 1: Operation Attributes
     273            OPTIONAL 'status-message' (text(255))
     274            OPTIONAL 'detailed-status-message' (text(MAX))
     275            REQUIRED 'attributes-charset'
     276            REQUIRED 'attributes-natural-language'
     277        Group 2: Unsupported Attributes
     278        Group 3: Job Object Attributes
     279            REQUIRED 'job-uri' (uri)
     280            REQUIRED 'job-id' (integer(1:MAX))
     281            REQUIRED 'job-state' (type1 enum)
     282            REQUIRED 'job-state-reasons' (1setOf type2 keyword)
     283            OPTIONAL 'job-state-message' (text(MAX))
     284            OPTIONAL 'number-of-intervening-jobs' (integer(0:MAX))
    263285       
    264286        """
    265287
    266         raise ipp.errors.ServerErrorOperationNotSupported
     288
     289        operation = request.attribute_groups[0]
     290
     291        # requested printer uri
     292        if 'printer-uri' not in operation:
     293            raise ipp.errors.ClientErrorBadRequest("Missing 'printer-uri' attribute")
     294        uri_attr = operation['printer-uri']
     295        printer_name = uri_attr.values[0].value.split("/")[-1]
     296        if uri_attr != ipp.PrinterUri(uri_attr.values[0].value):
     297            raise ipp.errors.ClientErrorBadRequest(str(uri_attr))
     298        if printer_name not in self.printers:
     299            raise ipp.errors.ClientErrorAttributes(str(uri_attr), uri_attr)
     300
     301        # get attributes from the printer and add to response
     302        job = self.printers[printer_name].create_job(request)
     303        response.attribute_groups.append(ipp.AttributeGroup(
     304            ipp.AttributeTags.JOB, job.get_job_attributes(operation)))
    267305   
    268306    @handler_for(ipp.OperationCodes.PAUSE_PRINTER)
     
    296334            OPTIONAL 'requesting-user-name' (name(MAX))
    297335            OPTIONAL 'requested-attributes' (1setOf type2 keyword)
    298             OPTIONAL 'document-format' (mimeMediaType):
    299 
     336            OPTIONAL 'document-format' (mimeMediaType)
     337           
    300338        Response
    301339        --------
     
    324362        printer = self.printers[printer_name]
    325363
    326         # requesting username
    327         if 'requesting-user-name' in operation:
    328             username_attr = operation['requesting-user-name']
    329             username = username_attr.values[0].value
    330             if username_attr != ipp.RequestingUserName(username):
    331                 raise ipp.errors.ClientErrorBadRequest(str(username_attr))
    332 
    333364        # get attributes from the printer and add to response
    334365        response.attribute_groups.append(ipp.AttributeGroup(
    335             ipp.AttributeTags.PRINTER, printer.get_printer_attributes(request)))
     366            ipp.AttributeTags.PRINTER, printer.get_printer_attributes(operation)))
    336367
    337368    @handler_for(ipp.OperationCodes.SET_PRINTER_ATTRIBUTES)
     
    379410        job = printer.get_job(job_id)
    380411
    381         # requesting username
    382         if 'requesting-user-name' in operation:
    383             username_attr = operation['requesting-user-name']
    384             username = username_attr.values[0].value
    385             if username_attr != ipp.RequestingUserName(username):
    386                 raise ipp.errors.ClientErrorBadRequest(str(username_attr))
    387 
    388412        # get the job attributes and add them to the response
    389         attrs = job.get_job_attributes(request)
     413        attrs = job.get_job_attributes(operation)
    390414        response.attribute_groups.append(ipp.AttributeGroup(
    391415            ipp.AttributeTags.JOB, attrs))
     
    438462        printer = self.printers[self.default]
    439463
    440         # requesting username
    441         if 'requesting-user-name' in operation:
    442             username_attr = operation['requesting-user-name']
    443             username = username_attr.values[0].value
    444             if username_attr != ipp.RequestingUserName(username):
    445                 raise ipp.errors.ClientErrorBadRequest(str(username_attr))
    446 
    447464        # get attributes from the printer and add to response
    448465        response.attribute_groups.append(ipp.AttributeGroup(
    449             ipp.AttributeTags.PRINTER, printer.get_printer_attributes(request)))
     466            ipp.AttributeTags.PRINTER, printer.get_printer_attributes(operation)))
    450467
    451468    @handler_for(ipp.OperationCodes.CUPS_GET_PRINTERS)
     
    462479        operation = request.attribute_groups[0]
    463480
    464         # requesting username
    465         if 'requesting-user-name' in operation:
    466             username_attr = operation['requesting-user-name']
    467             username = username_attr.values[0].value
    468             if username_attr != ipp.RequestingUserName(username):
    469                 raise ipp.errors.ClientErrorBadRequest(str(username_attr))
    470 
    471481        # get attributes from the printer and add to response
    472482        for printer in self.printers.values():
    473483            response.attribute_groups.append(ipp.AttributeGroup(
    474                 ipp.AttributeTags.PRINTER, printer.get_printer_attributes(request)))
     484                ipp.AttributeTags.PRINTER, printer.get_printer_attributes(operation)))
    475485
    476486    @handler_for(ipp.OperationCodes.CUPS_GET_CLASSES)
Note: See TracChangeset for help on using the changeset viewer.