1 | from . import verify_operations |
---|
2 | from . import verify_printer_uri |
---|
3 | from . import verify_requesting_username |
---|
4 | from . import make_empty_response |
---|
5 | from . import make_printer_attributes |
---|
6 | |
---|
7 | import logging |
---|
8 | logger = logging.getLogger(__name__) |
---|
9 | |
---|
10 | def verify_get_printer_attributes_request(request): |
---|
11 | """RFC 2911: 3.2.5.1 Get-Printer-Attributes Request |
---|
12 | |
---|
13 | The following sets of attributes are part of the Get-Printer- |
---|
14 | Attributes Request: |
---|
15 | |
---|
16 | Group 1: Operation Attributes |
---|
17 | Natural Language and Character Set: |
---|
18 | The 'attributes-charset' and 'attributes-natural-language' |
---|
19 | attributes as described in section 3.1.4.1. |
---|
20 | Target: |
---|
21 | The 'printer-uri' (uri) operation attribute which is the |
---|
22 | target for this operation as described in section 3.1.5. |
---|
23 | Requesting User Name: |
---|
24 | The 'requesting-user-name' (name(MAX)) attribute SHOULD be |
---|
25 | supplied by the client as described in section 8.3. |
---|
26 | 'requested-attributes' (1setOf keyword): |
---|
27 | The client OPTIONALLY supplies a set of attribute names |
---|
28 | and/or attribute group names in whose values the requester |
---|
29 | is interested. The Printer object MUST support this |
---|
30 | attribute. If the client omits this attribute, the |
---|
31 | Printer MUST respond as if this attribute had been |
---|
32 | supplied with a value of 'all'. |
---|
33 | 'document-format' (mimeMediaType): |
---|
34 | The client OPTIONALLY supplies this attribute. The Printer |
---|
35 | object MUST support this attribute. This attribute is |
---|
36 | useful for a Printer object to determine the set of |
---|
37 | supported attribute values that relate to the requested |
---|
38 | document format. The Printer object MUST return the |
---|
39 | attributes and values that it uses to validate a job on a |
---|
40 | create or Validate-Job operation in which this document |
---|
41 | format is supplied. The Printer object SHOULD return only |
---|
42 | (1) those attributes that are supported for the specified |
---|
43 | format and (2) the attribute values that are supported for |
---|
44 | the specified document format. By specifying the document |
---|
45 | format, the client can get the Printer object to eliminate |
---|
46 | the attributes and values that are not supported for a |
---|
47 | specific document format. For example, a Printer object |
---|
48 | might have multiple interpreters to support both |
---|
49 | 'application/postscript' (for PostScript) and 'text/plain' |
---|
50 | (for text) documents. However, for only one of those |
---|
51 | interpreters might the Printer object be able to support |
---|
52 | 'number-up' with values of '1', '2', and '4'. For the |
---|
53 | other interpreter it might be able to only support |
---|
54 | 'number-up' with a value of '1'. Thus a client can use |
---|
55 | the Get-Printer-Attributes operation to obtain the |
---|
56 | attributes and values that will be used to accept/reject a |
---|
57 | create job operation. |
---|
58 | |
---|
59 | If the Printer object does not distinguish between |
---|
60 | different sets of supported values for each different |
---|
61 | document format when validating jobs in the create and |
---|
62 | Validate-Job operations, it MUST NOT distinguish between |
---|
63 | different document formats in the Get-Printer-Attributes |
---|
64 | operation. If the Printer object does distinguish between |
---|
65 | different sets of supported values for each different |
---|
66 | document format specified by the client, this |
---|
67 | specialization applies only to the following Printer |
---|
68 | object attributes: |
---|
69 | |
---|
70 | - Printer attributes that are Job Template attributes |
---|
71 | ('xxx- default' 'xxx-supported', and 'xxx-ready' in the |
---|
72 | Table in Section 4.2), |
---|
73 | |
---|
74 | - 'pdl-override-supported', |
---|
75 | - 'compression-supported', |
---|
76 | - 'job-k-octets-supported', |
---|
77 | - 'job-impressions-supported', |
---|
78 | - 'job-media-sheets-supported', |
---|
79 | - 'printer-driver-installer', |
---|
80 | - 'color-supported', and |
---|
81 | - 'reference-uri-schemes-supported' |
---|
82 | |
---|
83 | The values of all other Printer object attributes |
---|
84 | (including 'document-format-supported') remain invariant |
---|
85 | with respect to the client supplied document format |
---|
86 | (except for new Printer description attribute as |
---|
87 | registered according to section 6.2). |
---|
88 | |
---|
89 | If the client omits this 'document-format' operation |
---|
90 | attribute, the Printer object MUST respond as if the |
---|
91 | attribute had been supplied with the value of the Printer |
---|
92 | object's 'document-format- default' attribute. It is |
---|
93 | RECOMMENDED that the client always supply a value for |
---|
94 | 'document-format', since the Printer object's |
---|
95 | 'document-format-default' may be |
---|
96 | 'application/octet-stream', in which case the returned |
---|
97 | attributes and values are for the union of the document |
---|
98 | formats that the Printer can automatically sense. For |
---|
99 | more details, see the description of the 'mimeMediaType' |
---|
100 | attribute syntax in section 4.1.9. |
---|
101 | |
---|
102 | If the client supplies a value for the 'document-format' |
---|
103 | Operation attribute that is not supported by the Printer, |
---|
104 | i.e., is not among the values of the Printer object's |
---|
105 | 'document-format-supported' attribute, the Printer object |
---|
106 | MUST reject the operation and return the |
---|
107 | 'client-error-document-format-not-supported' status code. |
---|
108 | |
---|
109 | """ |
---|
110 | |
---|
111 | out = {} |
---|
112 | |
---|
113 | # generic operations verification |
---|
114 | attrs = verify_operations(request) |
---|
115 | |
---|
116 | # requested printer uri |
---|
117 | if 'printer-uri' not in attrs: |
---|
118 | raise err.BadRequest("Missing 'printer-uri' attribute") |
---|
119 | out['printer-uri'] = verify_printer_uri(attrs['printer-uri']) |
---|
120 | |
---|
121 | # requesting username |
---|
122 | if 'requesting-user-name' not in attrs: |
---|
123 | logger.warning("Missing 'requesting-user-name' attribute") |
---|
124 | else: |
---|
125 | out['requesting-user-name'] = verify_requesting_username(attrs['requesting-user-name']) |
---|
126 | |
---|
127 | if 'requested-attributes' in attrs: |
---|
128 | out['requested-attributes'] = None # XXX |
---|
129 | |
---|
130 | if 'document-format' in attrs: |
---|
131 | out['document-format'] = None # XXX |
---|
132 | |
---|
133 | return out |
---|
134 | |
---|
135 | def make_get_printer_attributes_response(attrs, request): |
---|
136 | """3.2.5.2 Get-Printer-Attributes Response |
---|
137 | |
---|
138 | The Printer object returns the following sets of attributes as |
---|
139 | part of the Get-Printer-Attributes Response: |
---|
140 | |
---|
141 | Group 1: Operation Attributes |
---|
142 | Status Message: |
---|
143 | In addition to the REQUIRED status code returned in every |
---|
144 | response, the response OPTIONALLY includes a |
---|
145 | 'status-message' (text(255)) and/or a |
---|
146 | 'detailed-status-message' (text(MAX)) operation attribute |
---|
147 | as described in sections 13 and 3.1.6. |
---|
148 | Natural Language and Character Set: |
---|
149 | The 'attributes-charset' and 'attributes-natural-language' |
---|
150 | attributes as described in section 3.1.4.2. |
---|
151 | |
---|
152 | Group 2: Unsupported Attributes |
---|
153 | See section 3.1.7 for details on returning Unsupported |
---|
154 | Attributes. The response NEED NOT contain the |
---|
155 | 'requested-attributes' operation attribute with any supplied |
---|
156 | values (attribute keywords) that were requested by the client |
---|
157 | but are not supported by the IPP object. If the Printer |
---|
158 | object does return unsupported attributes referenced in the |
---|
159 | 'requested-attributes' operation attribute and that attribute |
---|
160 | included group names, such as 'all', the unsupported |
---|
161 | attributes MUST NOT include attributes described in the |
---|
162 | standard but not supported by the implementation. |
---|
163 | |
---|
164 | Group 3: Printer Object Attributes |
---|
165 | This is the set of requested attributes and their current |
---|
166 | values. The Printer object ignores (does not respond with) |
---|
167 | any requested attribute which is not supported. The Printer |
---|
168 | object MAY respond with a subset of the supported attributes |
---|
169 | and values, depending on the security policy in |
---|
170 | force. However, the Printer object MUST respond with the |
---|
171 | 'unknown' value for any supported attribute (including all |
---|
172 | REQUIRED attributes) for which the Printer object does not |
---|
173 | know the value. Also the Printer object MUST respond with the |
---|
174 | 'no-value' for any supported attribute (including all REQUIRED |
---|
175 | attributes) for which the system administrator has not |
---|
176 | configured a value. See the description of the 'out-of-band' |
---|
177 | values in the beginning of Section 4.1. |
---|
178 | |
---|
179 | """ |
---|
180 | |
---|
181 | response = make_empty_response(request) |
---|
182 | make_printer_attributes(attrs, request, response) |
---|
183 | return response |
---|