
    Og                    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    R/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/groupby.py<lambda>z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   