Changeset 5fe360e
- Timestamp:
- Dec 20, 2011, 1:07:42 PM (12 years ago)
- 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)
- Location:
- server/lib/gutenbach/server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/server/job.py
r1a63bf7 r5fe360e 64 64 @property 65 65 def job_k_octets(self): 66 return "job-k-octets"66 return 1 67 67 68 68 @property … … 76 76 def get_job_attributes(self, request): 77 77 attributes = [(attr, getattr(self, attr)) for attr in self.attributes] 78 attributes = map(lambda x: x if isinstance(x, (tuple, list)) else [x], attributes) 78 79 return attributes 79 80 -
server/lib/gutenbach/server/printer.py
r1a63bf7 r5fe360e 156 156 def get_printer_attributes(self, request): 157 157 attributes = [(attr, getattr(self, attr)) for attr in self.attributes] 158 attributes = map(lambda x: x if isinstance(x, (tuple, list)) else [x], attributes) 158 159 return attributes 159 160 -
server/lib/gutenbach/server/requests.py
r6ed9d7a r5fe360e 1 from gutenbach.server.exceptions import MalformedIPPRequestException2 1 from gutenbach.server.printer import GutenbachPrinter 3 2 import gutenbach.ipp as ipp 4 3 import gutenbach.ipp.constants as const 4 from gutenbach.ipp.constants import job_attribute_value_tags, printer_attribute_value_tags 5 5 import logging 6 6 … … 51 51 52 52 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)) 53 60 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)) 58 71 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)) 88 73 89 74 def _get_job_id(self, request): … … 113 98 114 99 """ 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 117 108 # Each job will append a new job attribute group. 109 # XXX: we need to honor the things that the request actually asks for 118 110 for job in self.printers[printer_name].get_jobs(): 119 111 self._get_job_attributes(job, request, response) … … 135 127 # this is just like cups_get_default, except the printer name 136 128 # 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 138 136 self._get_printer_attributes(self.printers[printer_name], request, response) 139 137 … … 153 151 154 152 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) 159 171 160 172 def set_job_attributes(self, request, response):
Note: See TracChangeset
for help on using the changeset viewer.