Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_matrix(self, code: int) -> 'Matrix44':
subclass = self.tags.subclasses[1] # always 2nd subclass
try:
return matrix_accessors.get_matrix(subclass, code)
except DXFStructureError:
raise DXFStructureError('Invalid transformation matrix in entity ' + self.__str__())
def load_matrix(subclass: 'Tags', code: int) -> Matrix44:
values = [tag.value for tag in subclass.find_all(code)]
if len(values) != 16:
raise DXFStructureError('Invalid transformation matrix.')
return Matrix44(values)
def _get_extended_type(self, tags: Tags) -> Tuple[float, ...]:
value = tags.get_first_value(self.code)
if len(value) == 3:
if self.xtype is XType.point2d:
raise DXFStructureError("expected 2D point but found 3D point")
elif self.xtype is XType.point3d: # len(value) == 2
raise DXFStructureError("expected 3D point but found 2D point")
return value
def add_entity(self, entity: 'DXFGraphic') -> None:
"""
Add an existing :class:`DXFGraphic` entity to a layout, but be sure to unlink (:meth:`~BaseLayout.unlink_entity`)
entity from the previous owner layout. Adding entities from a different DXF drawing is not supported.
"""
if entity.doc != self.doc:
raise DXFStructureError('Adding entities from a different DXF drawing is not supported.')
self.block_record.add_entity(entity)
def _build(self, entities: Iterator[DXFTag]) -> None:
section_head = next(entities)
if section_head[0] != (0, 'SECTION') or section_head[1] != (2, 'CLASSES'):
raise DXFStructureError("Critical structure error in CLASSES section.")
for class_tags in entities:
self.register(ExtendedTags(class_tags))
def __init__(self, name: Filename):
self.structure, self.sections = self._load_index(name)
self.file: BinaryIO = open(name, mode='rb')
if 'ENTITIES' not in self.sections:
raise DXFStructureError('ENTITIES section not found.')
if self.structure.version > 'AC1009' and 'OBJECTS' not in self.sections:
raise DXFStructureError('OBJECTS section not found.')
def load(self, entities: Iterator[DXFEntity]) -> None:
section_head = next(entities) # type: DXFTagStorage
if section_head.dxftype() != 'SECTION' or section_head.base_class[1] != (2, 'CLASSES'):
raise DXFStructureError("Critical structure error in CLASSES section.")
for cls_entity in entities:
self.register(cast(DXFClass, cls_entity))
def __getattr__(self, key):
try:
return self._sections[Sections.key(key)]
except KeyError: # internal exception
# DXFStructureError because a requested section is not present, maybe a typo, but usual a hint for an
# invalid DXF file.
raise DXFStructureError('{} section not found'.format(key.upper()))
def _get_extended_type(self, tags: Tags) -> Tuple[float, ...]:
value = tags.get_first_value(self.code)
if len(value) == 3:
if self.xtype is XType.point2d:
raise DXFStructureError("expected 2D point but found 3D point")
elif self.xtype is XType.point3d: # len(value) == 2
raise DXFStructureError("expected 3D point but found 2D point")
return value