source: server/lib/ippattributegroup.py @ ebf327d

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

Change IPPValue, IPPAttribute, IPPAttributeGroup, and IPPRequest to Value, Attribute, AttributeGroup?, and Request, respectively, to make things a little less verbose

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#!/usr/bin/python
2
3import sys, struct, logging
4from ippattribute import Attribute
5
6# initialize logger
7logger = logging.getLogger("ippLogger")
8
9class AttributeGroup():
10    """
11    An AttributeGroup consists of an attribute-group-tag, followed by
12    a sequence of Attributes.
13    """
14
15    def __init__(self, attribute_group_tag, attributes=[]):
16        """
17        Initialize an AttributeGroup.
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 Attributes
31        assert isinstance(attributes, (list, tuple))
32        for a in attributes: assert isinstance(a, Attribute)
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 AttributeGroup 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.