Changeset 079ef11 for server


Ignore:
Timestamp:
Jan 21, 2012, 8:57:40 PM (12 years ago)
Author:
Daniel Cooper <danny@…>
Branches:
no-cups
Children:
b77e57e
Parents:
6c60b2e
git-author:
Daniel Cooper <danny@…> (01/21/12 20:57:40)
git-committer:
Daniel Cooper <danny@…> (01/21/12 20:57:40)
Message:

wrote print_job/print_uri

File:
1 edited

Legend:

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

    r6c60b2e r079ef11  
    125125    @handler_for(ipp.OperationCodes.PRINT_JOB)
    126126    def print_job(self, request, response):
    127             """RFC 2911: 3.2.1 Print-Job Operation
     127        """RFC 2911: 3.2.1 Print-Job Operation
    128128
    129129        This REQUIRED operation allows a client to submit a print job
     
    170170        """
    171171        operation = request.attribute_groups[0]
     172        document = request.data       
     173        user_name = None
     174        job_name = None
     175        job_k_octets = None
     176        document_format = None
     177        document_natural_language = None
     178        compression = None
     179        last_document = None
     180
     181
    172182        # requested printer uri
    173183        if 'printer-uri' not in operation:
     
    198208
    199209        # get attributes from the printer and add to response
    200         job_id = self.printer.create_job(
    201             requesting_user_name=user_name,
    202             job_name=job_name,
    203             job_k_octets=job_k_octets)
     210        try:
     211            job_id = self.printer.print_job(document,
     212                    document_name               = document_name,
     213                    document_format             = document_format,
     214                    document_natural_language   = document_natural_language,
     215                    requesting_user_name        = user_name,
     216                    compression                 = compression,
     217                    job_name                    = job_name,
     218                    job_k_octets                = job_k_octets)
     219        except InvalidJobException:
     220            raise ipp.errors.ClientErrorNotFound("bad job: %d" % job_id)
     221
     222
    204223        attrs = self.printer.get_job_attributes(job_id)
     224     
     225        #Actually append the attributes we pulled
    205226        response.attribute_groups.append(ipp.AttributeGroup(
    206227            ipp.AttributeTags.JOB, attrs))
    207             #raise ipp.errors.ServerErrorOperationNotSupported
    208         # Get nescessary information for calling send_document
    209         # Any field being set to None here just means that we either aren't using or haven't implemented parsing it
    210         document = request.data       
    211         #XXX
    212         document_format = None
    213         document_natural_language = None
    214         compression = None
    215         last_document = None
    216 
    217228
    218229       
    219         # Actually put the document in the job
    220         try:
    221             self.printer.send_document(job_id,document,
    222                     document_name = document_name,
    223                     document_format = document_format,
    224                     document_natural_language = document_natural_language,
    225                     requesting_user_name = requesting_user_name,
    226                     compression = compression,
    227                     last_document = last_document)
    228         except InvalidJobException:
    229             raise ipp.errors.ClientErrorNotFound("bad job: %d" % job_id)
    230 
    231        
    232         # Print the job, now that we've filled it in as appropriate
    233        
    234        #XXX
    235        #Should we be handling a possible exception here?
    236         self.print_job(document,
    237                 document_name = document_name,
    238                 document_format = document_format,
    239                 document_natural_language = document_natural_language,
    240                 requesting_user_name = requesting_user_name,
    241                 compression=compression,
    242                 job_name = job_name,
    243                 job_k_octets = job_k_octets)
    244 
    245         attrs = self.printer.get_job_attributes(job_id)
    246         response.attribute_groups.append(ipp.AttributeGroup(ipp.AttributeTags.JOB, attrs))
    247 
    248230    @handler_for(ipp.OperationCodes.VALIDATE_JOB)
    249231    def validate_job(self, request, response):
    250 
    251         raise ipp.errors.ServerErrorOperationNotSupported
     232        """3.2.3 Validate-Job Operation
     233
     234        This REQUIRED operation is similar to the Print-Job operation
     235        (section 3.2.1) except that a client supplies no document data and
     236        the Printer allocates no resources (i.e., it does not create a new
     237        Job object).  This operation is used only to verify capabilities of a
     238        printer object against whatever attributes are supplied by the client
     239        in the Validate-Job request.  By using the Validate-Job operation a
     240        client can validate that an identical Print-Job operation (with the
     241        document data) would be accepted. The Validate-Job operation also
     242        performs the same security negotiation as the Print-Job operation
     243        (see section 8), so that a client can check that the client and
     244        Printer object security requirements can be met before performing a
     245        Print-Job operation.
     246
     247        The Validate-Job operation does not accept a 'document-uri' attribute
     248        in order to allow a client to check that the same Print-URI operation
     249        will be accepted, since the client doesn't send the data with the
     250        Print-URI operation.  The client SHOULD just issue the Print-URI
     251        request.
     252
     253        The Printer object returns the same status codes, Operation
     254        Attributes (Group 1) and Unsupported Attributes (Group 2) as the
     255        Print-Job operation.  However, no Job Object Attributes (Group 3) are
     256        returned, since no Job object is created.
     257        """
     258        operation = request.attribute_groups[0]
     259        user_name = None
     260        job_name = None
     261        job_k_octets = None
     262        # requested printer uri
     263        if 'printer-uri' not in operation:
     264            raise ipp.errors.ClientErrorBadRequest("Missing 'printer-uri' attribute")
     265        printer_uri = verify_attribute(operation['printer-uri'], ipp.PrinterUri)[0]
     266        if printer_uri not in self.printer.uris:
     267            raise ipp.errors.ClientErrorAttributes(
     268                str(operation['printer-uri']), operation['printer-uri'])
     269
     270        if 'requesting-user-name' in operation:
     271            user_name = verify_attribute(
     272                operation['requesting-user-name'], ipp.RequestingUserName)[0]
     273
     274        if 'job-name' in operation:
     275            job_name = verify_attribute(
     276                operation['job-name'], ipp.JobName)[0]
     277
     278        if 'job-k-octets' in operation:
     279            job_k_octets = verify_attribute(
     280                operation['job-k-octets'], ipp.JobKOctets)[0]
     281       
     282        self.printer.verify_job(requesting_user_name=user_name,
     283            job_name=job_name,
     284            job_k_octets = job_k_octets)
     285
     286        #raise ipp.errors.ServerErrorOperationNotSupported
    252287
    253288    @handler_for(ipp.OperationCodes.GET_JOBS)
     
    377412        It is up to the IPP object to interpret the URI and subsequently
    378413        'pull' the document from the source referenced by the URI string."""
    379         raise ipp.errors.ServerErrorOperationNotSupported
     414        operation = request.attribute_groups[0]
     415        document = request.data       
     416        user_name = None
     417        job_name = None
     418        job_k_octets = None
     419        document_format = None
     420        document_natural_language = None
     421        compression = None
     422        last_document = None
     423
     424
     425        # requested printer uri
     426        if 'printer-uri' not in operation:
     427            raise ipp.errors.ClientErrorBadRequest("Missing 'printer-uri' attribute")
     428        printer_uri = verify_attribute(operation['printer-uri'], ipp.PrinterUri)[0]
     429        if printer_uri not in self.printer.uris:
     430            raise ipp.errors.ClientErrorAttributes(
     431                str(operation['printer-uri']), operation['printer-uri'])
     432
     433        if 'requesting-user-name' in operation:
     434            user_name = verify_attribute(
     435                operation['requesting-user-name'], ipp.RequestingUserName)[0]
     436
     437        if 'job-name' in operation:
     438            job_name = verify_attribute(
     439                operation['job-name'], ipp.JobName)[0]
     440
     441        if 'job-k-octets' in operation:
     442            job_k_octets = verify_attribute(
     443                operation['job-k-octets'], ipp.JobKOctets)[0]
     444
     445        if 'ipp-attribute-fidelity' in operation:
     446            pass # don't care
     447        if 'job-impressions' in operation:
     448            pass # don't care
     449        if 'job-media-sheets' in operation:
     450            pass # don't care
     451
     452        # get attributes from the printer and add to response
     453        try:
     454            job_id = self.printer.print_uri(document,
     455                    document_name               = document_name,
     456                    document_format             = document_format,
     457                    document_natural_language   = document_natural_language,
     458                    requesting_user_name        = user_name,
     459                    compression                 = compression,
     460                    job_name                    = job_name,
     461                    job_k_octets                = job_k_octets)
     462        except InvalidJobException:
     463            raise ipp.errors.ClientErrorNotFound("bad job: %d" % job_id)
     464
     465
     466        attrs = self.printer.get_job_attributes(job_id)
     467     
     468        #Actually append the attributes we pulled
     469        response.attribute_groups.append(ipp.AttributeGroup(
     470            ipp.AttributeTags.JOB, attrs))
     471
     472 
     473       #raise ipp.errors.ServerErrorOperationNotSupported
    380474
    381475    @handler_for(ipp.OperationCodes.CREATE_JOB)
Note: See TracChangeset for help on using the changeset viewer.