# Path: core/ezdxf/lldxf/tags.py
# class Tags(list):
#     """ DXFTag() chunk as flat list. """
#     def write(self, stream):
#         write_tags(stream, self)
# 
#     @classmethod
#     def from_text(cls, text):
#         return cls(skip_comments(string_tagger(text)))
# 
#     def __copy__(self):
#         return self.__class__(DXFTag(*tag) for tag in self)
# 
#     clone = __copy__
# 
#     def get_handle(self):
#         """Get DXF handle. Raises ValueError if handle not exists.
# 
#         :returns: handle as hex-string like 'FF'
#         """
#         handle = ''
#         for tag in self:
#             if tag.code in (5, 105):
#                 handle = tag.value
#                 break
#         int(handle, 16)  # check for valid handle
#         return handle
# 
#     def replace_handle(self, new_handle):
#         """Replace existing handle.
#         """
#         for index, tag in enumerate(self):
#             if tag.code in (5, 105):
#                 self[index] = DXFTag(tag.code, new_handle)
#                 return
# 
#     def dxftype(self):
#         return self[0].value
# 
#     def has_tag(self, code):
#         return any(True for tag in self if tag.code == code)
# 
#     def find_first(self, code, default=ValueError):
#         """Returns value of first DXFTag(code, value) or default if default != ValueError, else raises ValueError.
#         """
#         for tag in self:
#             if tag.code == code:
#                 return tag.value
#         if default is ValueError:
#             raise ValueError(code)
#         else:
#             return default
# 
#     def get_first_tag(self, code, default=ValueError):
#         """Returns first DXFTag(code, value) or default if default != ValueError, else raises ValueError.
#         """
#         for tag in self:
#             if tag.code == code:
#                 return tag
#         if default is ValueError:
#             raise ValueError(code)
#         else:
#             return default
# 
#     def find_all(self, code):
#         """Returns a list of DXFTag(code, value).
#         """
#         return [tag for tag in self if tag.code == code]
# 
#     def tag_index(self, code, start=0, end=None):
#         """Return first index of DXFTag(code, value).
#         """
#         if end is None:
#             end = len(self)
#         index = start
#         while index < end:
#             if self[index].code == code:
#                 return index
#             index += 1
#         raise ValueError(code)
# 
#     def update(self, code, value):
#         """Update first existing tag, raises ValueError if tag not exists.
#         """
#         index = self.tag_index(code)
#         self[index] = DXFTag(code, value)
# 
#     def set_first(self, code, value):
#         """Update first existing DXFTag(code, value) or append a new
#         DXFTag(code, value).
# 
#         """
#         try:
#             self.update(code, value)
#         except ValueError:
#             self.append(DXFTag(code, value))
# 
#     def remove_tags(self, codes):
#         self[:] = [tag for tag in self if tag.code not in set(codes)]
# 
#     def collect_consecutive_tags(self, codes, start=0, end=None):
#         """Collect all consecutive tags with code in codes, start and end delimits the search range. A tag code not
#         in codes ends the process.
# 
#         Returns the collected tags in a collection of type Tag().
#         """
#         codes = frozenset(codes)
#         collected_tags = Tags()
#         if end is None:
#             end = len(self)
#         index = start
#         while index < end:
#             tag = self[index]
#             if tag.code in codes:
#                 collected_tags.append(tag)
#                 index += 1
#             else:
#                 break
#         return collected_tags
# 
# class CompressedTags(object):
#     """Store multiple tags, compressed by zlib, as one DXFTag(code, value). value is a CompressedString() object.
#     """
#     def __init__(self, code, tags):
#         self.code = code
#         self.value = CompressedString("".join(strtag2(tag) for tag in tags))
# 
#     def __getitem__(self, item):
#         if item == 0:
#             return self.code
#         elif item == 1:
#             return self.value
#         else:
#             raise IndexError
# 
#     def decompress(self):
#         return Tags.from_text(self.value.decompress())
# 
#     def write(self, stream):
#         stream.write(self.value.decompress())
# 
# Path: core/ezdxf/lldxf/const.py
# COMPRESSED_TAGS = -10


from .tags import Tags, CompressedTags
from .const import COMPRESSED_TAGS
# Purpose: default chunk
# Created: 12.03.2011
# Copyright (C) 2011, Manfred Moitzi
# License: MIT License
from __future__ import unicode_literals
__author__ = "mozman <mozman@gmx.at>"



class DefaultChunk(object):
    def __init__(self, tags, drawing):
        self.tags = tags
        self._drawing = drawing

    @property
    def dxffactory(self):
        return self._drawing.dxffactory

    @property
    def name(self):
        return self.tags[1].value.lower()

    def write(self, stream):
        self.tags.write(stream)


class CompressedDefaultChunk(DefaultChunk):
    def __init__(self, tags, drawing):
        compressed_tags = CompressedTags(COMPRESSED_TAGS, tags)

