# Path: core/ezdxf/tools/c23.py
# PY3 = sys.version_info.major > 2
# def isstring(s):
# 
# Path: core/ezdxf/lldxf/types.py
# def strtag(tag):
#     return TAG_STRING_FORMAT % tag
# 
# Path: core/ezdxf/lldxf/tags.py
# COMMENT_CODE = 999
# def write_tags(stream, tags):
# def text2tags(text):
#     def __init__(self):
#     def DWGCODEPAGE(self, value):
#     def ACADVER(self, value):
#     def HANDSEED(self, value):
# def dxf_info(stream):
#     def write(self, stream):
#     def from_text(cls, text):
#     def __copy__(self):
#     def get_handle(self):
#     def replace_handle(self, new_handle):
#     def dxftype(self):
#     def has_tag(self, code):
#     def find_first(self, code, default=ValueError):
#     def get_first_tag(self, code, default=ValueError):
#     def find_all(self, code):
#     def tag_index(self, code, start=0, end=None):
#     def update(self, code, value):
#     def set_first(self, code, value):
#     def remove_tags(self, codes):
#     def collect_consecutive_tags(self, codes, start=0, end=None):
#     def __init__(self, tags, splitcode=0):
#     def _build_groups(self, tags, splitcode):
#         def append(tag):  # first do nothing, skip tags in front of the first split tag
#     def get_name(self, index):
#     def from_text(cls, text, splitcode=0):
# def strip_tags(tags, codes):
#     def __init__(self, code, tags):
#     def __getitem__(self, item):
#     def decompress(self):
#     def write(self, stream):
# class DXFInfo(object):
# class Tags(list):
# class TagGroups(list):
# class CompressedTags(object):


from collections import OrderedDict
from ..tools.c23 import ustr
from ..lldxf.types import strtag
from ..lldxf.tags import TagGroups, Tags, DXFStructureError
        for tag, value in self.properties:
            stream.write("  9\n$CUSTOMPROPERTYTAG\n  1\n%s\n" % tag)
            stream.write("  9\n$CUSTOMPROPERTY\n  1\n%s\n" % value)


class HeaderSection(object):
    MIN_HEADER_TAGS = Tags.from_text(MIN_HEADER_TEXT)
    name = 'header'

    def __init__(self, tags=None):
        if tags is None:
            tags = self.MIN_HEADER_TAGS
        self.hdrvars = OrderedDict()
        self.custom_vars = CustomVars()
        self._build(tags)

    def set_headervar_factory(self, factory):
        self._headervar_factory = factory

    def __contains__(self, key):
        return key in self.hdrvars

    def _build(self, tags):
        if tags[0] != (0, 'SECTION') or \
           tags[1] != (2, 'HEADER') or \
           tags[-1] != (0, 'ENDSEC'):
           raise DXFStructureError("Critical structure error in HEADER section.")

        if len(tags) == 3:  # DXF file with empty header section
            return

# Path: core/ezdxf/tools/c23.py
# PY3 = sys.version_info.major > 2
# def isstring(s):
# 
# Path: core/ezdxf/lldxf/types.py
# def strtag(tag):
#     return TAG_STRING_FORMAT % tag
# 
# Path: core/ezdxf/lldxf/tags.py
# COMMENT_CODE = 999
# def write_tags(stream, tags):
# def text2tags(text):
#     def __init__(self):
#     def DWGCODEPAGE(self, value):
#     def ACADVER(self, value):
#     def HANDSEED(self, value):
# def dxf_info(stream):
#     def write(self, stream):
#     def from_text(cls, text):
#     def __copy__(self):
#     def get_handle(self):
#     def replace_handle(self, new_handle):
#     def dxftype(self):
#     def has_tag(self, code):
#     def find_first(self, code, default=ValueError):
#     def get_first_tag(self, code, default=ValueError):
#     def find_all(self, code):
#     def tag_index(self, code, start=0, end=None):
#     def update(self, code, value):
#     def set_first(self, code, value):
#     def remove_tags(self, codes):
#     def collect_consecutive_tags(self, codes, start=0, end=None):
#     def __init__(self, tags, splitcode=0):
#     def _build_groups(self, tags, splitcode):
#         def append(tag):  # first do nothing, skip tags in front of the first split tag
#     def get_name(self, index):
#     def from_text(cls, text, splitcode=0):
# def strip_tags(tags, codes):
#     def __init__(self, code, tags):
#     def __getitem__(self, item):
#     def decompress(self):
#     def write(self, stream):
# class DXFInfo(object):
# class Tags(list):
# class TagGroups(list):
# class CompressedTags(object):


# Path: core/ezdxf/sections/header.py
from collections import OrderedDict
from ..tools.c23 import ustr
from ..lldxf.types import strtag
from ..lldxf.tags import TagGroups, Tags, DXFStructureError

        for tag, value in self.properties:
            stream.write("  9\n$CUSTOMPROPERTYTAG\n  1\n%s\n" % tag)
            stream.write("  9\n$CUSTOMPROPERTY\n  1\n%s\n" % value)


class HeaderSection(object):
    MIN_HEADER_TAGS = Tags.from_text(MIN_HEADER_TEXT)
    name = 'header'

    def __init__(self, tags=None):
        if tags is None:
            tags = self.MIN_HEADER_TAGS
        self.hdrvars = OrderedDict()
        self.custom_vars = CustomVars()
        self._build(tags)

    def set_headervar_factory(self, factory):
        self._headervar_factory = factory

    def __contains__(self, key):
        return key in self.hdrvars

    def _build(self, tags):
        if tags[0] != (0, 'SECTION') or \
           tags[1] != (2, 'HEADER') or \
           tags[-1] != (0, 'ENDSEC'):
           raise DXFStructureError("Critical structure error in HEADER section.")

        if len(tags) == 3:  # DXF file with empty header section
            return

        groups = TagGroups(tags[2:-1], splitcode=9)