Changeset e58af05 for server/lib/gutenbach/server/requests.py
- Timestamp:
- Dec 27, 2011, 11:33:55 PM (12 years ago)
- Branches:
- no-cups
- Children:
- ce2abc5
- Parents:
- 7c143c9
- git-author:
- Jessica B. Hamrick <jhamrick@…> (12/27/11 23:33:55)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (12/27/11 23:33:55)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/requests.py
r7c143c9 re58af05 1 from gutenbach.server.printer import GutenbachPrinter2 1 import gutenbach.ipp as ipp 3 2 import logging … … 40 39 class GutenbachRequestHandler(object): 41 40 42 def __init__(self): 43 self.printers = { 44 "test": GutenbachPrinter(name="test") 45 } 46 self.default = "test" 41 def __init__(self, gutenbach_server): 42 self.gutenbach_server = gutenbach_server 43 self.printer = gutenbach_server.printer 47 44 48 45 def generic_handle(self, request): … … 223 220 if uri_attr != ipp.PrinterUri(uri_attr.values[0].value): 224 221 raise ipp.errors.ClientErrorBadRequest(str(uri_attr)) 225 if printer_name not in self.printers:222 if printer_name != self.printer.name: 226 223 raise ipp.errors.ClientErrorAttributes(str(uri_attr), uri_attr) 227 jobs = self.printers[printer_name].get_jobs()228 224 229 225 # get the job attributes and add them to the response 230 for job in self.printer s[printer_name].get_jobs():226 for job in self.printer.get_jobs(): 231 227 attrs = job.get_job_attributes(operation) 232 228 response.attribute_groups.append(ipp.AttributeGroup( … … 295 291 if uri_attr != ipp.PrinterUri(uri_attr.values[0].value): 296 292 raise ipp.errors.ClientErrorBadRequest(str(uri_attr)) 297 if printer_name not in self.printers:293 if printer_name != self.printer.name: 298 294 raise ipp.errors.ClientErrorAttributes(str(uri_attr), uri_attr) 299 295 300 296 # get attributes from the printer and add to response 301 job = self.printer s[printer_name].create_job(request)297 job = self.printer.create_job(request) 302 298 response.attribute_groups.append(ipp.AttributeGroup( 303 299 ipp.AttributeTags.JOB, job.get_job_attributes(operation))) … … 357 353 if uri_attr != ipp.PrinterUri(uri_attr.values[0].value): 358 354 raise ipp.errors.ClientErrorBadRequest(str(uri_attr)) 359 if printer_name not in self.printers:355 if printer_name != self.printer.name: 360 356 raise ipp.errors.ClientErrorAttributes(str(uri_attr), uri_attr) 361 printer = self.printer s[printer_name]357 printer = self.printer 362 358 363 359 # get attributes from the printer and add to response … … 377 373 @handler_for(ipp.OperationCodes.SEND_DOCUMENT) 378 374 def send_document(self, request, response): 379 raise ipp.errors.ServerErrorOperationNotSupported 375 operation = request.attribute_groups[0] 376 377 # requested printer uri 378 if 'printer-uri' in operation: 379 uri_attr = operation['printer-uri'] 380 printer_name = uri_attr.values[0].value.split("/")[-1] 381 if uri_attr != ipp.PrinterUri(uri_attr.values[0].value): 382 raise ipp.errors.ClientErrorBadRequest(str(uri_attr)) 383 if printer_name != self.printer.name: 384 raise ipp.errors.ClientErrorAttributes(str(uri_attr), uri_attr) 385 printer = self.printer 386 387 if 'job-id' not in operation: 388 raise ipp.errors.ClientErrorBadRequest("Missing 'job-id' attribute") 389 job_id_attr = operation['job-id'] 390 job_id = job_id_attr.values[0].value 391 if job_id_attr != ipp.JobId(job_id_attr.values[0].value): 392 raise ipp.errors.ClientErrorBadRequest(str(job_id_attr)) 393 if job_id not in printer.jobs: 394 raise ipp.errors.ClientErrorAttributes(str(job_id_attr)) 395 job = printer.jobs[job_id] 396 397 if 'last-document' not in operation: 398 raise ipp.errors.ClientErrorBadRequest("Missing 'last-document' attribute") 399 last_attr = operation['last-document'] 400 last = last_attr.values[0].value 401 if last_attr != ipp.LastDocument(last): 402 raise ipp.errors.ClientErrorBadRequest(str(last_attr)) 403 if not last: 404 raise ipp.errors.ServerErrorMultipleJobsNotSupported 405 406 printer.send_document(job_id, request.data) 407 attrs = job.get_job_attributes() 408 response.attribute_groups.append(ipp.AttributeGroup( 409 ipp.AttributeTags.JOB, attrs)) 380 410 381 411 @handler_for(ipp.OperationCodes.SEND_URI) … … 385 415 @handler_for(ipp.OperationCodes.GET_JOB_ATTRIBUTES) 386 416 def get_job_attributes(self, request, response): 387 388 417 operation = request.attribute_groups[0] 389 418 … … 395 424 if uri_attr != ipp.PrinterUri(uri_attr.values[0].value): 396 425 raise ipp.errors.ClientErrorBadRequest(str(uri_attr)) 397 if printer_name not in self.printers:426 if printer_name != self.printer.name: 398 427 raise ipp.errors.ClientErrorAttributes(str(uri_attr), uri_attr) 399 printer = self.printer s[printer_name]428 printer = self.printer 400 429 401 430 if 'job-id' not in operation: … … 459 488 460 489 operation = request.attribute_groups[0] 461 printer = self.printer s[self.default]490 printer = self.printer 462 491 463 492 # get attributes from the printer and add to response … … 479 508 480 509 # get attributes from the printer and add to response 481 for printer in self.printers.values(): 482 response.attribute_groups.append(ipp.AttributeGroup( 483 ipp.AttributeTags.PRINTER, printer.get_printer_attributes(operation))) 510 response.attribute_groups.append(ipp.AttributeGroup( 511 ipp.AttributeTags.PRINTER, self.printer.get_printer_attributes(operation))) 484 512 485 513 @handler_for(ipp.OperationCodes.CUPS_GET_CLASSES)
Note: See TracChangeset
for help on using the changeset viewer.