Changeset 7bd1035
- Timestamp:
- Dec 19, 2011, 12:03:56 AM (12 years ago)
- 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)
- Location:
- server/lib/gutenbach
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/request.py
r9eeab06 r7bd1035 238 238 239 239 def __repr__(self): 240 val = '<IPPRequest (version=%r, ' % self.version240 val = '<IPPRequest (version=%r, ' % [self.version] 241 241 val += 'operation_id=%x, ' % self.operation_id 242 242 val += 'request_id=%r, ' % self.request_id -
server/lib/gutenbach/server/__init__.py
rb2e077a r7bd1035 1 from requestsimport GutenbachIPPServer1 from server import GutenbachIPPServer 2 2 import BaseHTTPServer 3 3 import logging 4 4 5 5 # configure logging 6 logging.basicConfig(level=logging. DEBUG)6 logging.basicConfig(level=logging.INFO) 7 7 8 8 def start(): -
server/lib/gutenbach/server/requests.py
r0ede474 r7bd1035 1 import BaseHTTPServer2 1 import gutenbach.ipp as ipp 3 2 import gutenbach.ipp.constants as const … … 42 41 # call the handler 43 42 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) 45 44 handler(request, response) 46 45 … … 105 104 for job in self.printers[printer_name].get_jobs(): 106 105 self._get_job_attributes(job, request, response) 107 response.operation_id = const.StatusCodes.OK108 106 109 107 def print_uri(self, request, response): … … 125 123 printer_name = self._get_printer_name(request) 126 124 self._get_printer_attributes(self.printers[printer_name], request, response) 127 response.operation_id = const.StatusCodes.OK128 125 129 126 def set_printer_attributes(self, request, response): … … 209 206 210 207 self._get_printer_attributes(self.printers[self.default], request, response) 211 response.operation_id = const.StatusCodes.OK212 208 213 209 @handler_for(const.Operations.CUPS_GET_PRINTERS) … … 282 278 for printer in self.printers: 283 279 self._get_printer_attributes(self.printers[printer], request, response) 284 response.operation_id = const.StatusCodes.OK285 280 286 281 @handler_for(const.Operations.CUPS_GET_CLASSES) … … 354 349 355 350 # 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.