source: server/lib/gutenbach/ipp/operations/__init__.py @ 793432f

no-cups
Last change on this file since 793432f was 793432f, checked in by Jessica B. Hamrick <jhamrick@…>, 12 years ago

Reorganization

  • Property mode set to 100644
File size: 7.0 KB
Line 
1from .. import Attribute
2from .. import AttributeGroup
3from .. import Request
4from .. import Value
5from .. import errors
6from .. import constants
7from .. import attributes
8
9def verify_operations(request):
10    """Pretty much all requests have the first attribute group for
11    operation attributes, and these all have 'attributes-charset' and
12    'attributes-natural-language' as the first two attributes.  This
13    method just generically verifies that these attributes are there.
14
15    """
16
17    # XXX: check version
18    if False:
19        raise errors.ClientErrorVersionNotSupported(str(request.version))
20
21    # XXX: check operation id
22    if False:
23        raise errors.ClientErrorOperationNotSupported(str(request.operation_id))
24
25    # check operation attributes tag
26    op_attrs = request.attribute_groups[0]
27    if op_attrs.tag != constants.AttributeTags.OPERATION:
28        raise errors.ClientErrorBadRequest(
29            "Attribute group does not have OPERATION tag: 0x%x" % op_attrs.tag)
30
31    # XXX: if these aren't valid, then you HAVE to return something
32    # special.  See RFC 2911 3.1.6.1
33    # # check compression
34    # if False:
35    #     raise errors.ClientErrorCompressionNotSupported
36
37    # # check document format
38    # if False:
39    #     raise errors.ClientErrorDocumentFormatNotSupported
40
41    # # check document uri
42    # if False:
43    #     raise errors.ClientErrorUriSchemeNotSupported
44
45    # check charset
46    charset_attr = op_attrs.attributes[0]
47    expected = attributes.AttributesCharset('utf-8')
48    if charset_attr != expected:
49        raise errors.ClientErrorBadRequest("%s != %s" % (charset_attr, expected))
50
51    # check for attributes-natural-language
52    natlang_attr = op_attrs.attributes[1]
53    expected = attributes.AttributesNaturalLanguage('en-us')
54    if natlang_attr != expected:
55        raise errors.ClientErrorBadRequest("%s != %s" % (natlang_attr, expected))
56
57    return dict([(attr.name, attr) for attr in op_attrs.attributes])
58
59def verify_printer_uri(uri_attr):
60    expected = attributes.PrinterUri(uri_attr.values[0].value)
61    if uri_attr != expected:
62        raise errors.ClientErrorBadRequest("%s != %s" % (uri_attr, expected))
63   
64    # actually get the printer name
65    # XXX: hack -- CUPS will strip the port from the request, so
66    # we can't do an exact comparison (also the hostname might be
67    # different, depending on the CNAME or whether it's localhost)
68    uri = uri_attr.values[0].value.split("/")[-1]
69    return uri
70
71def verify_requesting_username(username_attr):
72    expected = attributes.RequestingUserName(username_attr.values[0].value)
73    if username_attr != expected:
74        raise errors.ClientErrorBadRequest("%s != %s" % (username_attr, expected))
75    return username_attr.values[0].value
76
77def make_empty_response(request):
78    # Operation attributes -- typically the same for any request
79    attribute_group = AttributeGroup(
80        constants.AttributeTags.OPERATION,
81        [attributes.AttributesCharset('utf-8'),
82         attributes.AttributesNaturalLanguage('en-us')])
83
84    # Set up the default response -- handlers will override these
85    # values if they need to
86    response_kwargs = {}
87    response_kwargs['version']          = request.version
88    response_kwargs['operation_id']     = constants.StatusCodes.OK
89    response_kwargs['request_id']       = request.request_id
90    response_kwargs['attribute_groups'] = [attribute_group]
91    response = Request(**response_kwargs)
92
93    return response
94
95def make_job_attributes(attrs, request, response):
96    response.attribute_groups.append(AttributeGroup(
97        constants.AttributeTags.JOB, attrs))
98
99def make_printer_attributes(attrs, request, response):
100    response.attribute_groups.append(AttributeGroup(
101        constants.AttributeTags.PRINTER, attrs))
102
103from cups_get_classes import verify_cups_get_classes_request, make_cups_get_classes_response
104from cups_get_default import verify_cups_get_default_request, make_cups_get_default_response
105from cups_get_document import verify_cups_get_document_request, make_cups_get_document_response
106from cups_get_printers import verify_cups_get_printers_request, make_cups_get_printers_response
107
108from cancel_job import verify_cancel_job_request, make_cancel_job_response
109from create_job import verify_create_job_request, make_create_job_response
110from get_jobs import verify_get_jobs_request, make_get_jobs_response
111from get_printer_attributes import make_get_printer_attributes_response
112from get_printer_attributes import verify_get_printer_attributes_request
113from pause_printer import verify_pause_printer_request, make_pause_printer_response
114from print_job import verify_print_job_request, make_print_job_response
115from print_uri import verify_print_uri_request, make_print_uri_response
116from promote_job import verify_promote_job_request, make_promote_job_response
117from restart_job import verify_restart_job_request, make_restart_job_response
118from resume_printer import verify_resume_printer_request, make_resume_printer_response
119from send_document import verify_send_document_request, make_send_document_response
120from send_uri import verify_send_uri_request, make_send_uri_response
121from set_job_attributes import make_set_job_attributes_response
122from set_job_attributes import verify_set_job_attributes_request
123from set_printer_attributes import make_set_printer_attributes_response
124from set_printer_attributes import verify_set_printer_attributes_request
125from validate_job import verify_validate_job_request, make_validate_job_response
126
127__all__ = ['verify_cups_get_classes_request', 'make_cups_get_classes_response',
128           'verify_cups_get_default_request', 'make_cups_get_default_response',
129           'verify_cups_get_document_request', 'make_cups_get_document_response',
130           'verify_cups_get_printers_request', 'make_cups_get_printers_response',
131
132           'verify_cancel_job_request', 'make_cancel_job_response',
133           'verify_create_job_request', 'make_create_job_response',
134           'verify_get_jobs_request', 'make_get_jobs_response',
135           'make_get_printer_attributes_response',
136           'verify_get_printer_attributes_request',
137           'verify_pause_printer_request', 'make_pause_printer_response',
138           'verify_print_job_request', 'make_print_job_response',
139           'verify_print_uri_request', 'make_print_uri_response',
140           'verify_promote_job_request', 'make_promote_job_response',
141           'verify_restart_job_request', 'make_restart_job_response',
142           'verify_resume_printer_request', 'make_resume_printer_response',
143           'verify_send_document_request', 'make_send_document_response',
144           'verify_send_uri_request', 'make_send_uri_response',
145           'make_set_job_attributes_response',
146           'verify_set_job_attributes_request',
147           'make_set_printer_attributes_response',
148           'verify_set_printer_attributes_request',
149           'verify_validate_job_request', 'make_validate_job_response',
150
151           'verify_operations',
152           'verify_printer_uri',
153           'verify_requesting_username',
154
155           'make_empty_response',
156           'make_job_attributes',
157           'make_printer_attributes']
Note: See TracBrowser for help on using the repository browser.