Changeset ef8df33 for server


Ignore:
Timestamp:
Dec 20, 2011, 3:11:32 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
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)
Message:

Move more ipp-specific code into ipp/operations from server/requests; Fix more bugs

Location:
server/lib/gutenbach
Files:
3 edited

Legend:

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

    rcad7502 ref8df33  
    33from .attributegroup import AttributeGroup
    44from .request import Request
    5 from .constants import AttributeTags, StatusCodes, operations_attribute_value_tags
     5import constants as consts
    66import exceptions as err
    77import logging
     
    2727    # check operation attributes tag
    2828    op_attrs = request.attribute_groups[0]
    29     if op_attrs.tag != AttributeTags.OPERATION:
     29    if op_attrs.tag != consts.AttributeTags.OPERATION:
    3030        raise err.BadRequest(
    3131            "Attribute group does not have OPERATION tag: 0x%x" % op_attrs.tag)
     
    5353    # check charset value
    5454    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']:
    5656        raise err.BadRequest(
    5757            "Wrong tag for charset value: 0x%x" % charset_value.tag)
     
    6969    # check natural language value
    7070    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']:
    7272        raise err.BadRequest(
    7373            "Natural language value does not have NATURAL_LANGUAGE tag: 0x%x" % natlang_value.tag)
     
    8383            "Requesting printer uri attribute has too many values: %d" % len(values))
    8484    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']:
    8686        raise err.BadRequest(
    8787            "Bad value tag (expected URI): 0x%x" % uri_value_tag)
     
    9999            "Requesting user name attribute has too many values: %d" % len(values))
    100100    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']:
    102102        raise err.BadRequest(
    103103            "Bad value tag (expected NAME_WITHOUT_LANGUAGE): 0x%x" % requser_value.tag)
     
    110110        Attribute(
    111111            'attributes-charset',
    112             [Value(operations_attribute_value_tags['attributes-charset'], 'utf-8')]),
     112            [Value(consts.operations_attribute_value_tags['attributes-charset'], 'utf-8')]),
    113113        Attribute(
    114114            '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')])
    116117        ]
    117118    # Put the operation attributes in a group
    118119    attribute_group = AttributeGroup(
    119         AttributeTags.OPERATION,
     120        consts.AttributeTags.OPERATION,
    120121        attributes)
    121122
     
    124125    response_kwargs = {}
    125126    response_kwargs['version']          = request.version
    126     response_kwargs['operation_id']     = StatusCodes.OK
     127    response_kwargs['operation_id']     = consts.StatusCodes.OK
    127128    response_kwargs['request_id']       = request.request_id
    128129    response_kwargs['attribute_groups'] = [attribute_group]
     
    130131
    131132    return response
     133
     134def 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
     144def 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))
    132153
    133154#### GET-JOBS
     
    247268    return out
    248269
    249 def make_get_jobs_response(self, request):
     270def make_get_jobs_response(jobs, request):
    250271    """RFC 2911: 3.2.6.2 Get-Jobs Response
    251272       
     
    320341    """
    321342
    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
    323348
    324349## GET-PRINTER-ATTRIBUTES
     
    450475
    451476
    452 def make_get_printer_attributes_response(self, request):
     477def make_get_printer_attributes_response(attrs, request):
    453478    """3.2.5.2 Get-Printer-Attributes Response
    454479
     
    495520
    496521    """
    497     pass
     522
     523    response = make_empty_response(request)
     524    make_printer_attributes(attrs, request, response)
     525    return response
     526
     527
     528def 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
     553def 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
     579def 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
     623def 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
     651def 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
     696def 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
  • server/lib/gutenbach/server/requests.py

    rcad7502 ref8df33  
    22import gutenbach.ipp as ipp
    33import gutenbach.ipp.constants as const
    4 from gutenbach.ipp.constants import job_attribute_value_tags, printer_attribute_value_tags
    54import logging
    65
     
    2827        self.default = "test"
    2928   
    30     def handle(self, request, response):
     29    def handle(self, request):
    3130        # look up the handler
    3231        handler = None
     
    4241        handler = getattr(self, handler_name)
    4342        logger.info("Handling request of type '%s'" % handler_name)
    44         handler(request, response)
    45 
    46     def unknown_operation(self, request, response):
     43        response = handler(request)
     44        return response
     45
     46    def unknown_operation(self, request):
    4747        logger.warning("Received unknown operation 0x%x" % request.operation_id)
     48        response = ipp.ops.make_empty_response(request)
    4849        response.operation_id = const.StatusCodes.OPERATION_NOT_SUPPORTED
    49 
    50     ##### Helper functions
    51 
    52     def _get_printer_attributes(self, printer, request, response):
    53         attrs = printer.get_printer_attributes(request)
    54         ipp_attrs = []
    55         for attr, vals in attrs:
    56             ipp_vals = [ipp.Value(
    57                 tag=printer_attribute_value_tags[attr],
    58                 value=val) for val in vals]
    59             ipp_attrs.append(ipp.Attribute(name=attr, values=ipp_vals))
    60         response.attribute_groups.append(ipp.AttributeGroup(
    61             const.AttributeTags.PRINTER, ipp_attrs))
    62 
    63     def _get_job_attributes(self, job, request, response):
    64         attrs = job.get_job_attributes(request)
    65         ipp_attrs = []
    66         for attr, vals in attrs:
    67             ipp_vals = [ipp.Value(
    68                 tag=job_attribute_value_tags[attr],
    69                 value=val) for val in vals]
    70             ipp_attrs.append(ipp.Attribute(name=attr, values=ipp_vals))
    71         response.attribute_groups.append(ipp.AttributeGroup(
    72             const.AttributeTags.JOB, ipp_attrs))
    73 
    74     def _get_job_id(self, request):
    75         pass
     50        return response
    7651       
    7752    ##### Printer Commands
    7853
    79     def print_job(self, request, response):
    80         pass
    81 
    82     def validate_job(self, request, response):
     54    def print_job(self, request):
     55        pass
     56
     57    def validate_job(self, request):
    8358        pass
    8459
    8560    @handler_for(const.Operations.GET_JOBS)
    86     def get_jobs(self, request, response):
     61    def get_jobs(self, request):
    8762        """RFC 2911: 3.2.6 Get-Jobs Operation
    8863       
     
    9974        """
    10075       
    101         reqdict = ipp.ops.verify_get_jobs_request(request)
    102         printer_name = reqdict['printer-uri']
     76        req_dict = ipp.ops.verify_get_jobs_request(request)
     77        printer_name = req_dict['printer-uri']
    10378        if printer_name not in self.printers:
    10479            raise ipp.errors.Attributes(
     
    10782
    10883        # Each job will append a new job attribute group.
    109         # XXX: we need to honor the things that the request actually asks for
    110         for job in self.printers[printer_name].get_jobs():
    111             self._get_job_attributes(job, request, response)
    112 
    113     def print_uri(self, request, response):
    114         pass
    115 
    116     def create_job(self, request, response):
    117         pass
    118 
    119     def pause_printer(self, request, response):
    120         pass
    121 
    122     def resume_printer(self, request, response):
     84        jobs = [job.get_job_attributes(request) for job in \
     85                self.printers[printer_name].get_jobs()]
     86        response = ipp.ops.make_get_jobs_response(jobs, request)
     87        return response
     88
     89    def print_uri(self, request):
     90        pass
     91
     92    def create_job(self, request):
     93        pass
     94
     95    def pause_printer(self, request):
     96        pass
     97
     98    def resume_printer(self, request):
    12399        pass
    124100
    125101    @handler_for(const.Operations.GET_PRINTER_ATTRIBUTES)
    126     def get_printer_attributes(self, request, response):
     102    def get_printer_attributes(self, request):
    127103        """RFC 2911: 3.2.5 Get-Printer-Attributes Operation
    128104
     
    169145        # this is just like cups_get_default, except the printer name
    170146        # is given
    171         reqdict = ipp.ops.verify_get_printer_attributes_request(request)
    172         printer_name = reqdict['printer-uri']
     147        req_dict = ipp.ops.verify_get_printer_attributes_request(request)
     148        printer_name = req_dict['printer-uri']
    173149        if printer_name not in self.printers:
    174150            raise ipp.errors.Attributes(
     
    176152                [request.attribute_groups[0].attributes[2]])
    177153       
    178         self._get_printer_attributes(self.printers[printer_name], request, response)
    179 
    180     def set_printer_attributes(self, request, response):
     154        response = ipp.ops.make_get_printer_attributes_response(
     155            self.printers[printer_name].get_printer_attributes(request), request)
     156        return response
     157
     158    def set_printer_attributes(self, request):
    181159        pass
    182160
    183161    ##### Job Commands
    184162
    185     def cancel_job(self, request, response):
    186         pass
    187 
    188     def send_document(self, request, response):
    189         pass
    190 
    191     def send_uri(self, request, response):
    192         pass
    193 
    194     def get_job_attributes(self, request, response):
    195         reqdict = ipp.ops.verify_get_jobs_request(request)
    196         printer_name = reqdict['printer-uri']
    197         job_id = reqdict['job-id']
     163    def cancel_job(self, request):
     164        pass
     165
     166    def send_document(self, request):
     167        pass
     168
     169    def send_uri(self, request):
     170        pass
     171
     172    def get_job_attributes(self, request):
     173        req_dict = ipp.ops.verify_get_jobs_request(request)
     174        printer_name = req_dict['printer-uri']
     175        job_id = req_dict['job-id']
    198176       
    199177        if printer_name not in self.printers:
     
    210188        # Each job will append a new job attribute group.
    211189        # XXX: we need to honor the things that the request actually asks for
    212         self._get_job_attributes(job, request, response)
    213 
    214     def set_job_attributes(self, request, response):
    215         pass
    216 
    217     def cups_get_document(self, request, response):
    218         pass
    219 
    220     def restart_job(self, request, response):
    221         pass
    222 
    223     def promote_job(self, request, response):
     190        response = ipp.ops.make_get_job_attributes_response(
     191            job.get_job_attributes(request), request)
     192        return response
     193
     194    def set_job_attributes(self, request):
     195        pass
     196
     197    def cups_get_document(self, request):
     198        pass
     199
     200    def restart_job(self, request):
     201        pass
     202
     203    def promote_job(self, request):
    224204        pass
    225205
     
    227207
    228208    @handler_for(const.Operations.CUPS_GET_DEFAULT)
    229     def cups_get_default(self, request, response):
     209    def cups_get_default(self, request):
    230210        """The CUPS-Get-Default operation (0x4001) returns the default
    231211        printer URI and attributes.
    232212
    233         CUPS-Get-Default Request
    234         ------------------------
    235 
    236         The following groups of attributes are supplied as part of the
    237         CUPS-Get-Default request:
    238 
    239         Group 1: Operation Attributes
    240             Natural Language and Character Set:
    241                 The 'attributes-charset' and
    242                 'attributes-natural-language' attributes as described
    243                 in section 3.1.4.1 of the IPP Model and Semantics
    244                 document.
    245             'requested-attributes' (1setOf keyword):
    246                 The client OPTIONALLY supplies a set of attribute
    247                 names and/or attribute group names in whose values the
    248                 requester is interested. If the client omits this
    249                 attribute, the server responds as if this attribute
    250                 had been supplied with a value of 'all'.
    251        
    252         CUPS-Get-Default Response
    253         -------------------------
    254 
    255         The following groups of attributes are send as part of the
    256         CUPS-Get-Default Response:
    257 
    258         Group 1: Operation Attributes
    259             Status Message:
    260                 The standard response status message.
    261             Natural Language and Character Set:
    262                 The 'attributes-charset' and
    263                 'attributes-natural-language' attributes as described
    264                 in section 3.1.4.2 of the IPP Model and Semantics
    265                 document.
    266 
    267         Group 2: Printer Object Attributes
    268             The set of requested attributes and their current values.
    269 
    270213        (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_DEFAULT )
    271214
    272215        """
    273            
    274         self._get_printer_attributes(self.printers[self.default], request, response)
     216
     217        req_dict = ipp.ops.verify_cups_get_default_request(request)
     218        response = ipp.ops.make_get_printer_attributes_response(
     219            self.printers[self.default].get_printer_attributes(request), request)
     220        return response
    275221
    276222    @handler_for(const.Operations.CUPS_GET_PRINTERS)
    277     def cups_get_printers(self, request, response):
    278         """
    279         The CUPS-Get-Printers operation (0x4002) returns the printer
    280         attributes for every printer known to the system. This may
    281         include printers that are not served directly by the server.
    282 
    283         CUPS-Get-Printers Request
    284         -------------------------
    285        
    286         The following groups of attributes are supplied as part of the
    287         CUPS-Get-Printers request:
    288 
    289         Group 1: Operation Attributes
    290             Natural Language and Character Set:
    291                 The 'attributes-charset' and
    292                 'attributes-natural-language' attributes as described
    293                 in section 3.1.4.1 of the IPP Model and Semantics
    294                 document.
    295             'first-printer-name' (name(127)):CUPS 1.2/Mac OS X 10.5
    296                 The client OPTIONALLY supplies this attribute to
    297                 select the first printer that is returned.
    298             'limit' (integer (1:MAX)):
    299                 The client OPTIONALLY supplies this attribute limiting
    300                 the number of printers that are returned.
    301             'printer-location' (text(127)): CUPS 1.1.7
    302                 The client OPTIONALLY supplies this attribute to
    303                 select which printers are returned.
    304             'printer-type' (type2 enum): CUPS 1.1.7
    305                 The client OPTIONALLY supplies a printer type
    306                 enumeration to select which printers are returned.
    307             'printer-type-mask' (type2 enum): CUPS 1.1.7
    308                 The client OPTIONALLY supplies a printer type mask
    309                 enumeration to select which bits are used in the
    310                 'printer-type' attribute.
    311             'requested-attributes' (1setOf keyword) :
    312                 The client OPTIONALLY supplies a set of attribute
    313                 names and/or attribute group names in whose values the
    314                 requester is interested. If the client omits this
    315                 attribute, the server responds as if this attribute
    316                 had been supplied with a value of 'all'.
    317             'requested-user-name' (name(127)) : CUPS 1.2/Mac OS X 10.5
    318                 The client OPTIONALLY supplies a user name that is
    319                 used to filter the returned printers.
    320 
    321         CUPS-Get-Printers Response
    322         --------------------------
    323 
    324         The following groups of attributes are send as part of the
    325         CUPS-Get-Printers Response:
    326 
    327         Group 1: Operation Attributes
    328             Status Message:
    329                 The standard response status message.
    330             Natural Language and Character Set:
    331                 The 'attributes-charset' and
    332                 'attributes-natural-language' attributes as described
    333                 in section 3.1.4.2 of the IPP Model and Semantics
    334                 document.
    335                
    336         Group 2: Printer Object Attributes
    337             The set of requested attributes and their current values
    338             for each printer.
     223    def cups_get_printers(self, request):
     224        """The CUPS-Get-Printers operation (0x4002) returns the
     225        printer attributes for every printer known to the system. This
     226        may include printers that are not served directly by the
     227        server.
    339228
    340229        (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_PRINTERS )
     
    342231        """
    343232
    344         # Each printer will append a new printer attribute group.
    345         for printer in self.printers:
    346             self._get_printer_attributes(self.printers[printer], request, response)
     233        req_dict = ipp.ops.verify_cups_get_printers_request(request)
     234        attrs = [self.printers[printer].get_printer_attributes(request) \
     235                 for printer in self.printers]
     236        response = ipp.ops.make_cups_get_printers_response(attrs, request)
     237        return response
    347238
    348239    @handler_for(const.Operations.CUPS_GET_CLASSES)
    349     def cups_get_classes(self, request, response):
     240    def cups_get_classes(self, request):
    350241        """The CUPS-Get-Classes operation (0x4005) returns the printer
    351242        attributes for every printer class known to the system. This
    352243        may include printer classes that are not served directly by
    353244        the server.
    354 
    355         CUPS-Get-Classes Request
    356         ------------------------
    357 
    358         The following groups of attributes are supplied as part of the
    359         CUPS-Get-Classes request:
    360 
    361         Group 1: Operation Attributes
    362             Natural Language and Character Set:
    363                 The 'attributes-charset' and
    364                 'attributes-natural-language' attributes as described
    365                 in section 3.1.4.1 of the IPP Model and Semantics
    366                 document.
    367             'first-printer-name' (name(127)):CUPS 1.2/Mac OS X 10.5
    368                 The client OPTIONALLY supplies this attribute to
    369                 select the first printer that is returned.
    370             'limit' (integer (1:MAX)):
    371                 The client OPTIONALLY supplies this attribute limiting
    372                 the number of printer classes that are returned.
    373             'printer-location' (text(127)): CUPS 1.1.7
    374                 The client OPTIONALLY supplies this attribute to
    375                 select which printer classes are returned.
    376             'printer-type' (type2 enum): CUPS 1.1.7
    377                 The client OPTIONALLY supplies a printer type
    378                 enumeration to select which printer classes are
    379                 returned.
    380             'printer-type-mask' (type2 enum): CUPS 1.1.7
    381                 The client OPTIONALLY supplies a printer type mask
    382                 enumeration to select which bits are used in the
    383                 'printer-type' attribute.
    384             'requested-attributes' (1setOf keyword) :
    385                 The client OPTIONALLY supplies a set of attribute
    386                 names and/or attribute group names in whose values the
    387                 requester is interested. If the client omits this
    388                 attribute, the server responds as if this attribute
    389                 had been supplied with a value of 'all'.
    390             'requested-user-name' (name(127)) : CUPS 1.2/Mac OS X 10.5
    391                 The client OPTIONALLY supplies a user name that is
    392                 used to filter the returned printers.
    393                
    394         CUPS-Get-Classes Response
    395         -------------------------
    396 
    397         The following groups of attributes are send as part of the
    398         CUPS-Get-Classes Response:
    399 
    400         Group 1: Operation Attributes
    401             Status Message:
    402                 The standard response status message.
    403             Natural Language and Character Set:
    404                 The 'attributes-charset' and
    405                 'attributes-natural-language' attributes as described
    406                 in section 3.1.4.2 of the IPP Model and Semantics
    407                 document.
    408 
    409         Group 2: Printer Class Object Attributes
    410             The set of requested attributes and their current values
    411             for each printer class.
    412 
     245       
    413246        (Source: http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_CLASSES )
    414247
    415248        """
    416        
    417         # We have no printer classes, so we don't need to do anything
    418         pass
     249
     250        req_dict = ipp.ops.verify_cups_get_classes_request(request)
     251        response = ipp.ops.make_cups_get_classes_response(request)
     252        return response
  • server/lib/gutenbach/server/server.py

    r6effd50 ref8df33  
    2929        logger.debug("Received request: %s" % repr(request))
    3030
    31         # Create an empty response object
    32         response = ipp.ops.make_empty_response(request)
    33 
    3431        # Get the handler and pass it the request and response
    3532        # objects.  It will fill in values for the response object or
    3633        # thrown an error.
    3734        try:
    38             self.root.handle(request, response)
     35            response = self.root.handle(request)
    3936           
    4037        # Handle any errors that occur.  If an exception occurs that
     
    4340        except ipp.errors.IPPException:
    4441            exctype, excval, exctb = sys.exc_info()
     42            logger.error(traceback.format_exc())
     43            response = ipp.ops.make_empty_response(request)
    4544            excval.update_response(response)
    46             logger.error(traceback.format_exc())
    4745
    4846        # If it wasn't an IPP error, then it's our fault, so mark it
    4947        # as an internal server error
    5048        except Exception:
     49            logger.error(traceback.format_exc())
     50            response = ipp.ops.make_empty_response(request)
    5151            response.operation_id = ipp.StatusCodes.INTERNAL_ERROR
    52             logger.error(traceback.format_exc())
    5352
    5453        # Send the response across HTTP
Note: See TracChangeset for help on using the changeset viewer.