Changeset 71bfce0 for server/lib/gutenbach/ipp/operations.py
- Timestamp:
- Dec 20, 2011, 1:07:05 PM (12 years ago)
- Branches:
- no-cups
- Children:
- 5fe360e
- Parents:
- cf32fee
- git-author:
- Jessica B. Hamrick <jhamrick@…> (12/20/11 13:07:05)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (12/20/11 13:07:05)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/operations.py
rcf32fee r71bfce0 3 3 from .attributegroup import AttributeGroup 4 4 from .request import Request 5 from .constants import AttributeTags, Tags5 from .constants import AttributeTags, operations_attribute_value_tags 6 6 import exceptions as err 7 7 … … 54 54 # check charset value 55 55 charset_value = charset_attr.values[0] 56 if charset_value.tag != Tags.CHARSET:57 raise err.BadRequest( 58 " Charset value does not have CHARSET tag: 0x%x" % charset_value.tag)56 if charset_value.tag != operations_attribute_value_tags['attributes-charset']: 57 raise err.BadRequest( 58 "Wrong tag for charset value: 0x%x" % charset_value.tag) 59 59 if charset_value.value != 'utf-8': 60 60 raise err.CharsetNotSupported(str(charset_value.value)) … … 71 71 # check natural language value 72 72 natlang_value = natlang_attr.values[0] 73 if natlang_value.tag != Tags.NATURAL_LANGUAGE:73 if natlang_value.tag != operations_attribute_value_tags['attributes-natural-language']: 74 74 raise err.BadRequest( 75 75 "Natural language value does not have NATURAL_LANGUAGE tag: 0x%x" natlang_value.tag) … … 78 78 "Invalid natural language value: %s" % natlang_value.value, [natlang_attr]) 79 79 80 def verify_printer_uri(uri_attr): 81 if uri_attr.name != 'printer-uri': 82 raise err.BadRequest( 83 "Unexpected name for attribute 'printer-uri': %s" % uri_attr.name) 84 if len(uri_attr.values) != 1: 85 raise err.BadRequest( 86 "Requesting printer uri attribute has too many values: %d" % len(uri_attr.values)) 87 printer_name_value = uri_attr.values[0] 88 if printer_name_value.tag != operations_attribute_value_tags['printer-uri']: 89 raise err.BadRequest( 90 "Bad value tag (expected URI): 0x%x" % printer_name_value_tag) 91 92 # actually get the printer name 93 printer_name_value = printer_name_attr.values[0].value 94 # XXX: hack -- CUPS will strip the port from the request, so 95 # we can't do an exact comparison (also the hostname might be 96 # different, depending on the CNAME or whether it's localhost) 97 printer_name = printer_name_value.split("/")[-1] 98 return printer_name 99 80 100 def verify_requesting_username(requser_attr): 81 if requser_attr.tag != Tags.NAME_WITHOUT_LANGUAGE: 82 raise err.BadRequest( 83 "Requesting user name attribute tag is not NAME_WITHOUT_LANGUAGE: 0x%x" % \ 84 requser_attr.tag) 101 if requser_attr.name != 'requesting-user-name': 102 raise err.BadRequest( 103 "Unexpected name for attribute 'requesting-user-name': %s" % requser_attr.name) 85 104 if len(requser_attr.values) != 1: 86 105 raise err.BadRequest( 87 106 "Requesting user name attribute has too many values: %d" % len(requser_attr.values)) 88 107 requser_value = requser_attr.values[0] 89 if requser_value.tag != Tags.NAME_WITHOUT_LANGUAGE:90 raise err.BadRequest( 91 " Requesting user name value tag is not NAME_WITHOUT_LANGUAGE: 0x%x" % \92 requser_value.tag)108 if requser_value.tag != operations_attribute_value_tags['requesting-user-name']: 109 raise err.BadRequest( 110 "Bad value tag (expected NAME_WITHOUT_LANGUAGE): 0x%x" % requser_value.tag) 111 93 112 return requser_value.value 94 113 … … 98 117 ipp.Attribute( 99 118 'attributes-charset', 100 [ ipp.Value(ipp.Tags.CHARSET, 'utf-8')]),119 [(operations_attribute_value_tags['attributes-charset'], 'utf-8')]), 101 120 ipp.Attribute( 102 121 'attributes-natural-language', 103 [ ipp.Value(ipp.Tags.NATURAL_LANGUAGE, 'en-us')])122 [(operations_attribute_value_tags['attributes-natural-language'], 'en-us')]) 104 123 ] 105 124 # Put the operation attributes in a group … … 205 224 """ 206 225 226 207 227 # generic operations verification 208 228 verify_operations(request) 209 229 # requested printer uri 230 printeruri = verify_printer_uri(request.attribute_groups[0].attributes[2]) 210 231 # requesting username 211 requser = verify_requesting_username(request.attributes[2]) 212 out = {'requesting-user-name': requser} 213 232 requser = verify_requesting_username(request.attribute_groups[0].attributes[3]) 214 233 # make the rest of the attributes into a dictionary 215 attrs = dict([(attr.name, attr.values) for attr in request.attributes[ 3:]])234 attrs = dict([(attr.name, attr.values) for attr in request.attributes[4:]]) 216 235 236 out = { 237 'printer-uri': printeruri, 238 'requesting-user-name': requser 239 } 240 217 241 if 'limit' in attrs: 218 242 out['limit'] = None # XXX … … 230 254 231 255 def make_get_jobs_response(self, request): 232 """ 3.2.6.2 Get-Jobs Response256 """RFC 2911: 3.2.6.2 Get-Jobs Response 233 257 234 258 The Printer object returns all of the Job objects up to the number
Note: See TracChangeset
for help on using the changeset viewer.