Changeset dc40fe9


Ignore:
Timestamp:
Dec 20, 2011, 11:56:11 AM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
cf32fee
Parents:
5b3a81e
git-author:
Jessica B. Hamrick <jhamrick@…> (12/20/11 11:56:11)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/20/11 11:56:11)
Message:

Update server/server.py to leave IPP object construction to ipp/operations or ipp/exceptions

File:
1 edited

Legend:

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

    rc70a3c9 rdc40fe9  
    22import BaseHTTPServer
    33import gutenbach.ipp as ipp
    4 import gutenbach.ipp.constants as const
    54import logging
    65import traceback
     6import sys
    77
    88# initialize logger
     
    2929        logger.debug("Received request: %s" % repr(request))
    3030
    31         # Operation attributes -- typically the same for any request
    32         attributes = [
    33             ipp.Attribute(
    34                 'attributes-charset',
    35                 [ipp.Value(ipp.Tags.CHARSET, 'utf-8')]),
    36             ipp.Attribute(
    37                 'attributes-natural-language',
    38                 [ipp.Value(ipp.Tags.NATURAL_LANGUAGE, 'en-us')])
    39             ]
    40         # Put the operation attributes in a group
    41         attribute_group = ipp.AttributeGroup(
    42             const.AttributeTags.OPERATION,
    43             attributes)
     31        # Create an empty response object
     32        response = ipp.ops.make_empty_response(request)
    4433
    45         # Set up the default response -- handlers will override these
    46         # values if they need to
    47         response_kwargs = {}
    48         response_kwargs['version']          = request.version
    49         response_kwargs['operation_id']     = const.StatusCodes.OK
    50         response_kwargs['request_id']       = request.request_id
    51         response_kwargs['attribute_groups'] = [attribute_group]
    52         response = ipp.Request(**response_kwargs)
    53 
    54         # Get the handler and pass it the request and response objects
     34        # Get the handler and pass it the request and response
     35        # objects.  It will fill in values for the response object or
     36        # thrown an error.
    5537        try:
    5638            self.root.handle(request, response)
    57         except:
    58             response.operation_id = const.StatusCodes.INTERNAL_ERROR
     39           
     40        # Handle any errors that occur.  If an exception occurs that
     41        # is an IPP error, then we can get the error code from the
     42        # exception itself.
     43        except IPPException:
     44            exctype, excval, exctb = sys.exc_info()
     45            excval.update_response(response)
     46            logger.error(traceback.format_exc())
     47
     48        # If it wasn't an IPP error, then it's our fault, so mark it
     49        # as an internal server error
     50        except Exception:
     51            response.operation_id = const.ErrorCodes.INTERNAL_ERROR
    5952            logger.error(traceback.format_exc())
    6053
Note: See TracChangeset for help on using the changeset viewer.