source: server/lib/ippattributegroup.py @ 2646571

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

Update references to IPPTags and add import statements for IPPAttribute, IPPAttributeGroup, IPPValue

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