Changeset ffbe41d for server/lib/gutenbach/ipp/core/attribute.py
- Timestamp:
- Jan 10, 2012, 7:25:33 PM (12 years ago)
- Branches:
- no-cups
- Children:
- b01b6d1
- Parents:
- ce2abc5
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/10/12 19:25:33)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/10/12 19:25:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/core/attribute.py
r793432f rffbe41d 59 59 """ 60 60 61 if name is not None: 62 assert isinstance(name, str), \ 63 "Attribute name must be a string!" 61 if name is not None and not isinstance(name, str): 62 raise ValueError("attribute name must be a string") 64 63 if values is None: 65 64 values = [] 66 65 for value in values: 67 assert isinstance(value, Value), \68 "Value %s must be of type Value" % (value,)66 if not isinstance(value, Value): 67 raise ValueError("value %s must be of type Value" % (value,)) 69 68 70 69 self.name = name … … 83 82 """ 84 83 85 assert self.name is not None, \86 "cannot pack unnamed attribute!"87 assert len(self.values) > 0, \88 "cannot pack empty attribute!"84 if self.name is None: 85 raise ValueError, "cannot pack unnamed attribute" 86 if len(self.values) == 0: 87 raise ValueError, "cannot pack empty attribute" 89 88 90 89 # get the binary data for all the values … … 94 93 # get the name length (0 for everything but the first 95 94 # value) 96 if i == 0: 97 name_length = len(self.name) 98 else: 99 name_length = 0 95 name_length = len(self.name) if i == 0 else 0 100 96 101 97 logger.debug("dumping name : %s" % self.name) … … 113 109 # the value tag in binary 114 110 tag_bin = struct.pack('>b', v.tag) 115 116 111 # the name length in binary 117 112 name_length_bin = struct.pack('>h', name_length) 118 119 113 # the name in binary 120 114 name_bin = self.name 121 122 115 # the value length in binary 123 116 value_length_bin = struct.pack('>h', value_length) 124 117 118 # add the binary value to the list of values 119 vlist = [tag_bin, name_length_bin, value_length_bin, value_bin] 125 120 if i == 0: 126 values.append(''.join([tag_bin, 127 name_length_bin, 128 name_bin, 129 value_length_bin, 130 value_bin])) 131 else: 132 values.append(''.join([tag_bin, 133 name_length_bin, 134 value_length_bin, 135 value_bin])) 121 vlist.insert(2, name_bin) 122 values.append(''.join(vlist)) 136 123 137 124 # concatenate everything together and return it along with the
Note: See TracChangeset
for help on using the changeset viewer.