Changeset aef164a


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

Location:
server/lib/gutenbach
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/ipp/operations.py

    r59a1d4a raef164a  
    1 from .value import Value
    21from .attribute import Attribute
    32from .attributegroup import AttributeGroup
    43from .request import Request
     4from .value import Value
    55import constants as consts
    66import exceptions as err
  • 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
  • server/lib/gutenbach/server/server.py

    ref8df33 raef164a  
    33import gutenbach.ipp as ipp
    44import logging
     5import sys
    56import traceback
    6 import sys
    77
    88# initialize logger
     
    2727        length = int(self.headers.getheader('content-length', 0))
    2828        request = ipp.Request(request=self.rfile, length=length)
    29         logger.debug("Received request: %s" % repr(request))
    3029
    3130        # Get the handler and pass it the request and response
    3231        # objects.  It will fill in values for the response object or
    33         # thrown an error.
     32        # throw a fatal error.
     33        logger.debug("Received request: %s" % repr(request))
    3434        try:
    3535            response = self.root.handle(request)
    36            
    37         # Handle any errors that occur.  If an exception occurs that
    38         # is an IPP error, then we can get the error code from the
    39         # exception itself.
    40         except ipp.errors.IPPException:
    41             exctype, excval, exctb = sys.exc_info()
    42             logger.error(traceback.format_exc())
    43             response = ipp.ops.make_empty_response(request)
    44             excval.update_response(response)
    45 
    46         # If it wasn't an IPP error, then it's our fault, so mark it
    47         # as an internal server error
    48         except Exception:
    49             logger.error(traceback.format_exc())
    50             response = ipp.ops.make_empty_response(request)
    51             response.operation_id = ipp.StatusCodes.INTERNAL_ERROR
     36        except:
     37            logger.fatal(traceback.format_exc())
     38            sys.exit(1)
    5239
    5340        # Send the response across HTTP
Note: See TracChangeset for help on using the changeset viewer.