Changeset a76f440 for server/lib
- Timestamp:
- Mar 10, 2011, 1:28:20 AM (14 years ago)
- Branches:
- no-cups
- Children:
- 0e5cdb3
- Parents:
- 75c0cab
- git-author:
- Quentin Smith <quentin@…> (03/10/11 01:28:20)
- git-committer:
- Quentin Smith <quentin@…> (03/10/11 01:28:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/ippattributegroup.py
rc269bc7 ra76f440 7 7 logger = logging.getLogger("ippLogger") 8 8 9 class AttributeGroup( ):9 class AttributeGroup(object): 10 10 """ 11 11 An AttributeGroup consists of an attribute-group-tag, followed by 12 a sequence of Attributes. 12 a sequence of Attributes. According to RFC 2565, "Within an 13 attribute-sequence, if two attributes have the same name, the 14 first occurrence MUST be ignored.", so we can effectively treat 15 this as an ordered dictionary. 13 16 """ 14 17 … … 35 38 36 39 37 if len(attributes) > 0: 38 for a in attributes: 39 assert isinstance(a, Attribute), \ 40 "attribute must be of type Attribute!" 40 self.attribute_group_tag = attribute_group_tag 41 self.attributes[] 42 self.extend(attributes) 41 43 42 self.attribute_group_tag = attribute_group_tag 43 self.attributes = attributes 44 45 def getAttribute(self, name): 44 def __getitem__(self, name): 46 45 """ 47 46 Returns a list of attributes which have name 'name'. 48 47 """ 49 48 50 return filter(lambda x: x.name == name, self.attributes) 49 attribute = filter(lambda x: x.name == name, self.attributes) 50 if attribute: 51 return attribute[0] 52 else: 53 raise KeyError("Attribute %r not found" % name) 51 54 52 def getTag(self): 55 def __contains__(self, name): 56 return len(filter(lambda x: x.name == name, self.attributes)) 57 58 def __iter__(self): 59 return (a.name for a in self.attributes) 60 iterkeys = __iter__ 61 62 def __setitem__(self, name, attribute): 53 63 """ 54 Return the attribute group tag. 64 Sets an attribute in the attribute group. Note that the key is 65 ignored and the attribute is queried for its name. 55 66 """ 56 67 57 return self.a ttribute_group_tag68 return self.append(attribute) 58 69 59 def getAttributes(self): 60 """ 61 Return the list of attributes in this attribue group. 62 """ 70 def __delitem__(self, name): 71 self.attributes = filter(lambda x: x.name != name, self.attributes) 63 72 64 return self.attributes 73 def append(self, attribute): 74 return self.extend([attribute]) 65 75 66 def setAttributes(self, attributes):76 def extend(self, attributes): 67 77 """ 68 78 Sets the attributes for the attribute group. … … 73 83 "attribute must be of type Attribute!" 74 84 75 self.attributes = attributes 85 for a in attributes: 86 # XXX: Instead of replacing the attribute, do we want to 87 # append the value to the attribute here? 88 del self[a.name] 89 self.attributes.append(a) 76 90 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): 91 @property 92 def packed_value(self): 99 93 """ 100 94 Convert the AttributeGroup to binary. … … 105 99 106 100 # convert each of the attributes to binary 107 attributes = [a. toBinaryData()for a in self.attributes]101 attributes = [a.packed_value for a in self.attributes] 108 102 109 103 # concatenate everything and return
Note: See TracChangeset
for help on using the changeset viewer.