# Path: core/ezdxf/lldxf/tags.py
# class Tags(list):
#     """ DXFTag() chunk as flat list. """
#     def write(self, stream):
#         write_tags(stream, self)
# 
#     @classmethod
#     def from_text(cls, text):
#         return cls(skip_comments(string_tagger(text)))
# 
#     def __copy__(self):
#         return self.__class__(DXFTag(*tag) for tag in self)
# 
#     clone = __copy__
# 
#     def get_handle(self):
#         """Get DXF handle. Raises ValueError if handle not exists.
# 
#         :returns: handle as hex-string like 'FF'
#         """
#         handle = ''
#         for tag in self:
#             if tag.code in (5, 105):
#                 handle = tag.value
#                 break
#         int(handle, 16)  # check for valid handle
#         return handle
# 
#     def replace_handle(self, new_handle):
#         """Replace existing handle.
#         """
#         for index, tag in enumerate(self):
#             if tag.code in (5, 105):
#                 self[index] = DXFTag(tag.code, new_handle)
#                 return
# 
#     def dxftype(self):
#         return self[0].value
# 
#     def has_tag(self, code):
#         return any(True for tag in self if tag.code == code)
# 
#     def find_first(self, code, default=ValueError):
#         """Returns value of first DXFTag(code, value) or default if default != ValueError, else raises ValueError.
#         """
#         for tag in self:
#             if tag.code == code:
#                 return tag.value
#         if default is ValueError:
#             raise ValueError(code)
#         else:
#             return default
# 
#     def get_first_tag(self, code, default=ValueError):
#         """Returns first DXFTag(code, value) or default if default != ValueError, else raises ValueError.
#         """
#         for tag in self:
#             if tag.code == code:
#                 return tag
#         if default is ValueError:
#             raise ValueError(code)
#         else:
#             return default
# 
#     def find_all(self, code):
#         """Returns a list of DXFTag(code, value).
#         """
#         return [tag for tag in self if tag.code == code]
# 
#     def tag_index(self, code, start=0, end=None):
#         """Return first index of DXFTag(code, value).
#         """
#         if end is None:
#             end = len(self)
#         index = start
#         while index < end:
#             if self[index].code == code:
#                 return index
#             index += 1
#         raise ValueError(code)
# 
#     def update(self, code, value):
#         """Update first existing tag, raises ValueError if tag not exists.
#         """
#         index = self.tag_index(code)
#         self[index] = DXFTag(code, value)
# 
#     def set_first(self, code, value):
#         """Update first existing DXFTag(code, value) or append a new
#         DXFTag(code, value).
# 
#         """
#         try:
#             self.update(code, value)
#         except ValueError:
#             self.append(DXFTag(code, value))
# 
#     def remove_tags(self, codes):
#         self[:] = [tag for tag in self if tag.code not in set(codes)]
# 
#     def collect_consecutive_tags(self, codes, start=0, end=None):
#         """Collect all consecutive tags with code in codes, start and end delimits the search range. A tag code not
#         in codes ends the process.
# 
#         Returns the collected tags in a collection of type Tag().
#         """
#         codes = frozenset(codes)
#         collected_tags = Tags()
#         if end is None:
#             end = len(self)
#         index = start
#         while index < end:
#             tag = self[index]
#             if tag.code in codes:
#                 collected_tags.append(tag)
#                 index += 1
#             else:
#                 break
#         return collected_tags
# 
# class CompressedTags(object):
#     """Store multiple tags, compressed by zlib, as one DXFTag(code, value). value is a CompressedString() object.
#     """
#     def __init__(self, code, tags):
#         self.code = code
#         self.value = CompressedString("".join(strtag2(tag) for tag in tags))
# 
#     def __getitem__(self, item):
#         if item == 0:
#             return self.code
#         elif item == 1:
#             return self.value
#         else:
#             raise IndexError
# 
#     def decompress(self):
#         return Tags.from_text(self.value.decompress())
# 
#     def write(self, stream):
#         stream.write(self.value.decompress())
# 
# Path: core/ezdxf/lldxf/const.py
# COMPRESSED_TAGS = -10


# Path: core/ezdxf/lldxf/defaultchunk.py
from .tags import Tags, CompressedTags
from .const import COMPRESSED_TAGS

# Purpose: default chunk
# Created: 12.03.2011
# Copyright (C) 2011, Manfred Moitzi
# License: MIT License
from __future__ import unicode_literals
__author__ = "mozman <mozman@gmx.at>"



class DefaultChunk(object):
    def __init__(self, tags, drawing):
        self.tags = tags
        self._drawing = drawing

    @property
    def dxffactory(self):
        return self._drawing.dxffactory

    @property
    def name(self):
        return self.tags[1].value.lower()

    def write(self, stream):
        self.tags.write(stream)


class CompressedDefaultChunk(DefaultChunk):
    def __init__(self, tags, drawing):
        compressed_tags = CompressedTags(COMPRESSED_TAGS, tags)

        super(CompressedDefaultChunk, self).__init__(Tags((tags[0], tags[1], compressed_tags)), drawing)