Changeset 7bd1035


Ignore:
Timestamp:
Dec 19, 2011, 12:03:56 AM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
738d179
Parents:
0ede474
git-author:
Jessica B. Hamrick <jhamrick@…> (12/19/11 00:03:56)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/19/11 00:03:56)
Message:

Move actual server code out of server/requests.py and into server/server.py

Location:
server/lib/gutenbach
Files:
1 added
3 edited

Legend:

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

    r9eeab06 r7bd1035  
    238238
    239239    def __repr__(self):
    240         val = '<IPPRequest (version=%r, ' % self.version
     240        val = '<IPPRequest (version=%r, ' % [self.version]
    241241        val += 'operation_id=%x, ' % self.operation_id
    242242        val += 'request_id=%r, ' % self.request_id
  • server/lib/gutenbach/server/__init__.py

    rb2e077a r7bd1035  
    1 from requests import GutenbachIPPServer
     1from server import GutenbachIPPServer
    22import BaseHTTPServer
    33import logging
    44
    55# configure logging
    6 logging.basicConfig(level=logging.DEBUG)
     6logging.basicConfig(level=logging.INFO)
    77
    88def start():
  • server/lib/gutenbach/server/requests.py

    r0ede474 r7bd1035  
    1 import BaseHTTPServer
    21import gutenbach.ipp as ipp
    32import gutenbach.ipp.constants as const
     
    4241        # call the handler
    4342        handler = getattr(self, handler_name)
    44         logger.debug("Sending request to handler '%s'" % handler_name)
     43        logger.info("Handling request of type '%s'" % handler_name)
    4544        handler(request, response)
    4645
     
    105104        for job in self.printers[printer_name].get_jobs():
    106105            self._get_job_attributes(job, request, response)
    107         response.operation_id = const.StatusCodes.OK
    108106
    109107    def print_uri(self, request, response):
     
    125123        printer_name = self._get_printer_name(request)
    126124        self._get_printer_attributes(self.printers[printer_name], request, response)
    127         response.operation_id = const.StatusCodes.OK
    128125
    129126    def set_printer_attributes(self, request, response):
     
    209206           
    210207        self._get_printer_attributes(self.printers[self.default], request, response)
    211         response.operation_id = const.StatusCodes.OK
    212208
    213209    @handler_for(const.Operations.CUPS_GET_PRINTERS)
     
    282278        for printer in self.printers:
    283279            self._get_printer_attributes(self.printers[printer], request, response)
    284         response.operation_id = const.StatusCodes.OK
    285280
    286281    @handler_for(const.Operations.CUPS_GET_CLASSES)
     
    354349       
    355350        # We have no printer classes, so we don't need to do anything
    356         response.operation_id = const.StatusCodes.OK
    357 
    358 class GutenbachIPPServer(BaseHTTPServer.BaseHTTPRequestHandler):
    359     def setup(self):
    360         self.root = GutenbachRequestHandler()
    361         BaseHTTPServer.BaseHTTPRequestHandler.setup(self)
    362 
    363     def handle_one_request(self):
    364         self.raw_requestline = self.rfile.readline()
    365         if not self.raw_requestline:
    366             self.close_connection = 1
    367             return
    368         if not self.parse_request(): # An error code has been sent, just exit
    369             return
    370         self.handle_ipp()
    371 
    372     def handle_ipp(self):
    373         # Receive a request
    374         length = int(self.headers.getheader('content-length', 0))
    375         request = ipp.Request(request=self.rfile, length=length)
    376         logger.debug("Received request: %s" % repr(request))
    377 
    378         # Operation attributes -- typically the same for any request
    379         attributes = [
    380             ipp.Attribute(
    381                 'attributes-charset',
    382                 [ipp.Value(ipp.Tags.CHARSET, 'utf-8')]),
    383             ipp.Attribute(
    384                 'attributes-natural-language',
    385                 [ipp.Value(ipp.Tags.NATURAL_LANGUAGE, 'en-us')])
    386             ]
    387         # Put the operation attributes in a group
    388         attribute_group = ipp.AttributeGroup(
    389             const.AttributeTags.OPERATION,
    390             attributes)
    391 
    392         # Set up the default response -- handlers will override these
    393         # values if they need to
    394         response_kwargs = {}
    395         response_kwargs['version']          = request.version
    396         response_kwargs['operation_id']     = const.StatusCodes.INTERNAL_ERROR
    397         response_kwargs['request_id']       = request.request_id
    398         response_kwargs['attribute_groups'] = [attribute_group]
    399         response = ipp.Request(**response_kwargs)
    400 
    401         # Get the handler and pass it the request and response objects
    402         self.root.handle(request, response)
    403         logger.debug("Sending response: %s" % repr(response))
    404 
    405         # Send the response across HTTP
    406         self.send_response(200, "Gutenbach IPP Response")
    407         self.send_header("Content-Type", "application/ipp")
    408         self.send_header("Connection", "close")
    409         self.end_headers()
    410         self.wfile.write(response.packed_value)
     351        pass
Note: See TracChangeset for help on using the changeset viewer.