
    5i%                         d dl mZmZmZmZ d dlZd dlmZ ddlm	Z	m
Z
mZmZmZmZ g dZdZd Zdd	Z	 	 dd
Zd ZddZy)    )print_functionunicode_literalsdivisionabsolute_importN)Mapping   )GREENBLUEYELLOWWHITEBOLDENDC))milisecondsi  )seconds<   )minutesr   )hours   )daysim  )yearsN) z\x00z\x01z\x02z\x03z\x04z\x05z\x06z\x07z\x08z\tz\nz\x0bz\x0cz\rz\x0ez\x0fz\x10z\x11z\x12z\x13z\x14z\x15z\x16z\x17z\x18z\x19z\x1az\x1bz\x1cz\x1dz\x1ez\x1fc                 6    d }t        j                  d||       S )z
    Escapes the nonprintable chars 0-31 and 127, and backslash;
    preferably with a friendly equivalent such as '
' if available, but
    otherwise with a Python-style backslashed hex escape.
    c                     t        | j                  d            dk(  ryt        | j                  d            dk(  ryt        t        | j                  d               S )Nr      z\x7f\   z\\)ordgroupREPLACEMENT_TABLE)matchobjs    y/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/utils/pretty_print.pyreplacerz'escape_unicode_string.<locals>.replacerL   sM    x~~a !S(x~~a !R' X^^A%6!788    z([\000-\037\134\177]))resub)ur    s     r   escape_unicode_stringr%   F   s    9 66-x;;r!   c                 T    ||gng dfd	 |        dj                        S )a/   Tree pretty printer.
    Expects trees to be given as mappings (dictionaries). Keys will be printed; values will be traversed if they are
    mappings. To preserve order, use collections.OrderedDict.

    Example:

        print format_tree(collections.OrderedDict({'foo': 0, 'bar': {'xyz': 0}}))

    c                 0   t        | j                               }t        t        |            D ]  }||   }|t        |      dz
  k(  rt        |      dkD  r|d d dz   }|d d dz   }n|d d dz   }|d d dz   }d}|j	                         D ]5  }|dk(  rj                  ||z          nj                  ||z          |dz  }7 t        | |   t              s|}	|t        |      dz
  k  rt        |      dkD  r|dd  dk(  r|d d dz   }	 
| |   |	dz           y )Nr   u
   └──     u
   ├── u   │   r   )listkeysrangelen
splitlinesappend
isinstancer   )treeprefixnodesinode	my_prefixmy_multiline_prefixnline	subprefix_formatformatted_trees             r   r;   zformat_tree.<locals>._format_   sA   TYY[!s5z" 	8A8DCJqL S[1_"3BK,6	&,SbkF&:#"3BK,6	&,SbkH&<#A) 6")))d*:;"))*=*DEQ $t*g."	s5z!|#FaF23K6<Q &sh 6IT
I$67)	8r!   
)r)   )join)r1   rootr;   r<   s     @@r   format_treer@   T   s0      $/dVRN8. DM99^$$r!   c                    t        |       dkD  rdgt        t        |       d         z  }n&dgt              dz   z  }ndgt              z  }g }.dgj                  D cg c]  }|d   	 c}       dddgz   lt        t                    D ]U  }t	        |         }	t        |	      |kD  r|	d|dz
   dz   }	|j                  |	       t        |   t        |	            ||<   W g }
