Ignore:
Timestamp:
Dec 20, 2011, 3:24:01 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
5e44432
Parents:
59a1d4a
git-author:
Jessica B. Hamrick <jhamrick@…> (12/20/11 15:24:01)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/20/11 15:24:01)
Message:

Move ipp error handling out of the server and into server/requests

File:
1 edited

Legend:

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

    r59a1d4a raef164a  
    11from gutenbach.server.printer import GutenbachPrinter
    22import gutenbach.ipp as ipp
    3 import gutenbach.ipp.constants as const
     3import gutenbach.ipp.constants as consts
    44import logging
    55
     
    4141        handler = getattr(self, handler_name)
    4242        logger.info("Handling request of type '%s'" % handler_name)
    43         response = handler(request)
     43
     44        # Try to handle the request
     45        try:
     46            response = handler(request)
     47
     48        # Handle any errors that occur.  If an exception occurs that
     49        # is an IPP error, then we can get the error code from the
     50        # exception itself.
     51        except ipp.errors.IPPException:
     52            exctype, excval, exctb = sys.exc_info()
     53            logger.error(traceback.format_exc())
     54            response = ipp.ops.make_empty_response(request)
     55            excval.update_response(response)
     56
     57        # If it wasn't an IPP error, then it's our fault, so mark it
     58        # as an internal server error
     59        except Exception:
     60            logger.error(traceback.format_exc())
     61            response = ipp.ops.make_empty_response(request)
     62            response.operation_id = ipp.StatusCodes.INTERNAL_ERROR
     63
    4464        return response
    4565
     
    4767        logger.warning("Received unknown operation 0x%x" % request.operation_id)
    4868        response = ipp.ops.make_empty_response(request)
    49         response.operation_id = const.StatusCodes.OPERATION_NOT_SUPPORTED
     69        response.operation_id = consts.StatusCodes.OPERATION_NOT_SUPPORTED
    5070        return response
    5171       
     
    5878        pass
    5979
    60     @handler_for(const.Operations.GET_JOBS)
     80    @handler_for(consts.Operations.GET_JOBS)
    6181    def get_jobs(self, request):
    6282        """RFC 2911: 3.2.6 Get-Jobs Operation
     
    104124        pass
    105125
    106     @handler_for(const.Operations.GET_PRINTER_ATTRIBUTES)
     126    @handler_for(consts.Operations.GET_PRINTER_ATTRIBUTES)
    107127    def get_printer_attributes(self, request):
    108128        """RFC 2911: 3.2.5 Get-Printer-Attributes Operation
     
    217237    ##### CUPS Specific Commands
    218238
    219     @handler_for(const.Operations.CUPS_GET_DEFAULT)
     239    @handler_for(consts.Operations.CUPS_GET_DEFAULT)
    220240    def cups_get_default(self, request):
    221241        """The CUPS-Get-Default operation (0x4001) returns the default
     
    233253        return response
    234254
    235     @handler_for(const.Operations.CUPS_GET_PRINTERS)
     255    @handler_for(consts.Operations.CUPS_GET_PRINTERS)
    236256    def cups_get_printers(self, request):
    237257        """The CUPS-Get-Printers operation (0x4002) returns the
     
    253273        return response
    254274
    255     @handler_for(const.Operations.CUPS_GET_CLASSES)
     275    @handler_for(consts.Operations.CUPS_GET_CLASSES)
    256276    def cups_get_classes(self, request):
    257277        """The CUPS-Get-Classes operation (0x4005) returns the printer
Note: See TracChangeset for help on using the changeset viewer.