def _build(self, tags: Iterator[DXFTag]) -> None: section_tag = next(tags) name_tag = next(tags) if section_tag != (0, 'SECTION') or name_tag != (2, 'HEADER'): raise DXFStructureError( "Critical structure error in HEADER section.") groups = group_tags(header_validator(tags), splitcode=9) custom_property_stack = [] # collect $CUSTOMPROPERTY/TAG for group in groups: name = group[0].value value = group[1] if name in ('$CUSTOMPROPERTYTAG', '$CUSTOMPROPERTY'): custom_property_stack.append(value.value) else: self.hdrvars[name] = HeaderVar(value) custom_property_stack.reverse() while len(custom_property_stack): try: self.custom_vars.append(tag=custom_property_stack.pop(), value=custom_property_stack.pop()) except IndexError: # internal exception break
def load_tags(self, tags: Iterator[DXFTag]) -> None: """ Constructor to generate header variables loaded from DXF files (untrusted environment) Args: tags: DXF tags as Tags() or ExtendedTags() """ tags = tags or self.MIN_HEADER_TAGS section_tag = next(tags) name_tag = next(tags) if section_tag != (0, 'SECTION') or name_tag != (2, 'HEADER'): raise DXFStructureError("Critical structure error in HEADER section.") groups = group_tags(header_validator(tags), splitcode=9) custom_property_stack = [] # collect $CUSTOMPROPERTY/TAG for group in groups: name = group[0].value value = group[1] if name in ('$CUSTOMPROPERTYTAG', '$CUSTOMPROPERTY'): custom_property_stack.append(value.value) else: self.hdrvars[name] = HeaderVar(value) custom_property_stack.reverse() while len(custom_property_stack): try: self.custom_vars.append(tag=custom_property_stack.pop(), value=custom_property_stack.pop()) except IndexError: # internal exception break
def test_invalid_header_structure(): tags = Tags.from_text(INVALID_HEADER_STRUCTURE) with pytest.raises(ezdxf.DXFStructureError): list(header_validator(tags))
def test_invalid_header_var_name(): tags = Tags.from_text(INVALID_HEADER_VAR_NAME) with pytest.raises(ezdxf.DXFValueError): list(header_validator(tags))
def test_valid_header(): tags = Tags.from_text(TESTHEADER)[2:-1] result = list(header_validator(tags)) assert 8 == len(result)