Changeset ef8df33 for server/lib/gutenbach/ipp/operations.py
- Timestamp:
- Dec 20, 2011, 3:11:32 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 59a1d4a
- Parents:
- cad7502
- git-author:
- Jessica B. Hamrick <jhamrick@…> (12/20/11 15:11:32)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (12/20/11 15:11:32)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/operations.py
rcad7502 ref8df33 3 3 from .attributegroup import AttributeGroup 4 4 from .request import Request 5 from .constants import AttributeTags, StatusCodes, operations_attribute_value_tags5 import constants as consts 6 6 import exceptions as err 7 7 import logging … … 27 27 # check operation attributes tag 28 28 op_attrs = request.attribute_groups[0] 29 if op_attrs.tag != AttributeTags.OPERATION:29 if op_attrs.tag != consts.AttributeTags.OPERATION: 30 30 raise err.BadRequest( 31 31 "Attribute group does not have OPERATION tag: 0x%x" % op_attrs.tag) … … 53 53 # check charset value 54 54 charset_value = charset_attr.values[0] 55 if charset_value.tag != operations_attribute_value_tags['attributes-charset']:55 if charset_value.tag != consts.operations_attribute_value_tags['attributes-charset']: 56 56 raise err.BadRequest( 57 57 "Wrong tag for charset value: 0x%x" % charset_value.tag) … … 69 69 # check natural language value 70 70 natlang_value = natlang_attr.values[0] 71 if natlang_value.tag != operations_attribute_value_tags['attributes-natural-language']:71 if natlang_value.tag != consts.operations_attribute_value_tags['attributes-natural-language']: 72 72 raise err.BadRequest( 73 73 "Natural language value does not have NATURAL_LANGUAGE tag: 0x%x" % natlang_value.tag) … … 83 83 "Requesting printer uri attribute has too many values: %d" % len(values)) 84 84 uri_value = values[0] 85 if uri_value.tag != operations_attribute_value_tags['printer-uri']:85 if uri_value.tag != consts.operations_attribute_value_tags['printer-uri']: 86 86 raise err.BadRequest( 87 87 "Bad value tag (expected URI): 0x%x" % uri_value_tag) … … 99 99 "Requesting user name attribute has too many values: %d" % len(values)) 100 100 requser_value = values[0] 101 if requser_value.tag != operations_attribute_value_tags['requesting-user-name']:101 if requser_value.tag != consts.operations_attribute_value_tags['requesting-user-name']: 102 102 raise err.BadRequest( 103 103 "Bad value tag (expected NAME_WITHOUT_LANGUAGE): 0x%x" % requser_value.tag) … … 110 110 Attribute( 111 111 'attributes-charset', 112 [Value( operations_attribute_value_tags['attributes-charset'], 'utf-8')]),112 [Value(consts.operations_attribute_value_tags['attributes-charset'], 'utf-8')]), 113 113 Attribute( 114 114 'attributes-natural-language', 115 [Value(operations_attribute_value_tags['attributes-natural-language'], 'en-us')]) 115 [Value(consts.operations_attribute_value_tags['attributes-natural-language'], 116 'en-us')]) 116 117 ] 117 118 # Put the operation attributes in a group 118 119 attribute_group = AttributeGroup( 119 AttributeTags.OPERATION,120 consts.AttributeTags.OPERATION, 120 121 attributes) 121 122 … … 124 125 response_kwargs = {} 125 126 response_kwargs['version'] = request.version 126 response_kwargs['operation_id'] = StatusCodes.OK127 response_kwargs['operation_id'] = consts.StatusCodes.OK 127 128 response_kwargs['request_id'] = request.request_id 128 129 response_kwargs['attribute_groups'] = [attribute_group] … … 130 131 131 132 return response 133 134 def make_job_attributes(attrs, request, response): 135 ipp_attrs = [] 136 for attr, vals in attrs: 137 ipp_vals = [Value( 138 tag=consts.job_attribute_value_tags[attr], 139 value=val) for val in vals] 140 ipp_attrs.append(Attribute(name=attr, values=ipp_vals)) 141 response.attribute_groups.append(AttributeGroup( 142 consts.AttributeTags.JOB, ipp_attrs)) 143 144 def make_printer_attributes(attrs, request, response): 145 ipp_attrs = [] 146 for attr, vals in attrs: 147 ipp_vals = [Value( 148 tag=consts.printer_attribute_value_tags[attr], 149 value=val) for val in vals] 150 ipp_attrs.append(Attribute(name=attr, values=ipp_vals)) 151 response.attribute_groups.append(AttributeGroup( 152 consts.AttributeTags.PRINTER, ipp_attrs)) 132 153 133 154 #### GET-JOBS … … 247 268 return out 248 269 249 def make_get_jobs_response( self, request):270 def make_get_jobs_response(jobs, request): 250 271 """RFC 2911: 3.2.6.2 Get-Jobs Response 251 272 … … 320 341 """ 321 342 322 pass 343 response = make_empty_response(request) 344 # XXX: we need to honor the things that the request actually asks for 345 for job in jobs: 346 make_job_attributes(job, request, response) 347 return response 323 348 324 349 ## GET-PRINTER-ATTRIBUTES … … 450 475 451 476 452 def make_get_printer_attributes_response( self, request):477 def make_get_printer_attributes_response(attrs, request): 453 478 """3.2.5.2 Get-Printer-Attributes Response 454 479 … … 495 520 496 521 """ 497 pass 522 523 response = make_empty_response(request) 524 make_printer_attributes(attrs, request, response) 525 return response 526 527 528 def verify_cups_get_default_request(request): 529 """CUPS-Get-Default Request 530 531 The following groups of attributes are supplied as part of the 532 CUPS-Get-Default request: 533 534 Group 1: Operation Attributes 535 Natural Language and Character Set: 536 The 'attributes-charset' and 537 'attributes-natural-language' attributes as described 538 in section 3.1.4.1 of the IPP Model and Semantics 539 document. 540 'requested-attributes' (1setOf keyword): 541 The client OPTIONALLY supplies a set of attribute 542 names and/or attribute group names in whose values the 543 requester is interested. If the client omits this 544 attribute, the server responds as if this attribute 545 had been supplied with a value of 'all'. 546 547 (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_DEFAULT ) 548 549 """ 550 551 return {} 552 553 def make_cups_get_default_response(attrs, request): 554 """CUPS-Get-Default Response 555 556 The following groups of attributes are send as part of the 557 CUPS-Get-Default Response: 558 559 Group 1: Operation Attributes 560 Status Message: 561 The standard response status message. 562 Natural Language and Character Set: 563 The 'attributes-charset' and 564 'attributes-natural-language' attributes as described 565 in section 3.1.4.2 of the IPP Model and Semantics 566 document. 567 568 Group 2: Printer Object Attributes 569 The set of requested attributes and their current values. 570 571 (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_DEFAULT ) 572 573 """ 574 575 response = make_empty_response(request) 576 make_printer_attributes(attrs, request, response) 577 return response 578 579 def verify_cups_get_printers_request(request): 580 """CUPS-Get-Printers Request 581 582 The following groups of attributes are supplied as part of the 583 CUPS-Get-Printers request: 584 585 Group 1: Operation Attributes 586 Natural Language and Character Set: 587 The 'attributes-charset' and 588 'attributes-natural-language' attributes as described 589 in section 3.1.4.1 of the IPP Model and Semantics 590 document. 591 'first-printer-name' (name(127)):CUPS 1.2/Mac OS X 10.5 592 The client OPTIONALLY supplies this attribute to 593 select the first printer that is returned. 594 'limit' (integer (1:MAX)): 595 The client OPTIONALLY supplies this attribute limiting 596 the number of printers that are returned. 597 'printer-location' (text(127)): CUPS 1.1.7 598 The client OPTIONALLY supplies this attribute to 599 select which printers are returned. 600 'printer-type' (type2 enum): CUPS 1.1.7 601 The client OPTIONALLY supplies a printer type 602 enumeration to select which printers are returned. 603 'printer-type-mask' (type2 enum): CUPS 1.1.7 604 The client OPTIONALLY supplies a printer type mask 605 enumeration to select which bits are used in the 606 'printer-type' attribute. 607 'requested-attributes' (1setOf keyword) : 608 The client OPTIONALLY supplies a set of attribute 609 names and/or attribute group names in whose values the 610 requester is interested. If the client omits this 611 attribute, the server responds as if this attribute 612 had been supplied with a value of 'all'. 613 'requested-user-name' (name(127)) : CUPS 1.2/Mac OS X 10.5 614 The client OPTIONALLY supplies a user name that is 615 used to filter the returned printers. 616 617 (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_PRINTERS ) 618 619 """ 620 621 return {} 622 623 def make_cups_get_printers_response(printers, request): 624 """CUPS-Get-Printers Response 625 626 The following groups of attributes are send as part of the 627 CUPS-Get-Printers Response: 628 629 Group 1: Operation Attributes 630 Status Message: 631 The standard response status message. 632 Natural Language and Character Set: 633 The 'attributes-charset' and 634 'attributes-natural-language' attributes as described 635 in section 3.1.4.2 of the IPP Model and Semantics 636 document. 637 638 Group 2: Printer Object Attributes 639 The set of requested attributes and their current values 640 for each printer. 641 642 (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_PRINTERS ) 643 644 """ 645 646 response = make_empty_response(request) 647 for printer in printers: 648 make_printer_attributes(printer, request, response) 649 return response 650 651 def verify_cups_get_classes_request(request): 652 """CUPS-Get-Classes Request 653 654 The following groups of attributes are supplied as part of the 655 CUPS-Get-Classes request: 656 657 Group 1: Operation Attributes 658 Natural Language and Character Set: 659 The 'attributes-charset' and 660 'attributes-natural-language' attributes as described 661 in section 3.1.4.1 of the IPP Model and Semantics 662 document. 663 'first-printer-name' (name(127)):CUPS 1.2/Mac OS X 10.5 664 The client OPTIONALLY supplies this attribute to 665 select the first printer that is returned. 666 'limit' (integer (1:MAX)): 667 The client OPTIONALLY supplies this attribute limiting 668 the number of printer classes that are returned. 669 'printer-location' (text(127)): CUPS 1.1.7 670 The client OPTIONALLY supplies this attribute to 671 select which printer classes are returned. 672 'printer-type' (type2 enum): CUPS 1.1.7 673 The client OPTIONALLY supplies a printer type 674 enumeration to select which printer classes are 675 returned. 676 'printer-type-mask' (type2 enum): CUPS 1.1.7 677 The client OPTIONALLY supplies a printer type mask 678 enumeration to select which bits are used in the 679 'printer-type' attribute. 680 'requested-attributes' (1setOf keyword) : 681 The client OPTIONALLY supplies a set of attribute 682 names and/or attribute group names in whose values the 683 requester is interested. If the client omits this 684 attribute, the server responds as if this attribute 685 had been supplied with a value of 'all'. 686 'requested-user-name' (name(127)) : CUPS 1.2/Mac OS X 10.5 687 The client OPTIONALLY supplies a user name that is 688 used to filter the returned printers. 689 690 (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_CLASSES ) 691 692 """ 693 694 return {} 695 696 def make_cups_get_classes_response(request): 697 """CUPS-Get-Classes Response 698 699 The following groups of attributes are send as part of the 700 CUPS-Get-Classes Response: 701 702 Group 1: Operation Attributes 703 Status Message: 704 The standard response status message. 705 Natural Language and Character Set: 706 The 'attributes-charset' and 707 'attributes-natural-language' attributes as described 708 in section 3.1.4.2 of the IPP Model and Semantics 709 document. 710 711 Group 2: Printer Class Object Attributes 712 The set of requested attributes and their current values 713 for each printer class. 714 715 (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_CLASSES ) 716 717 """ 718 719 response = make_empty_response(request) 720 return response
Note: See TracChangeset
for help on using the changeset viewer.