Changeset 4603
- Timestamp:
- 04/29/09 03:12:17 (4 years ago)
- Files:
-
- 1 modified
-
branch/UMPA/umpa/protocols/_protocols.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branch/UMPA/umpa/protocols/_protocols.py
r4598 r4603 84 84 """ 85 85 86 if self._is_valid(attr): 87 return self.get_field(attr).get() 88 else: 89 raise UMPAAttributeException(attr + ' is not allowed') 86 return self.get_field(attr).get() 90 87 91 88 def __setattr__(self, attr, value): … … 99 96 """ 100 97 101 if self._is_valid(attr): 102 self.get_field(attr).set(value) 103 else: 104 raise UMPAAttributeException(attr + ' is not allowed') 98 self.get_field(attr).set(value) 105 99 106 100 def __str__(self): … … 121 115 return super(Protocol, self).__str__() 122 116 117 def _is_valid(self, field): 118 """ 119 Validate if the filed is allowed. 120 121 @param field: requested field. 122 123 @rtype: C{bool} 124 @return: result of the validation. 125 """ 126 127 return field in self._fields 128 123 129 @classmethod 124 130 def get_fields_keys(cls): … … 171 177 """ 172 178 179 if len(args) % 2: 180 raise UMPAAttributeException('wrong amount of passed arguments') 173 181 # converting args list to the dict and update our kwargs 174 182 kwargs.update(_dict_from_sequence(args)) 175 183 184 # first check if all keys are valid to avoid partial-changing 176 185 for key in kwargs: 177 if self._is_valid(key): 178 setattr(self, key, kwargs[key]) 186 if not self._is_valid(key): 187 raise UMPAAttributeException(key + ' is not allowed; ' 188 'nothing has changed') 189 190 for key in kwargs: 191 setattr(self, key, kwargs[key]) 192 193 def get_flags(self, name, *args): 194 """ 195 Return flags of the field. 196 197 @type name: C{str} 198 @param name: name of the field. 199 200 @param args: names of flags. 201 202 @rtype: C{list} 203 @return: list of flags. 204 """ 205 206 flag_field = self.get_field(name) 207 if not isinstance(flag_field, Flags): 208 raise UMPAAttributeException("No Flags instance for " + name) 209 return flag_field.get(*args) 179 210 180 211 def set_flags(self, name, *args, **kwargs): … … 194 225 """ 195 226 227 if len(args) % 2: 228 raise UMPAAttributeException('wrong amount of passed arguments') 196 229 # converting args list to the dict and update our kwargs 197 230 kwargs.update(_dict_from_sequence(args)) … … 207 240 raise UMPAAttributeException("No Flags instance for " + name) 208 241 209 def get_flags(self, name, *args):210 """211 Return flags of the field.212 213 @type name: C{str}214 @param name: name of the field.215 216 @param args: names of flags.217 218 @rtype: C{list}219 @return: list of flags.220 """221 222 flag_field = self.get_field(name)223 if isinstance(flag_field, Flags):224 return flag_field.get(*args)225 else:226 raise UMPAAttributeException("No Flags instance for " + name)227 228 242 def get_offset(self, field): 229 243 """ … … 245 259 field_list = [ f for f in self.get_fields() ] 246 260 else: 247 raise UMPAException( type(field) + ' unsupported')261 raise UMPAException(str(type(field)) + ' unsupported') 248 262 249 263 if field not in field_list: 250 raise UMPAAttributeException( field+ ' is not allowed')264 raise UMPAAttributeException(repr(field) + ' is not allowed') 251 265 252 266 offset = 0 … … 380 394 # protocol should return byte-compatible length 381 395 if bit % BYTE != 0: 382 raise UMPAException('odd number of bits in ' + s elf.__name__)396 raise UMPAException('odd number of bits in ' + str(self.name)) 383 397 384 398 self.__dict__['__raw_value'] = raw_value 385 399 return raw_value, bit 386 387 def _is_valid(self, field):388 """389 Validate if the filed is allowed.390 391 @param field: requested field.392 393 @rtype: C{bool}394 @return: result of the validation.395 """396 397 return field in self._fields
