Ë
    £èhX  ã                  óp   — d dl mZ d dlmZmZmZmZ d dlmZm	Z	 erd dl
mZ d dlmZ 	 	 d	 	 	 	 	 	 	 d	d„Zy)
é    )Úannotations)ÚIterableÚHashableÚTYPE_CHECKINGÚOptional)ÚDXFValueErrorÚDXFAttributeError)Ú	DXFEntity)ÚKeyFuncNc                ó  ‡— t        ‰|f«      rt        d«      ‚‰dk7  rˆfd„}|€t        d«      ‚t        «       }| D ]>  }|j                  sŒ	  ||«      }|€Œ|j                  |g «      }|j                  |«       Œ@ |S # t        $ r Y ŒNw xY w)ay  
    Groups a sequence of DXF entities by a DXF attribute like ``'layer'``,
    returns a dict with `dxfattrib` values as key and a list of entities
    matching this `dxfattrib`.
    A `key` function can be used to combine some DXF attributes (e.g. layer and
    color) and should return a hashable data type like a tuple of strings,
    integers or floats, `key` function example::

        def group_key(entity: DXFEntity):
            return entity.dxf.layer, entity.dxf.color

    For not suitable DXF entities return ``None`` to exclude this entity, in
    this case it's not required, because :func:`groupby` catches
    :class:`DXFAttributeError` exceptions to exclude entities, which do not
    provide layer and/or color attributes, automatically.

    Result dict for `dxfattrib` = ``'layer'`` may look like this::

        {
            '0': [ ... list of entities ],
            'ExampleLayer1': [ ... ],
            'ExampleLayer2': [ ... ],
            ...
        }

    Result dict for `key` = `group_key`, which returns a ``(layer, color)``
    tuple, may look like this::

        {
            ('0', 1): [ ... list of entities ],
            ('0', 3): [ ... ],
            ('0', 7): [ ... ],
            ('ExampleLayer1', 1): [ ... ],
            ('ExampleLayer1', 2): [ ... ],
            ('ExampleLayer1', 5): [ ... ],
            ('ExampleLayer2', 7): [ ... ],
            ...
        }

    All entity containers (modelspace, paperspace layouts and blocks) and the
    :class:`~ezdxf.query.EntityQuery` object have a dedicated :meth:`groupby`
    method.

    Args:
        entities: sequence of DXF entities to group by a DXF attribute or a
            `key` function
        dxfattrib: grouping DXF attribute like ``'layer'``
        key: key function, which accepts a :class:`DXFEntity` as argument and
            returns a hashable grouping key or ``None`` to ignore this entity

    z4Specify a dxfattrib or a key function, but not both.Ú c                ó:   •— | j                   j                  ‰«      S )N)ÚdxfÚget_default)ÚentityÚ	dxfattribs    €ú-lib/python3.12/site-packages/ezdxf/groupby.pyÚ<lambda>zgroupby.<locals>.<lambda>K   s   ø€ ˜VŸZ™Z×3Ñ3°IÔ>ó    zMno valid argument found, specify a dxfattrib or a key function, but not both.)Úallr   ÚdictÚis_aliver	   Ú
setdefaultÚappend)Úentitiesr   ÚkeyÚresultÚ
dxf_entityÚ	group_keyÚgroups    `     r   Úgroupbyr!      s¶   ø€ ôp ˆI�sÐÔÜØBó
ð 	
ð �B‚Û>ˆØ
€{Üðó
ð 	
ô
 /3«f€FÛˆ
Ø×"Ò"Øð	Ù˜J›ˆIð Ñ Ø×%Ñ% i°Ó4ˆEØ�L‰L˜Õ$ð ð €Møô !ò 	áð	ús   ÁB Â 	BÂB)r   N)r   zIterable[DXFEntity]r   Ústrr   zOptional[KeyFunc]Úreturnzdict[Hashable, list[DXFEntity]])Ú
__future__r   Útypingr   r   r   r   Úezdxf.lldxf.constr   r	   Úezdxf.entitiesr
   Úezdxf.eztypesr   r!   © r   r   Ú<module>r*      sR   ðõ #ß >Ó >ç >áÝ(Ý%ð
 Ø!ðPØ!ðPàðPð 
ðPð %ô	Pr   