| D ]  }g }t        t        |            D ]^  }t        t	        ||               }t        |      |kD  r|d|dz
   dz   }|j                  |       t        |   t        |            ||<   ` |
j                  |        d	 t               t               t               t               d
dD ]
  }d   |<    d   d<   fd} d       d      j                  fdD              z    d      z   g}t        |      dkD  rt        t        |            D cg c]"  } ||      d||   t        ||         z
  z  z   $ }}|j                   d       d      j                  |      z    d      z          |j                   d       d      j                  fd|D              z    d      z          |
D ]v  }t        t        |            D cg c]  }||   d||   t        ||         z
  z  z   ! }}|j                   d       d      j                  |      z    d      z          x |j                   d       d      j                  fd|D              z    d      z          |r5dj                  |      t        |      t        |      t        |      z   dz   fS dj                  |      S c c}w c c}w c c}w )z Table pretty printer.
    Expects tables to be given as arrays of arrays.

    Example:

        print format_table([[1, "2"], [3, "456"]], column_names=['A', 'B'])

    r   Nr   Rownamefloat)rC   typeu   …c                 2    t               | z   t               z   S N)r   r   )r4   s    r   borderzformat_table.<locals>.border   s    w{TV##r!   )booleanintegerrD   string)uint8int16uint16int32uint32int64rJ   doublec                     't               |    d      z   |    z   t               z   S t               t               z   |    z   t               z   S )NrE   )r   r   r   )r4   column_namescolumn_specstype_colormaps    r   col_headzformat_table.<locals>.col_head   sV    #6M,q/&*ABB\RS_TW[W]]]6EG#l1o5>>r!   u   ┌u   ┬c              3   4   K   | ]  } d       |z    ywu   ─N .0r4   rH   s     r   	<genexpr>zformat_table.<locals>.<genexpr>   s     9^a&-/9^   u   ┐ u   │u   ├u   ┼c              3   4   K   | ]  } d       |z    ywrY   rZ   r[   s     r   r]   zformat_table.<locals>.<genexpr>   s     AfVW&-PQ/Afr^   u   ┤u   └u   ┴c              3   4   K   | ]  } d       |z    ywrY   rZ   r[   s     r   r]   zformat_table.<locals>.<genexpr>   s     =bRSfUmAo=br^   u   ┘r=   )r-   r*   extendr,   strr/   maxr%   r
   r   r   r	   r>   sum)tablerT   rU   max_col_widthreport_dimensions
col_widthsmy_column_namescolr4   my_colmy_tablerowmy_rowmy_itemrW   formatted_tablepadded_column_names
padded_rowrH   rV   s    ``               @@r   format_tablert   y   s    5zA~S3tE{1~..
		!SC-12
		!S3|,,
OwLASS[AB!&89LHs<() 	<Aa)F6{]* 0q1E9""6*
1s6{;JqM	< H  s3x 	=A+CAK8G7|m+!"2=?3e;MM'"
1s7|<JqM	= 	 $ !% &#g$w(M D 4(3a4+G4M(? e}ve}'9'99^S]9^'^^aghmannoO
?abghkl{h|b}~]^x{S*Q-OTUDV@W2W-XX~~ve}ve}/A/ABU/VVY_`eYffgve}ve}/A/AAf[eAf/ffiopuivvw _HMcRUhX1c!fsJqM#c!f+$=>>X
Xve}ve}/A/A*/MMPVW\P]]^_ 6%=6%=+=+==bWa=b+bbeklqerrsyy)3+?ZSVWaSbAbefAfffyy))g BN 
 Ys   +O%'O"$Oc                 
   t        j                  dj                  |      dj                  |      | t         j                        }t        j                  dj                  |      t         j                        }|j                  |      r3|j                  dj                  |      |      }|j                  |      r3t        j                  dj                  |      dj                  |      |t         j                        }|S )z
    Flattens all arrays with the same name in the JSON string

    :param json_string: JSON string
    :type json_string: str
    :param array_name: Array name to flatten
    :type array_name: str
    z"{}": \[?
\s*z"{}": [)flagsz"{}": \[(.*)(?<=,)?
\s*z
"{}": [\1 z"{}": \[(.*)?
\s*\]z
"{}": [\1])r"   r#   format	MULTILINEcompilesearch)json_string
array_nameresultflatten_regexps       r   flatten_json_arrayr      s     VV(//
;Y=M=Mj=Y[fnpnznz{FZZ > E Ej QY[YeYefN



'##M$8$8$DfM 


'VV/66zBMDXDXYcDdfltv  uA  uA  BFMr!   c                 X   |r	t         dd nt         }|	|d   d   }n|t        d |      vrt        d      | dk(  rd|d   d   z   S d}|D ]M  \  }}| dk(  r nC||k(  rd}|r| |z  n| }|dk7  r#t        |      d	z   |r
|dk(  r|dd n|z   d
z   |z   }| n| |z  } O |j	                  d
      S )a  
    Formats timedelta (duration) to a human readable form

    :param timedelta: Duration in miliseconds or seconds (see in_seconds)
    :type timedelta: int
    :param in_seconds: Whether the given duration is in seconds
    :type in_seconds: bool
    :param largest_units: Largest units to be displayed. Allowed values are miliseconds, seconds, minutes, hours, days and years
    :type largest_units: str
    :param auto_singulars: Automatically use singular when value of given units is 1
    :type auto_singulars: bool
    r   Nr   c                     | d   S )Nr   rZ   )xs    r   <lambda>z"format_timedelta.<locals>.<lambda>   s
    AaD r!   zInvalid largest units specifiedz0  r_   z, )
TIME_UNITSmap
ValueErrorrc   strip)		timedelta
in_secondslargest_unitsauto_singularsunitsout_strrC   diviservals	            r   format_timedeltar      s     )JqrNjEb	!	c.%8	8:;;A~eAhqk!!G g>D G%,i'!)!8#hn^qSb	VZ[^bbellG?g	  ==r!   rG   )NN    F)FNF)
__future__r   r   r   r   r"   collections.abcr   printingr	   r
   r   r   r   r   r   r   r%   r@   rt   r   r   rZ   r!   r   <module>r      sP   ( S R 	 # > >
! F<#%J MO#(F*P"*r!   