def load_classes(self) -> Iterable[Tuple[int, DXFClass]]: sentinel = self.data[:SENTINEL_SIZE] if ( sentinel != b"\x8D\xA1\xC4\xB8\xC4\xA9\xF8\xC5\xC0\xDC\xF4\x5F\xE7\xCF\xB6\x8A" ): raise DwgCorruptedClassesSection( "Sentinel for start of CLASSES section not found." ) start_index = SENTINEL_SIZE bs = BitStream( self.data[start_index:], dxfversion=self.specs.version, encoding=self.specs.encoding, ) class_data_size = bs.read_unsigned_long() # data size in bytes end_sentinel_index = SENTINEL_SIZE + 6 + class_data_size end_index = end_sentinel_index - 2 end_bit_index = (3 + class_data_size) << 3 while bs.bit_index < end_bit_index: class_num = bs.read_bit_short() dxfattribs = { "flags": bs.read_bit_short(), # version? "app_name": bs.read_text(), "cpp_class_name": bs.read_text(), "name": bs.read_text(), "was_a_proxy": bs.read_bit(), "is_an_entity": int(bs.read_bit_short() == 0x1F2), } yield class_num, DXFClass.new(dxfattribs=dxfattribs) if self.crc_check and False: check = struct.unpack_from("<H", self.data, end_index)[0] # TODO: classes crc check # Which data should be checked? This is not correct: crc = crc8(self.data[start_index:end_index]) if check != crc: raise CRCError("CRC error in classes section.") sentinel = self.data[ end_sentinel_index : end_sentinel_index + SENTINEL_SIZE ] if ( sentinel != b"\x72\x5E\x3B\x47\x3B\x56\x07\x3A\x3F\x23\x0B\xA0\x18\x30\x49\x75" ): raise DwgCorruptedClassesSection( "Sentinel for end of CLASSES section not found." )
def classes_R2000(self) -> None: seeker, section_size = self.specs.sections[CLASSES_ID] sentinel = self.data[seeker:seeker + SENTINEL_SIZE] if sentinel != b'\x8D\xA1\xC4\xB8\xC4\xA9\xF8\xC5\xC0\xDC\xF4\x5F\xE7\xCF\xB6\x8A': raise DwgCorruptedClassesSection( 'Sentinel for start of section not found.') cls_tag = DXFTag(0, 'CLASS') classes = self.sections['CLASSES'] bs = BitStream( self.data[seeker + SENTINEL_SIZE:seeker + section_size], dxfversion=self.specs.version, encoding=self.specs.encoding, ) class_data_size = bs.read_unsigned_long() # data size in bytes end_index = (3 + class_data_size) << 3 while bs.bit_index < end_index: class_num = bs.read_bit_short() flags = bs.read_bit_short() # version? app_name = bs.read_text() cpp_class_name = bs.read_text() class_dxf_name = bs.read_text() was_a_zombie = bs.read_bit() item_class_id = bs.read_bit_short() # print((class_num, flags, app_name, class_dxf_name, cpp_class_name, was_a_zombie, item_class_id)) classes.append( Tags([ cls_tag, DXFTag(1, class_dxf_name), DXFTag(2, cpp_class_name), DXFTag(3, app_name), DXFTag(90, flags), DXFTag(280, was_a_zombie), DXFTag(281, 1 if item_class_id == 0x1f2 else 0) ])) self.dxf_object_types[class_num] = class_dxf_name # Ignore crc for the sake of speed. # _index = index + (20 + class_data_size) # crc = struct.unpack_from('<h', self.data, index) _index = seeker + (SENTINEL_SIZE + 6 + class_data_size) sentinel = self.data[_index:_index + SENTINEL_SIZE] if sentinel != b'\x72\x5E\x3B\x47\x3B\x56\x07\x3A\x3F\x23\x0B\xA0\x18\x30\x49\x75': raise DwgCorruptedClassesSection( 'Sentinel for end of section not found.')