Esempio n. 1
0
 def __getattr__(self, name):
     """
     This method is only called if the attribute is not found in the usual
     places (i.e. not an instance attribute or not found in the class tree
     for self).
     """
     try:
         index = TRACE_HEADER_KEYS.index(name)
     # If not found raise an attribute error.
     except ValueError:
         msg = "'%s' object has no attribute '%s'" % (self.__class__.__name__, name)
         raise AttributeError(msg)
     # Unpack the one value and set the class attribute so it will does not
     # have to unpacked again if accessed in the future.
     length, name, special_format, start = TRACE_HEADER_FORMAT[index]
     string = self.unpacked_header[start : start + length]
     attribute = unpack_header_value(self.endian, string, length, special_format)
     setattr(self, name, attribute)
     return attribute
Esempio n. 2
0
 def __getitem__(self, name):
     # Return if already set.
     if name in self.__dict__:
         if name in self.readonly:
             return self.__dict__[name]
         return super(AttribDict, self).__getitem__(name)
     # Otherwise try to unpack them.
     try:
         index = TRACE_HEADER_KEYS.index(name)
     # If not found raise an attribute error.
     except ValueError:
         msg = "'%s' object has no attribute '%s'" % (self.__class__.__name__, name)
         raise AttributeError(msg)
     # Unpack the one value and set the class attribute so it will does not
     # have to unpacked again if accessed in the future.
     length, name, special_format, start = TRACE_HEADER_FORMAT[index]
     string = self.__dict__["unpacked_header"][start : start + length]
     attribute = unpack_header_value(self.__dict__["endian"], string, length, special_format)
     setattr(self, name, attribute)
     return attribute
Esempio n. 3
0
 def __getattr__(self, name):
     """
     This method is only called if the attribute is not found in the usual
     places (i.e. not an instance attribute or not found in the class tree
     for self).
     """
     try:
         index = TRACE_HEADER_KEYS.index(name)
     # If not found raise an attribute error.
     except ValueError:
         msg = "'%s' object has no attribute '%s'" % \
             (self.__class__.__name__, name)
         raise AttributeError(msg)
     # Unpack the one value and set the class attribute so it will does not
     # have to unpacked again if accessed in the future.
     length, name, special_format, start = TRACE_HEADER_FORMAT[index]
     string = self.unpacked_header[start:start + length]
     attribute = unpack_header_value(self.endian, string, length,
                                     special_format)
     setattr(self, name, attribute)
     return attribute
Esempio n. 4
0
 def __getitem__(self, name):
     # Return if already set.
     if name in self.__dict__:
         if name in self.readonly:
             return self.__dict__[name]
         return super(AttribDict, self).__getitem__(name)
     # Otherwise try to unpack them.
     try:
         index = TRACE_HEADER_KEYS.index(name)
     # If not found raise an attribute error.
     except ValueError:
         msg = "'%s' object has no attribute '%s'" % \
             (self.__class__.__name__, name)
         raise AttributeError(msg)
     # Unpack the one value and set the class attribute so it will does not
     # have to unpacked again if accessed in the future.
     length, name, special_format, start = TRACE_HEADER_FORMAT[index]
     string = self.__dict__['unpacked_header'][start:start + length]
     attribute = unpack_header_value(self.__dict__['endian'], string,
                                     length, special_format)
     setattr(self, name, attribute)
     return attribute