
    6Dh[B              	       2   S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
JrJrJr  SrSrSrSrS	rS
rSrSrSrSSSSSSSSS.rS rS rS rS r " S S\R8                  5      r " S S\5      rS r S  r!S)S! jr"S" r#S# r$S$ r%S*S% jr&S)S& jr'S' r(S( r)g)+    Nreduce)
get_module)ImageUriValidatorcopy_to_readonly_numpy_arrayis_homogeneous_arrayi   i i  i   i   i  l    i1u1i2u2i4u4f4f8)int8uint8int16uint16int32uint32float32float64c                    [        U 5      n [        SSS9nU(       a*  [        XR                  5      (       a  U R                  S:X  a  U $ [        U R                  5      nUS:X  a  U R                  5       nU R                  5       nU[        ::  a  U[        :  a  U R                  S5      n OU[        ::  a  U[        :  a  U R                  S5      n OU[        ::  a  U[        :  a  U R                  S5      n OU $ US	:X  a  U R                  5       nU R                  5       nU[         ::  a  US:  a  U R                  S
5      n OFU["        ::  a  US:  a  U R                  S5      n O$U[$        ::  a  US:  a  U R                  S5      n OU $ [        U R                  5      nU[&        ;   a\  [&        U   [(        R*                  " U 5      R-                  S5      S.nU R.                  S:  a  [        U R0                  5      SS US'   U$ U $ )z]
Convert numpy array to plotly.js typed array spec
If not possible return the original value
numpyFshould_loadr   int64r   r   r   uint64r   r   r   ascii)dtypebdata   shape)r   r   
isinstancendarraysizestrr"   maxminint8maxint8minastypeint16maxint16minint32maxint32minuint8max	uint16max	uint32maxplotlyjsShortTypesbase64	b64encodedecodendimr&   )vnpr"   r+   r,   arrObjs         E/var/www/html/env/lib/python3.13/site-packages/_plotly_utils/utils.pyto_typed_array_specr@   '   s   
 	%Q'A 
G	/BZ::..!&&A+LE eegeeg'>cWn AH_!AH_!AH	(	eegeeg(?sax!AI#("AI#("AHLE""'.%%a(//8

 66A:!!''l1R0F7OH    c                 6   ^  / SQn[        U 4S jU 5       5      $ )zJ
Return whether the key is skipped for conversion to the typed array spec
)geojsonlayerlayersrangec              3   ,   >#    U  H	  oT:H  v   M     g 7fN ).0skipped_keykeys     r?   	<genexpr>!is_skipped_key.<locals>.<genexpr>d   s     B\kc!\s   )any)rL   skipped_keyss   ` r?   is_skipped_keyrQ   _   s     ;LB\BBBrA   c                 X   [        U [        5      (       aV  U R                  5        HA  u  p[        U5      (       a  M  [	        U5      (       a  [        U5      X'   M6  [        U5        MC     g [        U [        5      (       d  [        U [        5      (       a  U  H  n[        U5        M     g g rH   )	r'   dictitemsrQ   r   r@   convert_to_base64listtuple)objrL   values      r?   rU   rU   g   s    #t))+JCc""%e,,.u5!%( & 
C		*S%"8"8Ee$  #9rA   c                 $    S n[        X/ 5      nU$ )z(
Custom cumsum to avoid a numpy import.
c                 <    [        U 5      S:X  a  U/$ X S   U-   /-   $ Nr   r%   )len)axs     r?   _reducercumsum.<locals>._reducerz   s&    q6Q;3JbEAI;rA   r   )r_   r`   rets      r?   cumsumrc   u   s    

 b
!CJrA   c                      ^  \ rS rSrSrS rU 4S jrS r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrU =r$ )PlotlyJSONEncoder   a!  
Meant to be passed as the `cls` kwarg to json.dumps(obj, cls=..)

See PlotlyJSONEncoder.default for more implementation information.

Additionally, this encoder overrides nan functionality so that 'Inf',
'NaN' and '-Inf' encode to 'null'. Which is stricter JSON than the Python
version.

c                     US;   a  gU$ )zE
This is used to ultimately *encode* into strict JSON, see `encode`

)Infinityz	-InfinityNaNNrI   )selfconsts     r?   coerce_to_strict"PlotlyJSONEncoder.coerce_to_strict   s     44LrA   c                 8  > [         [        U ]  U5      nSU;   d  SU;   d  U$  [        R                  " X R
                  S9n[        R                  " UU R                  U R                  U R                  U R                  4S9$ ! [         a    [        S5      ef = f)z
Load and then dump the result using parse_constant kwarg

Note that setting invalid separators will cause a failure at this step.

ri   rh   )parse_constant)	sort_keysindent
separatorszSEncoding into strict JSON failed. Did you set the separators valid JSON separators?)superre   encode_jsonloadsrl   dumpsrp   rq   item_separatorkey_separator
ValueError)rj   o	encoded_onew_o	__class__s       r?   rt   PlotlyJSONEncoder.encode   s     +T9!<	 "jI&=
	KK	:O:OPE ;;..{{ //1C1CD	   	 ) 	s   B Bc           	      P   U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  4	nU H  n U" U5      s  $    [        R                  R                  X5      $ ! [         a     M<  f = f)a]  
Accept an object (of unknown type) and try to encode with priority:
1. builtin:     user-defined objects
2. sage:        sage math cloud
3. pandas:      dataframes/series
4. numpy:       ndarrays
5. datetime:    time/datetime objects

Each method throws a NotEncoded exception if it fails.

The default method will only get hit if the object is not a type that
is naturally encoded by json:

    Normal objects:
        dict                object
        list, tuple         array
        str, unicode        string
        int, long, float    number
        True                true
        False               false
        None                null

    Extended objects:
        float('nan')        'NaN'
        float('infinity')   'Infinity'
        float('-infinity')  '-Infinity'

Therefore, we only anticipate either unknown iterables or values here.

)encode_as_plotlyencode_as_sageencode_as_numpyencode_as_pandasencode_as_datetimeencode_as_dateencode_as_listencode_as_decimalencode_as_pilNotEncodableru   JSONEncoderdefault)rj   rX   encoding_methodsencoding_methods       r?   r   PlotlyJSONEncoder.default   s    B !!  !!##""

  0O&s++  0
   ((33   s   ,B
B%$B%c                 L     U R                  5       $ ! [         a    [        ef = f)z1Attempt to use a builtin `to_plotly_json` method.)to_plotly_jsonAttributeErrorr   rX   s    r?   r   "PlotlyJSONEncoder.encode_as_plotly   s+    	%%'' 		    #c                 P    [        U S5      (       a  U R                  5       $ [        e)z@Attempt to use `tolist` method to convert to normal Python list.tolist)hasattrr   r   r   s    r?   r    PlotlyJSONEncoder.encode_as_list   s#     3!!::<rA   c                     [        S5      nU(       d  [        eXR                  ;   a  [        U 5      $ XR                  ;   a  [        U 5      $ [        e)z@Attempt to convert sage.all.RR to floats and sage.all.ZZ to intszsage.all)r   r   RRfloatZZint)rX   sage_alls     r?   r    PlotlyJSONEncoder.encode_as_sage  sD     j)++:KKs8OrA   c                     [        SSS9nU(       d  [        eXR                  L a  g[        US5      (       a  XR                  L a  g[        e)z)Attempt to convert pandas.NaT / pandas.NApandasFr   NNA)r   r   NaTr   r   )rX   r   s     r?   r   "PlotlyJSONEncoder.encode_as_pandas  sG     H%8** 64  SII%5rA   c                 h   [        SSS9nU(       d  [        eXR                  R                  R                  L a  [        S5      $ [        XR                  5      (       a:  U R                  R                  S:X  a    UR                  U 5      R                  5       $ [        e! [         a     [        ef = f)z'Attempt to convert numpy.ma.core.maskedr   Fr   nanM)r   r   macoremaskedr   r'   r(   r"   kinddatetime_as_stringr   	TypeError)rX   r   s     r?   r   !PlotlyJSONEncoder.encode_as_numpy  s     76((--&&&<]]++		#0E//4;;==   s   :B 
B10B1c                 L     U R                  5       $ ! [         a    [        ef = f)z.Convert datetime objects to iso-format strings)	isoformatr   r   r   s    r?   r   $PlotlyJSONEncoder.encode_as_datetime0  s(    	==?" 		r   c                 b     U R                  5       n[        U5      $ ! [         a    [        ef = f)z=Attempt to convert to utc-iso time string using date methods.)r   iso_to_plotly_time_stringr   r   )rX   time_strings     r?   r    PlotlyJSONEncoder.encode_as_date8  s6    	:--/K -[99  		s    .c                 b    [        U [        R                  5      (       a  [        U 5      $ [        e)z3Attempt to encode decimal by converting it to float)r'   decimalDecimalr   r   r   s    r?   r   #PlotlyJSONEncoder.encode_as_decimalB  s%     c7??++:rA   c                     [        S5      nUb0  [        XR                  5      (       a  [        R                  " U 5      $ [
        e)z5Attempt to convert PIL.Image.Image to base64 data uriz	PIL.Image)r   r'   Imager   pil_image_to_urir   )rX   images     r?   r   PlotlyJSONEncoder.encode_as_pilJ  s9     ;'C!=!=$55c::rA   rI   )__name__
__module____qualname____firstlineno____doc__rl   rt   r   staticmethodr   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r~   s   @r?   re   re      s    		#J04d              : :    rA   re   c                       \ rS rSrSrg)r   iT  rI   N)r   r   r   r   r   rI   rA   r?   r   r   T  s    rA   r   c                 0   U R                  S5      SS S:X  d  U R                  S5      S   S:X  a  [        S5      eU R                  SS	5      R                  S
S	5      n U R                  S5      (       a  U R                  SS	5      $ U R                  SS5      $ )z=Remove timezone info and replace 'T' delimeter with ' ' (ws).-N   z00:00+r   z]Plotly won't accept timestrings with timezone info.
All timestrings are assumed to be in UTC.z-00:00 z+00:00z	T00:00:00T )split	Exceptionreplaceendswith)
iso_strings    r?   r   r   X  s     	bq!W,*2B2B32G2Jg2U8
 	

 ##Hb199(BGJ;''!!+r22!!#s++rA   c                     ^  U 4S jnU$ )Nc                    > [         R                  S S S:X  d.  U R                  b!  U R                  R                  " S0 TD6U l        U $ )N   )r   r   rI   )sysversion_infor   format)funcnamess    r?   
_decorator template_doc.<locals>._decoratorj  s@    #v-||'#||22;U;rA   rI   )r   r   s   ` r?   template_docr   i  s     rA   c                     S n[        XUS9$ )Nc                     [         R                  " SU 5      n[        [        U5      5       H  n [	        X   5      X'   M     [        U5      $ ! [
         a     M/  f = f)Nz(\d+))rer   rF   r]   r   rz   rW   )r<   v_partsis      r?   rL   "_natural_sort_strings.<locals>.keyt  sW    ((8Q's7|$A _
 % W~  s   A
AA)rL   reversesorted)valsr   rL   s      r?   _natural_sort_stringsr   s  s     $11rA   c                  ^    [        SSS9n U (       a  [        U R                  4nU$ [        4nU$ )Nr   Fr   )r   r   integer)r=   int_types     r?   _get_int_typer     s4    	G	/B	$ O 6OrA   c                    ^ [        U5      S:X  a  U $ UR                  5       m[        S [        U4S jU 5      5      n [	        X5      $ )aN  
Split all the strings in ss at any of the characters in chars.
Example:

    >>> ss = ["a.string[0].with_separators"]
    >>> chars = list(".[]_")
    >>> split_multichar(ss, chars)
    ['a', 'string', '0', '', 'with', 'separators']

:param (list) ss: A list of strings.
:param (list) chars: Is a list of chars (note: not a string).
r   c                 
    X-   $ rH   rI   )r_   ys     r?   <lambda>!split_multichar.<locals>.<lambda>  s    QUrA   c                 &   > U R                  T5      $ rH   )r   )r_   cs    r?   r   r     s    !''!*rA   )r]   popr   mapsplit_multichar)sscharsr   s     @r?   r   r     s@     5zQ			A	"C(<b$A	BB2%%rA   c                     [        [        S [        [        [	        U 5      5      [        S/[        [        [        U SS 5      5      -   5      5      5      5      $ )a  
Given a list of strings split using split_multichar, return a list of
integers representing the indices of the first character of every string in
the original string.
Example:

    >>> ss = ["a.string[0].with_separators"]
    >>> chars = list(".[]_")
    >>> ss_split = split_multichar(ss, chars)
    >>> ss_split
    ['a', 'string', '0', '', 'with', 'separators']
    >>> split_string_positions(ss_split)
    [0, 2, 9, 11, 12, 17]

:param (list) ss: A list of strings.
c                     U S   U S   -   $ )Nr   r$   rI   )ts    r?   r   (split_string_positions.<locals>.<lambda>  s    adQqTkrA   r   Nr%   )rV   r   ziprF   r]   rc   )r   s    r?   split_string_positionsr     sL    " !c"gsT#c2cr72C-D'D EF	
 rA   c                 B   [        [        U 5      S-   U-   U-   5       Vs/ s H  nSPM     nnSnUc'  U  H   n	[        U5       H  n
X-   U
-   nXGU'   M     M"     O [        U5       H  n
X   U-   U
-   nXGU'   M     SR                  U5      nU(       a  USUS-    nU$ s  snf )aW  
Return a string that is whitespace except at p[i] which is replaced with char.
If i is None then all the indices of the string in p are replaced with char.

Example:

    >>> ss = ["a.string[0].with_separators"]
    >>> chars = list(".[]_")
    >>> ss_split = split_multichar(ss, chars)
    >>> ss_split
    ['a', 'string', '0', '', 'with', 'separators']
    >>> ss_pos = split_string_positions(ss_split)
    >>> ss[0]
    'a.string[0].with_separators'
    >>> display_string_positions(ss_pos,4)
    '            ^'
    >>> display_string_positions(ss_pos,4,offset=1,length=3,char="~",trim=False)
    '             ~~~      '
    >>> display_string_positions(ss_pos)
    '^ ^      ^ ^^    ^'
:param (list) p: A list of integers.
:param (integer|None) i: Optional index of p to display.
:param (integer) offset: Allows adding a number of spaces to the replacement.
:param (integer) length: Allows adding a replacement that is the char
                         repeated length times.
:param (str) char: allows customizing the replacement character.
:param (boolean) trim: trims the remaining whitespace if True.
r$   r   r   Nr   )rF   r+   join)pr   offsetlengthchartrim_smaxaddrp_lrb   s               r?   display_string_positionsr    s    : CFQJ/&89:99A:GyB6]+/!'
 # 
 vAdVma'GgJ  ''!*C-GaK J 	;s   Bc           
      2   S nU(       a  U" [        U" U 5      U5      5      $ [        U 5      (       d  U $ [        [        [        U 5      5      S:X  a  U[        U 5      S-
  -  /$  " S S5      n[	        [        [        [        U" U5      U S/5      5      5      $ )a  
Given a list of strings, some of which are the empty string "", replace the
empty strings with c and combine them with the closest non-empty string on
the left or "" if it is the first string.
Examples:
for c="_"
['hey', '', 'why', '', '', 'whoa', '', ''] -> ['hey_', 'why__', 'whoa__']
['', 'hi', '', "I'm", 'bob', '', ''] -> ['_', 'hi_', "I'm", 'bob__']
['hi', "i'm", 'a', 'good', 'string'] -> ['hi', "i'm", 'a', 'good', 'string']
Some special cases are:
[] -> []
[''] -> ['']
['', ''] -> ['_']
['', '', '', ''] -> ['___']
If reverse is true, empty strings are combined with closest non-empty string
on the right or "" if it is the last string.
c                 H    U  Vs/ s H
  oS S S2   PM     snS S S2   $ s  snf )Nr%   rI   )r  r	  s     r?   _rev!chomp_empty_strings.<locals>._rev  s)    !"#A$B$#DbD))#s   r   r$   c                        \ rS rSrS rS rSrg)%chomp_empty_strings.<locals>._Chomperi  c                     Xl         g rH   r   )rj   r   s     r?   __init__.chomp_empty_strings.<locals>._Chomper.__init__  s    FrA   c                 \    [        U5      S:X  a  US S US   U R                  -   /-   $ X/-   $ r\   )r]   r   )rj   r_   r   s      r?   __call__.chomp_empty_strings.<locals>._Chomper.__call__  s8    
 1v{"v2 0003wrA   r  N)r   r   r   r   r  r  r   rI   rA   r?   _Chomperr    s    		rA   r  r   )chomp_empty_stringsr]   sumr   rV   filterr   )stringsr   r   r  r  s        r?   r  r    s    &* 'Wq9::w<<
3sG"S\A%&''  sF8A;">?@@rA   c           	      ~   [        U 5      [        U5      :  a  [        X5      $ [        U5      S:X  a  [        U 5      $ [        [        U5      S-   5      n[        U 5       HV  u  p4US-   /n[        U5       H:  u  pgX&S-      S-   nXV   S-   n	X&   XG:g  -   n
UR	                  [        XU
5      5        M<     UnMX     US   $ )Nr   r$   r%   )r]   levenshteinrF   	enumerateappendr,   )s1s2previous_rowr   c1current_rowjc2
insertions	deletionssubstitutionss              r?   r!  r!    s    
2wR2""
2w!|2wR1%L21ugr]EA &!e,q0J#*I(Orx8Ms:-HI # #  rA   c                 (   ^  U 4S jn[        XS9S   $ )Nc                     > [        U T5      U 4$ rH   )r!  )r	  strings    r?   _key!find_closest_string.<locals>._key)  s     Av&**rA   )rL   r   r   )r0  r  r1  s   `  r?   find_closest_stringr3  (  s    +
 '$Q''rA   )F)Nr   r$   ^T)*r8   r   jsonru   r   r   	functoolsr   _plotly_utils.optional_importsr   _plotly_utils.basevalidatorsr   r   r   r.   r-   r1   r0   r3   r2   r4   r5   r6   r7   r@   rQ   rU   rc   r   re   r   r   r   r   r   r   r   r   r  r  r!  r3  rI   rA   r?   <module>r9     s       
 	  5  
		 	 5pC%N)) Nb	9 	,"2&(2+\+A`&(rA   