Ignore:
Timestamp:
Mar 7, 2011, 7:47:42 PM (13 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
fa0d0ef
Parents:
5cfb358
git-author:
Jessica B. Hamrick <jhamrick@…> (03/07/11 19:47:42)
git-committer:
Jessica B. Hamrick <jhamrick@…> (03/07/11 19:47:42)
Message:

Update API for Value, Attribute, and AttributeGroup?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/ippattributegroup.py

    rebf327d rc269bc7  
    1313    """
    1414
    15     def __init__(self, attribute_group_tag, attributes=[]):
     15    def __init__(self, attribute_group_tag=None, attributes=[]):
    1616        """
    17         Initialize an AttributeGroup.
     17        Initialize an AttributeGroup.  An AttributeGroup can be
     18        initialized in three ways:
     19
     20            AttributeGroup()
     21            AttributeGroup(attribute_group_tag)
     22            AttributeGroup(attribute_group_tag, attributes)
    1823
    1924        Arguments:
     
    2227                                   attribute group
    2328
    24             attributes -- (optional) a list of attributes
     29            attributes -- a list of attributes
    2530        """
    2631
    27         # make sure attribute_group_tag isn't empty
    28         assert attribute_group_tag is not None
     32        if attribute_group_tag is not None:
     33            assert isinstance(attribute_group_tag, char), \
     34                   "attribute_group_tag must be a character!"
     35           
    2936
    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)
     37        if len(attributes) > 0:
     38            for a in attributes:
     39                assert isinstance(a, Attribute), \
     40                       "attribute must be of type Attribute!"
    3341
    3442        self.attribute_group_tag = attribute_group_tag
     
    3644
    3745    def getAttribute(self, name):
     46        """
     47        Returns a list of attributes which have name 'name'.
     48        """
     49       
    3850        return filter(lambda x: x.name == name, self.attributes)
    3951
    40     def toBinaryData(self):
     52    def getTag(self):
     53        """
     54        Return the attribute group tag.
     55        """
     56
     57        return self.attribute_group_tag
     58
     59    def getAttributes(self):
     60        """
     61        Return the list of attributes in this attribue group.
     62        """
     63
     64        return self.attributes
     65
     66    def setAttributes(self, attributes):
     67        """
     68        Sets the attributes for the attribute group.
     69        """
     70
     71        for a in attributes:
     72            assert isinstance(a, Attribute), \
     73                   "attribute must be of type Attribute!"
     74
     75        self.attributes = attributes
     76
     77    def addAttribute(self, attribute):
     78        """
     79        Adds an attribute to the list of attributes for the attribute
     80        group.
     81        """
     82       
     83        assert isinstance(attribute, Attribute), \
     84               "attribute must be of type Attribute!"
     85
     86        self.attributes.append(attribute)
     87
     88    def setTag(self, tag):
     89        """
     90        Sets the attribute group tag.
     91        """
     92
     93        assert isinstance(tag, char), \
     94               "attribute tag must be a character!"
     95
     96        self.attribute_group_tag = tag
     97
     98    def pack(self):
    4199        """
    42100        Convert the AttributeGroup to binary.
Note: See TracChangeset for help on using the changeset viewer.