o
    i                     @   st   d Z ddlmZmZmZmZ ddlmZmZm	Z	m
Z
 edZedddZG dd de	e ZG d	d
 d
ee ZdS )z`Code for multi-value data elements values,
or any list of items that must all be the same type.
    )overloadAnycastTypeVar)IterableCallableMutableSequenceIteratorTSelfConstrainedList)boundc                   @   s  e Zd ZdZd*dee dB ddfddZdeddfdd	Zd
ee	B ddfddZ
dee ddfddZdedefddZed
e	defddZed
edee fddZd
ee	B dee eB fddZdedee defddZde	deddfddZdee fddZde	fdd Zdedefd!d"Zed#e	deddfd$d%Zed#edee ddfd&d%Zd
ee	B dee eB ddfd'd%Zdedefd(d)ZdS )+r   z2A list of items that must all be of the same type.Niterablereturnc                    s*   g  _ |dur fdd|D  _ dS dS )zCreate a new ConstrainedList.

        Parameters
        ----------
        iterable : Iterable[T]
            An iterable such as a :class:`list` or :class:`tuple` containing
            the items to be used to create the ``ConstrainedList``.
        Nc                       g | ]}  |qS  	_validate.0itemselfr   F/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/multival.py
<listcomp>       z,ConstrainedList.__init__.<locals>.<listcomp>_list)r   r   r   r   r   __init__   s   	zConstrainedList.__init__r   c                 C   s   | j | | dS )zAppend an item.N)r   appendr   r   r   r   r   r   r      s   zConstrainedList.appendindexc                 C   s   | j |= dS )zRemove the item(s) at `index`.Nr   r   r!   r   r   r   __delitem__"   s   zConstrainedList.__delitem__valc                    s0   t |ds	td j fdd|D  dS )z;Extend using an iterable containing the same types of item.__iter__An iterable is requiredc                    r   r   r   r   r   r   r   r   +   r   z*ConstrainedList.extend.<locals>.<listcomp>N)hasattr	TypeErrorr   extend)r   r$   r   r   r   r)   &   s   
zConstrainedList.extendotherc                 C   s
   | j |kS )z,Return ``True`` if `other` is equal to self.r   r   r*   r   r   r   __eq__-      
zConstrainedList.__eq__c                 C      d S Nr   r"   r   r   r   __getitem__1      zConstrainedList.__getitem__c                 C   r.   r/   r   r"   r   r   r   r0   5   r1   c                 C   s
   | j | S )zReturn item(s) from self.r   r"   r   r   r   r0   9   r-   r   c                    s2   t |ds	td  j fdd|D 7  _ S )zImplement += [T, ...].r%   r&   c                    r   r   r   r   r   r   r   r   B   r   z,ConstrainedList.__iadd__.<locals>.<listcomp>)r'   r(   r   r+   r   r   r   __iadd__=   s   
zConstrainedList.__iadd__positionc                 C   s   | j || | dS )zInsert an `item` at `position`.N)r   insertr   )r   r3   r   r   r   r   r4   E   s   zConstrainedList.insertc                 c   s    | j E dH  dS )zYield items.Nr   r   r   r   r   r%   I   s   zConstrainedList.__iter__c                 C   s
   t | jS )z%Return the number of contained items.)lenr   r   r   r   r   __len__M   r-   zConstrainedList.__len__c                 C   s
   | j |kS )z0Return ``True`` if `other` is not equal to self.r   r+   r   r   r   __ne__Q   r-   zConstrainedList.__ne__idxc                 C   r.   r/   r   r   r8   r$   r   r   r   __setitem__U   r1   zConstrainedList.__setitem__c                 C   r.   r/   r   r9   r   r   r   r:   Y   r1   c                    sZ   t |trttt |} j| fdd|D  dS tt|} j| | dS )zAdd item(s) at `index`.c                    r   r   r   r   r   r   r   r   a   r   z/ConstrainedList.__setitem__.<locals>.<listcomp>N)
isinstanceslicer   r   r
   r   r:   r   )r   r!   r$   r   r   r   r:   ]   s
   
 
c                 C   s   t dt| j d)zCReturn items that have been validated as being of the expected type'z!._validate()' must be implemented)NotImplementedErrortype__name__r    r   r   r   r   f   s   zConstrainedList._validater/   )r@   
__module____qualname____doc__r   r
   r   r   r<   intr#   r)   r   r,   r   r0   r   r   r2   r4   r	   r%   r6   r7   r:   r   r   r   r   r   r      s.    "	c                       sz   e Zd ZdZdeegef dee ddf fddZdeeB defd	d
Z	dededdfddZ
defddZeZ  ZS )
MultiValuea$  Class to hold any multi-valued DICOM value, or any list of items that
    are all of the same type.

    This class enforces that any items added to the list are of the correct
    type, by calling the constructor on any items that are added. Therefore,
    the constructor must behave nicely if passed an object that is already its
    type. The constructor should raise :class:`TypeError` if the item cannot be
    converted.

    Note, however, that DS and IS types can be a blank string ``''`` rather
    than an instance of their classes.
    type_constructorr   r   Nc                    s   || _ t | dS )a  Create a new :class:`MultiValue` from an iterable and ensure each
        item in the :class:`MultiValue` has the same type.

        Parameters
        ----------
        type_constructor : callable
            A constructor for the required type for all items. Could be
            the class, or a factory function. Takes a single parameter and
            returns the input as the desired type (or raises an appropriate
            exception).
        iterable : iterable
            An iterable (e.g. :class:`list`, :class:`tuple`) of items to
            initialize the :class:`MultiValue` list. Each item in the iterable
            is passed to `type_constructor` and the returned value added to
            the :class:`MultiValue`.
        N)_constructorsuperr   )r   rF   r   	__class__r   r   r   {   s   zMultiValue.__init__r   c                 C   s
   |  |S r/   )rG   r    r   r   r   r      s   
zMultiValue._validateargskwargsc                 O   s   | j j|i | d S r/   )r   sort)r   rK   rL   r   r   r   rM      s   zMultiValue.sortc                 C   s(   | sdS dd | D }dd | dS )N c                 s   s,    | ]}t |ttB r|nt|V  qd S r/   )r;   strbytes)r   xr   r   r   	<genexpr>   s   * z%MultiValue.__str__.<locals>.<genexpr>[z, ])join)r   linesr   r   r   __str__   s   zMultiValue.__str__)r@   rA   rB   rC   r   r   r
   r   r   r   rM   rO   rW   __repr____classcell__r   r   rI   r   rE   m   s    rE   N)rC   typingr   r   r   r   collections.abcr   r   r   r	   r
   r   r   rE   r   r   r   r   <module>   s   _