o
    i7                     @   s`  d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 er&ddl
mZ dedefd	d
Z		d#deeB ejB dededB defddZ	d#dedededB defddZ			d$dedededB dedef
ddZ	d%dddededdfddZedkrejd  ZdZdZeejd!kreejd! Zeejd"kreejd" Zeeeee dS dS )&z7Utility functions used in debugging writing and reading    )BytesION)BinaryIOTYPE_CHECKING)VR)Datasetordchrreturnc                 C   s.   d|   k r
dk rn dS | dkrt | S dS )z<Return a printable character, or '.' for non-printable ones.   ~   \   .)chr)r    r   G/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/util/dump.pyprint_character   s
   r   filenamestart_addressstop_addressc                 C   s:   t | d}t|||W  d   S 1 sw   Y  dS )zDDump out the contents of a file to a standard hex dump 16 bytes widerbN)openhexdump)r   r   r   fr   r   r   filedump   s   
$r   datac                 C   s   t t| ||S )z-Return a hex string representation of `data`.)r   r   )r   r   r   r   r   r   datadump"   s   r   Tr   show_addressc           
      C   s   g }t | ddd}|rt |d}| | 	 |  }|r%||kr%n@| d}|s-n8g }|r>||d| dd dd	d
 |D }	||	d |ddd
 |D  |d| qd|S )aB  Return a formatted string of hex bytes and characters in data.

    This is a utility function for debugging file writing.

    Parameters
    ----------
    f : BinaryIO
        The file-like to dump.
    start_address : int, optional
        The offset where the dump should start (default ``0``)
    stop_address : int, optional
        The offset where the dump should end, by default the entire file will
        be dumped.
    show_address : bool, optional
        If ``True`` (default) then include the offset of each line of output.

    Returns
    -------
    str
    r      XT   0   c                 S   s   g | ]}|d qS )02Xr   .0xr   r   r   
<listcomp>\       zhexdump.<locals>.<listcomp>z<49 c                 S   s   g | ]}t |qS r   )r   r#   r   r   r   r&   `   r'   
)lenseektellreadappendjoin)
r   r   r   r   smax_offset_lenoffsetr   currentbr   r   r   r   )   s*   


r   r    dsr   indent_levelindent_charsc              	   C   s   || }||d  }| D ]8}|j t jkr<t| |j d|j dt|j d |jD ]}t||d  t|d  q+qt|t|  qdS )a  Print a dataset directly, with indented levels.

    This is just like Dataset._pretty_str, but more useful for debugging as it
    prints each item immediately rather than composing a string, making it
    easier to immediately see where an error in processing a dataset starts.

       r!   z -- z item(s)z	---------N)	r   SQprinttagnamer*   valuepretty_printrepr)r5   r6   r7   indentnext_indentelemdatasetr   r   r   r>   g   s   (
r>   __main__r8   r      )r   N)r   NT)r   r    )__doc__ior   ossystypingr   r   pydicom.valuerepr   pydicom.datasetr   intstrr   bytesPathLiker   r   boolr   r>   __name__argvr   r   r   r*   evalr:   r   r   r   r   <module>   s   


	
?

