Changeset 5fe360e


Ignore:
Timestamp:
Dec 20, 2011, 1:07:42 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
f6c6897
Parents:
71bfce0
git-author:
Jessica B. Hamrick <jhamrick@…> (12/20/11 13:07:42)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/20/11 13:07:42)
Message:

Converting server code to rely more on the ipp/ code

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

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/server/job.py

    r1a63bf7 r5fe360e  
    6464    @property
    6565    def job_k_octets(self):
    66         return "job-k-octets"
     66        return 1
    6767
    6868    @property
     
    7676    def get_job_attributes(self, request):
    7777        attributes = [(attr, getattr(self, attr)) for attr in self.attributes]
     78        attributes = map(lambda x: x if isinstance(x, (tuple, list)) else [x], attributes)
    7879        return attributes
    7980   
  • server/lib/gutenbach/server/printer.py

    r1a63bf7 r5fe360e  
    156156    def get_printer_attributes(self, request):
    157157        attributes = [(attr, getattr(self, attr)) for attr in self.attributes]
     158        attributes = map(lambda x: x if isinstance(x, (tuple, list)) else [x], attributes)
    158159        return attributes
    159160
  • server/lib/gutenbach/server/requests.py

    r6ed9d7a r5fe360e  
    1 from gutenbach.server.exceptions import MalformedIPPRequestException
    21from gutenbach.server.printer import GutenbachPrinter
    32import gutenbach.ipp as ipp
    43import gutenbach.ipp.constants as const
     4from gutenbach.ipp.constants import job_attribute_value_tags, printer_attribute_value_tags
    55import logging
    66
     
    5151
    5252    def _get_printer_attributes(self, printer, request, response):
     53        attrs = printer.get_printer_attributes(request)
     54        ipp_attrs = []
     55        for attr, vals in enumerate(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))
    5360        response.attribute_groups.append(ipp.AttributeGroup(
    54             const.AttributeTags.PRINTER,
    55             printer.get_printer_attributes(request)))
    56 
    57     def _get_job_attributes(self, job_id, printer, request, response):
     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 enumerate(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))
    5871        response.attribute_groups.append(ipp.AttributeGroup(
    59             const.AttributeTags.JOB,
    60             job.get_job_attributes(request)))
    61 
    62     def _get_printer_name(self, request):
    63         # make sure the first group is an OPERATION group
    64         group_tag = request.attribute_groups[0].tag
    65         if group_tag != const.AttributeTags.OPERATION:
    66             raise MalformedIPPRequestException, \
    67                   "Expected OPERATION group tag, got %d\n", group_tag
    68 
    69         # make sure the printer-uri value is appropriate
    70         printer_name_attr = request.attribute_groups[0]['printer-uri']
    71         printer_name_value_tag = printer_name_attr.values[0].value_tag
    72         if printer_name_value_tag != const.CharacterStringTags.URI:
    73             raise MalformedIPPRequestException, \
    74                   "Expected URI value tag, got %s" % printer_name_value_tag
    75 
    76         # actually get the printer name
    77         printer_name_value = printer_name_attr.values[0].value
    78         # XXX: hack -- CUPS will strip the port from the request, so
    79         # we can't do an exact comparison (also the hostname might be
    80         # different, depending on the CNAME or whether it's localhost)
    81         printer_name = printer_name_value.split("/")[-1]
    82 
    83         # make sure the printer name is valid
    84         if printer_name not in self.printers:
    85             raise ValueError, "Invalid printer uri: %s" % printer_name_value
    86 
    87         return printer_name
     72            const.AttributeTags.JOB, ipp_attrs))
    8873
    8974    def _get_job_id(self, request):
     
    11398
    11499        """
    115 
    116         printer_name = self._get_printer_name(request)
     100       
     101        reqdict = ipp.ops.verify_get_jobs_request(request)
     102        printer_name = reqdict['printer-uri']
     103        if printer_name not in self.printers:
     104            raise ipp.errors.Attributes(
     105                "Invalid printer uri: %s" % printer_name,
     106                [request.attribute_groups[0].attributes[2]])
     107
    117108        # Each job will append a new job attribute group.
     109        # XXX: we need to honor the things that the request actually asks for
    118110        for job in self.printers[printer_name].get_jobs():
    119111            self._get_job_attributes(job, request, response)
     
    135127        # this is just like cups_get_default, except the printer name
    136128        # is given
    137         printer_name = self._get_printer_name(request)
     129        reqdict = ipp.ops.verify_get_printer_attributes_request(request)
     130        printer_name = reqdict['printer-uri']
     131        if printer_name not in self.printers:
     132            raise ipp.errors.Attributes(
     133                "Invalid printer uri: %s" % printer_name,
     134                [request.attribute_groups[0].attributes[2]])
     135       
    138136        self._get_printer_attributes(self.printers[printer_name], request, response)
    139137
     
    153151
    154152    def get_job_attributes(self, request, response):
    155         printer_name = self._get_printer_name(request)
    156         job_id = self._get_job_id(request)
    157         self._get_job_attributes(
    158             self.printers[printer_name].get_job(job_id), request, response)
     153        reqdict = ipp.ops.verify_get_jobs_request(request)
     154        printer_name = reqdict['printer-uri']
     155        job_id = reqdict['job-id']
     156       
     157        if printer_name not in self.printers:
     158            raise ipp.errors.Attributes(
     159                "Invalid printer uri: %s" % printer_name,
     160                [request.attribute_groups[0].attributes[2]])
     161        try:
     162            job = self.printers[printer_name].get_job(job_id)
     163        except InvalidJobException:
     164            raise ipp.errors.Attributes(
     165                "Invalid job id: %d" % job_id,
     166                [request.attribute_groups[0].attributes[2]]) # XXX: this is wrong
     167
     168        # Each job will append a new job attribute group.
     169        # XXX: we need to honor the things that the request actually asks for
     170        self._get_job_attributes(job, request, response)
    159171
    160172    def set_job_attributes(self, request, response):
Note: See TracChangeset for help on using the changeset viewer.