o
    i                  	   @   s   d Z ddlmZmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 er*ddl
mZ dd	d
edd	fddZ		ddedeedf deddfddZdd	d
edd	fddZe	je	je	jffdeedf ddfddZdS )z/Code to fix non-standard dicom issues in files
    )TYPE_CHECKINGAny)config)datadict)valuesVR)RawDataElementraw_elemr	   kwargsreturnc                 K   s   | }d}| j du r&zt| j}W n ty   |d }Y nw ||d v }n| j |d v }|rfd}| jdur`|d dkrW| j }t| jt| }||d dd|  }n	| j|d d}| j	|d}|S )	z@Used by fix_separator as the callback function from read_datasetFNprocess_unknown_VRsfor_VRsinvalid_separator       \)value)
r   r   dictionary_VRtagKeyErrorr   striplenreplace_replace)r
   r   
return_valtry_replacevr	new_valuestripped_valstrip_count r    H/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/util/fixer.pyfix_separator_callback   s.   


r"   DSISTr   r   .r   Nc                 C   s   t t_| ||dt_dS )aI  A callback function to fix RawDataElement values using
    some other separator than the dicom standard backslash character

    Parameters
    ----------
    invalid_separator : bytes
        A single byte to replace with dicom backslash, in raw data element
        values before they have been decoded or processed by pydicom
    for_VRs : list, optional
        A list of VRs for which the replacement will be done.
        If the VR is unknown (for example, if a private element),
        then process_unknown_VR is used to determine whether to replace or not.
    process_unknown_VRs: bool, optional
        If True (default) then attempt the fix even if the VR is not known.

    Returns
    -------
    No return value.  However, the callback function will return either
    the original RawDataElement instance, or a fixed one.
    r   r   r   N)r"   r   data_element_callbackdata_element_callback_kwargsr&   r    r    r!   fix_separator5   s
   r)   c                 K   sv   | j d u r| S z
t| j |  W | S  ty:   |d D ]}zt||  W n	 ty/   Y qw | j|d} qY | S w )Nwith_VRsr   )r   r   convert_value
ValueErrorr   )r
   r   r   r    r    r!   fix_mismatch_callbackV   s    
	r-   r*   c                 C   s   t t_d| it_dS )a%  A callback function to check that RawDataElements are translatable
    with their provided VRs.  If not, re-attempt translation using
    some other translators.

    Parameters
    ----------
    with_VRs : Tuple[str]
        A tuple of VR strings to attempt if the raw data element value cannot
        be translated with the raw data element's VR. Default
        ``('PN', 'DS', 'IS')``.

    Returns
    -------
    No return value.  The callback function will return either
    the original RawDataElement instance, or one with a fixed VR.
    r*   N)r-   r   r'   r(   )r*   r    r    r!   fix_mismatchi   s   r.   )r#   T)__doc__typingr   r   pydicomr   r   r   pydicom.valuerepr   pydicom.dataelemr	   r"   bytestuplestrboolr)   r-   PNr$   r%   r.   r    r    r    r!   <module>   sD   
'

!
.