Exemple #1
0
 def _readTraceHeader(self, header):
     """
     Reads the 240 byte long header and unpacks all values into
     corresponding class attributes.
     """
     # Set the start position.
     pos = 0
     # Loop over all items in the TRACE_HEADER_FORMAT list which is supposed
     # to be in the correct order.
     for item in TRACE_HEADER_FORMAT:
         length, name, special_format, _ = item
         string = header[pos : pos + length]
         pos += length
         setattr(self, name, unpack_header_value(self.endian, string, length, special_format))
Exemple #2
0
 def _readTraceHeader(self, header):
     """
     Reads the 240 byte long header and unpacks all values into
     corresponding class attributes.
     """
     # Set the start position.
     pos = 0
     # Loop over all items in the TRACE_HEADER_FORMAT list which is supposed
     # to be in the correct order.
     for item in TRACE_HEADER_FORMAT:
         length, name, special_format, _ = item
         string = header[pos: pos + length]
         pos += length
         setattr(self, name, unpack_header_value(self.endian, string,
                                                 length, special_format))
Exemple #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
Exemple #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
Exemple #5
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
Exemple #6
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