Changeset aded2d1 for server/lib/gutenbach/ipp/operations/__init__.py
- Timestamp:
- Dec 23, 2011, 8:20:29 PM (12 years ago)
- Branches:
- no-cups
- Children:
- b828a96
- Parents:
- f6e2532
- git-author:
- Jessica B. Hamrick <jhamrick@…> (12/23/11 20:20:29)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (12/23/11 20:20:29)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/operations/__init__.py
re70c020 raded2d1 5 5 from .. import errors 6 6 from .. import constants as consts 7 from .. import object_attributes 7 8 8 9 def verify_operations(request): … … 16 17 # XXX: check version 17 18 if False: 18 raise errors. VersionNotSupported(str(request.version))19 raise errors.ClientErrorVersionNotSupported(str(request.version)) 19 20 20 21 # XXX: check operation id 21 22 if False: 22 raise errors. OperationNotSupported(str(request.operation_id))23 raise errors.ClientErrorOperationNotSupported(str(request.operation_id)) 23 24 24 25 # check operation attributes tag 25 26 op_attrs = request.attribute_groups[0] 26 27 if op_attrs.tag != consts.AttributeTags.OPERATION: 27 raise errors. BadRequest(28 raise errors.ClientErrorBadRequest( 28 29 "Attribute group does not have OPERATION tag: 0x%x" % op_attrs.tag) 29 30 … … 32 33 # # check compression 33 34 # if False: 34 # raise errors.C ompressionNotSupported35 # raise errors.ClientErrorCompressionNotSupported 35 36 36 37 # # check document format 37 38 # if False: 38 # raise errors. DocumentFormatNotSupported39 # raise errors.ClientErrorDocumentFormatNotSupported 39 40 40 41 # # check document uri 41 42 # if False: 42 # raise errors. UriSchemeNotSupported43 # raise errors.ClientErrorUriSchemeNotSupported 43 44 44 45 # check charset 45 46 charset_attr = op_attrs.attributes[0] 46 if charset_attr.name != 'attributes-charset': 47 raise errors.BadRequest( 48 "Attribute is not attributes-charset: %s" % charset_attr.name) 49 if len(charset_attr.values) != 1: 50 raise errors.BadRequest( 51 "Too many values for attributes-charset: %d" % len(charset_attr.values)) 52 # check charset value 53 charset_value = charset_attr.values[0] 54 if charset_value.tag != consts.operations_attribute_value_tags['attributes-charset']: 55 raise errors.BadRequest( 56 "Wrong tag for charset value: 0x%x" % charset_value.tag) 57 if charset_value.value != 'utf-8': 58 raise errors.CharsetNotSupported(str(charset_value.value)) 47 if charset_attr != object_attributes.AttributesCharset('utf-8'): 48 raise errors.ClientErrorBadRequest 59 49 60 50 # check for attributes-natural-language 61 51 natlang_attr = op_attrs.attributes[1] 62 if natlang_attr.name != 'attributes-natural-language': 63 raise errors.BadRequest( 64 "Attribute is not attributes-natural-language: %s" % natlang_attr.name) 65 if len(charset_attr.values) != 1: 66 raise errors.BadRequest( 67 "Too many values for attributes-natural-language: %s" % len(natlang_attr.values)) 68 # check natural language value 69 natlang_value = natlang_attr.values[0] 70 if natlang_value.tag != consts.operations_attribute_value_tags['attributes-natural-language']: 71 raise errors.BadRequest( 72 "Natural language value does not have NATURAL_LANGUAGE tag: 0x%x" % natlang_value.tag) 73 if natlang_value.value != 'en-us': 74 raise errors.Attributes( 75 "Invalid natural language value: %s" % natlang_value.value, [natlang_attr]) 52 if natlang_attr != object_attributes.AttributesNaturalLanguage('en-us'): 53 raise errors.ClientErrorBadRequest 76 54 77 return dict([(attr.name, attr .values) for attr in op_attrs.attributes])55 return dict([(attr.name, attr) for attr in op_attrs.attributes]) 78 56 79 def verify_printer_uri(values): 80 if len(values) != 1: 81 raise errors.BadRequest( 82 "Requesting printer uri attribute has too many values: %d" % len(values)) 83 uri_value = values[0] 84 if uri_value.tag != consts.operations_attribute_value_tags['printer-uri']: 85 raise errors.BadRequest( 86 "Bad value tag (expected URI): 0x%x" % uri_value_tag) 57 def verify_printer_uri(uri_attr): 58 if uri_attr != object_attributes.PrinterUri(uri_attr.values[0].value): 59 raise errors.ClientErrorBadRequest 87 60 88 61 # actually get the printer name … … 90 63 # we can't do an exact comparison (also the hostname might be 91 64 # different, depending on the CNAME or whether it's localhost) 92 uri = uri_ value.value.split("/")[-1]65 uri = uri_attr.values[0].value.split("/")[-1] 93 66 return uri 94 67 95 def verify_requesting_username(values): 96 if len(values) != 1: 97 raise errors.BadRequest( 98 "Requesting user name attribute has too many values: %d" % len(values)) 99 requser_value = values[0] 100 if requser_value.tag != consts.operations_attribute_value_tags['requesting-user-name']: 101 raise errors.BadRequest( 102 "Bad value tag (expected NAME_WITHOUT_LANGUAGE): 0x%x" % requser_value.tag) 103 104 return requser_value.value 68 def verify_requesting_username(username_attr): 69 if username_attr != object_attributes.RequestingUserName(username_attr.values[0].value): 70 raise errors.ClientErrorBadRequest 71 return username_attr.values[0].value 105 72 106 73 def make_empty_response(request): 107 74 # Operation attributes -- typically the same for any request 108 attributes = [ 109 Attribute( 110 'attributes-charset', 111 [Value(consts.operations_attribute_value_tags['attributes-charset'], 'utf-8')]), 112 Attribute( 113 'attributes-natural-language', 114 [Value(consts.operations_attribute_value_tags['attributes-natural-language'], 115 'en-us')]) 116 ] 117 # Put the operation attributes in a group 118 attribute_group = AttributeGroup( 75 attributes = AttributeGroup( 119 76 consts.AttributeTags.OPERATION, 120 attributes) 77 [object_attributes.AttributesCharset('utf-8'), 78 object_attributes.AttributesNaturalLanguage('en-us')]) 121 79 122 80 # Set up the default response -- handlers will override these … … 126 84 response_kwargs['operation_id'] = consts.StatusCodes.OK 127 85 response_kwargs['request_id'] = request.request_id 128 response_kwargs['attribute_groups'] = [attribute _group]86 response_kwargs['attribute_groups'] = [attributes] 129 87 response = Request(**response_kwargs) 130 88 … … 132 90 133 91 def make_job_attributes(attrs, request, response): 134 ipp_attrs = []135 for attr, vals in attrs:136 ipp_vals = [Value(137 tag=consts.job_attribute_value_tags[attr],138 value=val) for val in vals]139 ipp_attrs.append(Attribute(name=attr, values=ipp_vals))140 92 response.attribute_groups.append(AttributeGroup( 141 consts.AttributeTags.JOB, ipp_attrs))93 consts.AttributeTags.JOB, attrs)) 142 94 143 95 def make_printer_attributes(attrs, request, response): 144 ipp_attrs = []145 for attr, vals in attrs:146 ipp_vals = [Value(147 tag=consts.printer_attribute_value_tags[attr],148 value=val) for val in vals]149 ipp_attrs.append(Attribute(name=attr, values=ipp_vals))150 96 response.attribute_groups.append(AttributeGroup( 151 consts.AttributeTags.PRINTER, ipp_attrs))97 consts.AttributeTags.PRINTER, attrs)) 152 98 153 99 from cups_get_classes import verify_cups_get_classes_request, make_cups_get_classes_response
Note: See TracChangeset
for help on using the changeset viewer.