source: server/lib/ippattributegroup.py @ 8979f90

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

Put various IPP classes in their own files

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#!/usr/bin/python
2
3import sys, struct, logging
4
5# initialize logger
6logger = logging.getLogger("ippLogger")
7
8class IPPAttributeGroup():
9    """
10    An IPPAttributeGroup consists of an attribute-group-tag, followed
11    by a sequence of IPPAttributes.
12    """
13
14    def __init__(self, attribute_group_tag, attributes=[]):
15        """
16        Initialize an IPPAttributeGroup.
17
18        Arguments:
19
20            attribute_group_tag -- a signed char, holds the tag of the
21                                   attribute group
22
23            attributes -- (optional) a list of attributes
24        """
25
26        # make sure attribute_group_tag isn't empty
27        assert attribute_group_tag is not None
28
29        # make sure attributes is a list or tuple of IPPAttributes
30        assert isinstance(attributes, (list, tuple))
31        for a in attributes: assert isinstance(a, IPPAttribute)
32
33        self.attribute_group_tag = attribute_group_tag
34        self.attributes = attributes
35
36    def getAttribute(self, name):
37        return filter(lambda x: x.name == name, self.attributes)
38
39    def toBinaryData(self):
40        """
41        Convert the IPPAttributeGroup to binary.
42        """
43
44        # conver the attribute_group_tag to binary
45        tag = struct.pack('>b', self.attribute_group_tag)
46
47        # convert each of the attributes to binary
48        attributes = [a.toBinaryData() for a in self.attributes]
49
50        # concatenate everything and return
51        return tag + ''.join(attributes)
Note: See TracBrowser for help on using the repository browser.