
    h                    ~    S SK Jr  S SKJrJrJrJr  S SKJrJ	r	  \(       a  S SK
Jr  S SKJr    S       S	S jjrg)
    )annotations)IterableHashableTYPE_CHECKINGOptional)DXFValueErrorDXFAttributeError)	DXFEntity)KeyFuncNc                F  ^ [        TU45      (       a  [        S5      eTS:w  a  U4S jnUc  [        S5      e[        5       nU  HG  nUR                  (       d  M   U" U5      nUc  M$  UR                  U/ 5      nUR                  U5        MI     U$ ! [         a     MZ  f = f)a  
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                :   > U R                   R                  T5      $ )N)dxfget_default)entity	dxfattribs    ?/var/www/html/env/lib/python3.13/site-packages/ezdxf/groupby.py<lambda>groupby.<locals>.<lambda>K   s    VZZ33I>    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 IsB
 	
 B>
{
 	

 /3fF
""	JI  %%i4ELL$  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   