o
    iH                     @   s  U d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 dZzddlZW n ey4   dZY nw erKddlmZ dd	lmZ G d
d deZdaedZedate  eed< d.dededdfddZedd daeed< 	 daed ed< 	 i aee ef ed< 	 d/ddZ!d0deddfddZ"d0deddfddZ#da$	 dZ%	 dZ&	 dZ'	 dZ(	 dZ)	 d Z*	 G d!d" d"Z+e+ Z,	 ede
fd#d$Z-ede
fd%d&Z.dZ/	 dZ0	 dZ1	 dZ2	 dZ3	 ddl4m5  m6Z7 ddl8m5  m9Z9 ddl:m5  m;Z; ddl<m5  m=Z> ddl?m5  m@Z@ ddlAm5  mBZB e7e@e;e>eBe9gZ5	 dZC	 dZD	 d'aE	 d'ZF	 erNeG d(v r@daneG d)v rJdaneHd*d0d+eddfd,d-ZItr`eI  dS dS )1zPydicom configuration options.    N)contextmanager)OptionalAnyTYPE_CHECKING)	GeneratorTF)RawDataElement)Protocolc                   @   s"   e Zd ZdddeddfddZdS )ElementCallbackraw_elemr   kwargsreturnc                 K   s   d S N )selfr
   r   r   r   D/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/config.py__call__   s   zElementCallback.__call__N)__name__
__module____qualname__r   r   r   r   r   r   r	      s    r	   PYDICOM_FUTUREpydicom	debuggingdebug_ondefault_handlerr   c                 C   sV   |rt  }t d}|| t| | r!tt j dadS tt j	 dadS )a  Turn on/off debugging of DICOM file reading and writing.

    When debugging is on, file location and details about the elements read at
    that location are logged to the 'pydicom' logger using Python's
    :mod:`logging`
    module.

    Parameters
    ----------
    debug_on : bool, optional
        If ``True`` (default) then turn on debugging, ``False`` to turn off.
    default_handler : bool, optional
        If ``True`` (default) then use :class:`logging.StreamHandler` as the
        handler for log messages.
    z%(message)sTFN)
loggingStreamHandler	FormattersetFormatterlogger
addHandlersetLevelDEBUGr   WARNING)r   r   handler	formatterr   r   r   debug)   s   


r%   use_DS_decimaldata_element_callbackdata_element_callback_kwargsc                   C   s   da i adS )zReset the :func:`data_element_callback` function to the default.

    .. deprecated:: 3.0

        ``reset_data_element_callback()`` will be removed in v4.0, use
        :meth:`pydicom.hooks.Hooks.reset` instead.
    N)r'   r(   r   r   r   r   reset_data_element_callbackp   s   
r)   	use_numpyc                 C   s   t r| rtd| adS )aF  Set whether multi-valued elements with VR of **DS** will be numpy arrays

    .. versionadded:: 2.0

    Parameters
    ----------
    use_numpy : bool, optional
        ``True`` (default) to read multi-value **DS** elements
        as :class:`~numpy.ndarray`, ``False`` to read multi-valued **DS**
        data elements as type :class:`~python.mulitval.MultiValue`

        Note: once a value has been accessed, changing this setting will
        no longer change its type

    Raises
    ------
    ValueError
        If :data:`use_DS_decimal` and `use_numpy` are both True.

    zGCannot use numpy arrays to read DS elements if `use_DS_decimal` is TrueN)r&   
ValueErroruse_DS_numpy)r*   r   r   r   DS_numpy~   s
   r-   use_Decimal_booleanc                 C   s@   | a t r
tr
tdddl}t r|jj|j_dS |jj|j_dS )a#  Set DS class to be derived from :class:`decimal.Decimal` or
    :class:`float`.

    If this function is never called, the default in *pydicom* >= 0.9.8
    is for DS to be based on :class:`float`.

    Parameters
    ----------
    use_Decimal_boolean : bool, optional
        ``True`` (default) to derive :class:`~pydicom.valuerep.DS` from
        :class:`decimal.Decimal`, ``False`` to derive it from :class:`float`.

    Raises
    ------
    ValueError
        If `use_Decimal_boolean` and :data:`use_DS_numpy` are
        both ``True``.
    z6Cannot set use_DS_decimal True if use_DS_numpy is Truer   N)r&   r,   r+   pydicom.valuerepvaluerep	DSdecimalDSclassDSfloat)r.   r   r   r   r   
DS_decimal   s   r4         c                   @   s   e Zd ZdZdddZedefddZejdeddfd	dZedefd
dZ	e	jdeddfddZ	edefddZ
e
jdeddfddZ
edefddZejdeddfddZdS )Settingsz|Collection of several configuration values.
    Accessed via the singleton :attr:`settings`.

    .. versionadded:: 2.3
    r   Nc                 C   s$   d | _ trtnd | _d| _d| _d S )NTi    )_reading_validation_mode_use_futureRAISE_writing_validation_mode_infer_sq_for_un_vr_buffered_read_sizer   r   r   r   __init__   s   
zSettings.__init__c                 C      | j S )zGet or set the chunk size when reading from buffered
        :class:`~pydicom.dataelem.DataElement` values.

        Parameters
        ----------
        size : int
            The chunk size to use, must be greater than 0 (default 8192).
        )r=   r>   r   r   r   buffered_read_size  s   
zSettings.buffered_read_sizesizec                 C   s   |dkrt d|| _d S )Nr   z$The read size must be greater than 0)r+   r=   )r   rB   r   r   r   rA     s   
c                 C      | j du rtr	tS tS | j S )a  Defines behavior of validation while reading values, compared with
        the DICOM standard, e.g. that DS strings are not longer than
        16 characters and contain only allowed characters.

        * :attr:`WARN` will emit a warning in the case of an invalid value (default)
        * :attr:`RAISE` will raise an error instead
        * :attr:`IGNORE` will bypass the validation (with the exception of some
          encoding errors).
        N)r8   enforce_valid_valuesr:   WARNr>   r   r   r   reading_validation_mode  s   
z Settings.reading_validation_modevaluec                 C   
   || _ d S r   )r8   r   rG   r   r   r   rF   $     
c                 C   rC   )z{Defines behavior for value validation while writing a value.
        See :attr:`Settings.reading_validation_mode`.
        N)r;   rD   r:   rE   r>   r   r   r   writing_validation_mode(  s   
z Settings.writing_validation_modec                 C   rH   r   )r;   rI   r   r   r   rK   1  rJ   c                 C   r@   )ah  If ``True``, and the VR of a known data element is encoded as
        **UN** in an explicit encoding for an undefined length data element,
        the VR is changed to SQ per PS 3.5, section 6.2.2. Can be set to
        ``False`` where the content of the tag shown as **UN** is not DICOM
        conformant and would lead to a failure if accessing it.
        r<   r>   r   r   r   infer_sq_for_un_vr5  s   zSettings.infer_sq_for_un_vrc                 C   rH   r   rL   rI   r   r   r   rM   ?  rJ   r   N)r   r   r   __doc__r?   propertyintrA   setterrF   rK   boolrM   r   r   r   r   r7      s&    

	r7   c                  c   sB    t j} t j}ztt _tt _dV  W | t _|t _dS | t _|t _w )zContext manager to temporarily disable value validation
    both for reading and writing.
    Can be used for performance reasons if the values are known to be valid.
    N)settingsr8   r;   IGNORErF   rK   )reading_modewriting_moder   r   r   disable_value_validationL  s   
rX   c                  c   s*    t j} ztt _dV  W | t _dS | t _w )zNContext manager to temporarily enably strict value validation
    for reading.N)rT   r8   r:   rF   )original_reading_moder   r   r   strict_reading]  s   rZ   rE   )trueyeson1)falsenooff0zKUnknown setting for environment variable PYDICOM_FUTURE. Use True or False.enable_futurec                 C   s(   | rda datt_dS da dadt_dS )aN  Imitate the behavior for the next major version of *pydicom*.

    .. versionadded:: 2.1

    This can be used to ensure your code is "future-proof" for known
    upcoming changes in the next major version of *pydicom*. Typically,
    deprecations become errors, and default values of config flags may change.

    Parameters
    ----------
    enable_future: bool
        Set ``True`` (default) to emulate future pydicom behavior,
        ``False`` to reset to current pydicom behavior.

    See also
    --------
    :attr:`INVALID_KEYWORD_BEHAVIOR`
    :attr:`INVALID_KEY_BEHAVIOR`

    Tr:   FrE   N)r9   INVALID_KEYWORD_BEHAVIORr:   rT   r;   )rc   r   r   r   future_behavior(  s   

re   )TTrN   )T)JrO   r   os
contextlibr   typingr   r   r   collections.abcr   
have_numpynumpyImportErrorpydicom.dataelemr   r   r	   r9   getenv_use_future_env	getLoggerr   r   NullHandlerrS   __annotations__r%   r&   r'   r(   dictstrr)   r-   r4   r,   use_IS_numpyallow_DS_floatrD   rU   rE   r:   r7   rT   rX   rZ   convert_wrong_length_to_UNdatetime_conversionuse_none_as_empty_text_VR_valuereplace_un_with_known_vrshow_file_meta)pydicom.pixel_data_handlers.numpy_handlerpixel_data_handlersnumpy_handler
np_handler'pydicom.pixel_data_handlers.rle_handlerrle_handler*pydicom.pixel_data_handlers.pillow_handlerpillow_handler+pydicom.pixel_data_handlers.jpeg_ls_handlerjpeg_ls_handlerjpegls_handler(pydicom.pixel_data_handlers.gdcm_handlergdcm_handler-pydicom.pixel_data_handlers.pylibjpeg_handlerpylibjpeg_handlerAPPLY_J2K_CORRECTIONSassume_implicit_vr_switchrd   INVALID_KEY_BEHAVIORlowerr+   re   r   r   r   r   <module>   s   


!
#	T'
!
