
    &eÈ                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddl m!Z!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( d	Z)d
Z*dZ+d	Z,dZ-da.ddgZ/g dZ0 ej1        dg d          Z2eee3ee         f         eegef         f         Z4 G d dej5                  Z6	 	 d7dede6dedef         dee2         dee4         ddfdZ7 G d d          Z8 G d d          Z9 e9            Z: G d  d!          Z;de2fd"Z<d#e=de>fd$Z?d%ee         defd&Z@ G d' d(          ZAde2dee         fd)ZB G d* d+          ZC G d, d-e"          ZD G d. d/e"          ZE G d0 d1e!          ZFd2eGd3edee3ef         fd4ZHd5e=dee3         fd6ZIdS )8zA hashing utility for code.    N)AnyCallableDictListOptionalPatternTypeUnion)config	file_util	type_utilutil)MarkdownFormattedExceptionStreamlitAPIException)FolderBlackList)UploadedFile)HASHLIB_KWARGSi i'  i@B s<   streamlit-57R34ML17-hesamagicalponyflyingthroughthesky-CYCLEz_cffi_backend.FFIzbuiltins.CompiledFFI)zkeras.engine.training.Modelz-tensorflow.python.keras.engine.training.Modelz4tensorflow.python.keras.engine.functional.FunctionalContextglobalscellsvarnamesc                       e Zd ZdZdZdZdZdS )
HashReasonr            N)__name__
__module____qualname__CACHING_FUNC_ARGSCACHING_FUNC_BODYCACHING_FUNC_OUTPUTCACHING_BLOCK     Hlib/python3.11/site-packages/streamlit/runtime/legacy_caching/hashing.pyr   r   V   s%        MMMr&   r   valhash_reasonhash_source.context
hash_funcsreturnc                     |t           j        _        |t           j        _        t	          |          }|                    || |           dS )zcUpdates a hashlib hasher with the hash of val.

    This is the main entrypoint to hashing.py.
    N)hash_stackscurrentr)   r*   _CodeHasherupdate)r(   hasherr)   r*   r+   r,   chs          r'   update_hashr5   ]   sC     '2K#&1K#	Z	 	 BIIfc7#####r&   c                   H    e Zd ZdZd ZdefdZdefdZd Z	defdZ
d	 Zd
S )
_HashStacka  Stack of what has been hashed, for debug and circular reference detection.

    This internally keeps 1 stack per thread.

    Internally, this stores the ID of pushed objects rather than the objects
    themselves because otherwise the "in" operator inside __contains__ would
    fail for objects that don't return a boolean for "==" operator. For
    example, arr == 10 where arr is a NumPy array returns another NumPy array.
    This causes the "in" to crash since it expects a boolean.
    c                 R    t          j                    | _        d | _        d | _        d S N)collectionsOrderedDict_stackr)   r*   selfs    r'   __init__z_HashStack.__init__|   s,    ?J?V?X?X 26
 :>r&   r-   c                 *    t          j        |           S r9   r   repr_r=   s    r'   __repr__z_HashStack.__repr__       z$r&   r(   c                 4    || j         t          |          <   d S r9   )r<   idr>   r(   s     r'   pushz_HashStack.push   s    "BsGGr&   c                 8    | j                                          d S r9   )r<   popitemr=   s    r'   popz_HashStack.pop   s    r&   c                 .    t          |          | j        v S r9   )rF   r<   rG   s     r'   __contains__z_HashStack.__contains__   s    #ww$+%%r&   c                     d d                     fdt          | j                                                  D                       S )Nc                 r    dt          j        |           dt          |           S # t          $ r Y dS w xY w)NzObject of type z: z"<Unable to convert item to string>)r   get_fqn_typestr	Exception)vs    r'   to_strz'_HashStack.pretty_print.<locals>.to_str   sP    <2;2H2K2K2K2KSQRVVVTT < < <;;;<s   &( 
66
c              3   .   K   | ]} |          V  d S r9   r%   ).0xrT   s     r'   	<genexpr>z*_HashStack.pretty_print.<locals>.<genexpr>   s+      KKqKKKKKKr&   )joinreversedr<   values)r>   rT   s    @r'   pretty_printz_HashStack.pretty_print   sQ    	< 	< 	< yyKKKKHT[5G5G5I5I,J,JKKKKKKr&   N)r   r   r    __doc__r?   rQ   rC   r   rH   rK   rM   r]   r%   r&   r'   r7   r7   p   s        	 		> 	> 	> #        # # # # #  & & & & &L L L L Lr&   r7   c                   @    e Zd ZdZd ZdefdZedefd            Z	dS )_HashStacksz@Stacks of what has been hashed, with at most 1 stack per thread.c                 6    t          j                    | _        d S r9   )weakrefWeakKeyDictionary_stacksr=   s    r'   r?   z_HashStacks.__init__   s     %'' 	r&   r-   c                 *    t          j        |           S r9   rA   r=   s    r'   rC   z_HashStacks.__repr__   rD   r&   c                     t          j                    }| j                            |d           }|t	                      }|| j        |<   |S r9   )	threadingcurrent_threadrd   getr7   )r>   rh   stacks      r'   r0   z_HashStacks.current   sF    "133  66=LLE+0DL(r&   N)
r   r   r    r^   r?   rQ   rC   propertyr7   r0   r%   r&   r'   r`   r`      sk        JJ( ( (
 #         	 	 	 	 X	 	 	r&   r`   c                   L    e Zd ZdZ e            Zd ZdefdZd Z	d Z
d	dZdS )
_Cellsa  
    Class which is basically a dict that allows us to push/pop frames of data.

    Python code objects are nested. In the following function:

        @st.cache()
        def func():
            production = [[x + y for x in range(3)] for y in range(5)]
            return production

    func.__code__ is a code object, and contains (inside
    func.__code__.co_consts) additional code objects for the list
    comprehensions. Those objects have their own co_freevars and co_cellvars.

    What we need to do as we're traversing this "tree" of code objects is to
    save each code object's vars, hash it, and then restore the original vars.
    c                 0    i | _         g | _        g | _        d S r9   )r\   rj   framesr=   s    r'   r?   z_Cells.__init__   s    
r&   r-   c                 *    t          j        |           S r9   rA   r=   s    r'   rC   z_Cells.__repr__   rD   r&   c                     | j                             || j                            || j                  f           || j        |<   dS )z
        Sets a value and saves the old value so it can be restored when
        we pop the frame. A sentinel object, _cell_delete_obj, indicates that
        the key was previously empty and should just be deleted.
        N)rj   appendr\   ri   _cell_delete_obj)r>   keyvalues      r'   _setz_Cells._set   sF     	
3T5J K KLMMM !Cr&   c                     | j                                         }| j        |d         D ]!\  }}|| j        u r	| j        |= || j        |<   "| j        d|         | _        dS )zBPop off the last frame we created, and restore all the old values.N)ro   rK   rj   rs   r\   )r>   idxrt   r(   s       r'   rK   z
_Cells.pop   ss     koo
344( 	' 	'HCd+++K$$#&C  Z%


r&   Nc                    | j                             t          | j                             |j        D ]}|                     ||           |j        r|it          |j                  t          |j                  k    sJ t          |j        |j                  D ] \  }}|                     ||j	                   !dS |j        D ]}|                     ||           dS dS )z:Create a new frame, and save all of `code`'s vars into it.N)
ro   rr   lenrj   co_cellvarsrv   co_freevars__closure__zipcell_contents)r>   codefuncvarcells        r'   rH   z_Cells.push   s	    	3tz??+++# 	  	 CIIc3 		(4+,,D4D0E0EEEEE!$T%5t7G!H!H 7 7ICIIc4#566667 7
  + ( (CIIc3''''		( 		(( (r&   r9   )r   r   r    r^   objectrs   r?   rQ   rC   rv   rK   rH   r%   r&   r'   rm   rm      s         $ vxx  
 #        ! ! !	& 	& 	&( ( ( ( ( (r&   rm   c                     i }t          j        |           r	d| j        i}t          | j        t                      |          S )Nr>   r   )inspectismethod__self__r   __globals__rm   )r   r   s     r'   _get_contextr     sB    H +DM*4+688hOOOOr&   ic                 f    |                                  dz   dz  }|                     |dd          S )N   littleT)signed)
bit_lengthto_bytes)r   	num_bytess     r'   _int_to_bytesr     s1    !#)I::i$:777r&   objc                    | dS d } ||           r| S t          | t                    rt          t          ||                     r| S t          | t                    r.t          t          ||                     rdt          |           fS t          j        | d          sQt          j        | d          s<t          j        |           s(t          j	        |           st          j
        |           rt          |           S t          S )zReturn key for memoization.Nc                    t          | t                    plt          | t                    pWt          | t                    pBt          | t                    p-t          | t
                    pt          | t                    p| d u S r9   )
isinstancebytes	bytearrayrQ   floatintbool)r   s    r'   	is_simplez_key.<locals>.is_simple  s    sE"" #y))#s## #u%% #s##	
 #t$$ d{	
r&   __lpandas.core.frame.DataFramenumpy.ndarray)r   tupleallmaplistr   is_typer   	isbuiltin	isroutineiscoderF   NoResult)r   r   s     r'   _keyr     s    {t	
 	
 	
 y~~ 
#u s9c""## 	J#t 's9c""## 	'5::&& 	#<==S/22 S!! S!!	
 ># #wwOr&   c                       e Zd ZdZddee         fdZdefdZdde	dee
         defd	Zdde	dee
         ddfd
ZdedefdZde	dee
         defdZdde
defdZedefd            ZdS )r1   z;A hasher that can hash code objects including dependencies.Nr,   c                     |  |r$d |                                 D             | _        ni | _        i | _        d| _        d S )Nc                 l    i | ]1\  }}t          |t                    r|nt          j        |          |2S r%   )r   rQ   r   get_fqn)rW   krS   s      r'   
<dictcomp>z(_CodeHasher.__init__.<locals>.<dictcomp>H  sL          Aq  3''AY->q-A-A1     r&   r   )items_hash_funcs_hashessize)r>   r,   s     r'   r?   z_CodeHasher.__init__>  s`     	' 	"   &,,..     D
  "D)+ 			r&   r-   c                 *    t          j        |           S r9   rA   r=   s    r'   rC   z_CodeHasher.__repr__T  rD   r&   r   r+   c                    t          |          j                                        }|t          |          f}|d         t          ur|| j        v r| j        |         S |t          j        v rt          S t          j        	                    |           	 d|| 
                    ||          fz  }| xj        t          j        |          z  c_        |d         t          ur
|| j        |<   n9# t          t          t           f$ r  t"          $ r}t!          ||          d}~ww xY wt          j                                         n## t          j                                         w xY w|S )zKAdd memoization to _to_bytes and protect against cycles in data structures.r   s   %s:%sN)typer    encoder   r   r   r/   r0   _CYCLE_PLACEHOLDERrH   	_to_bytesr   sys	getsizeofUnhashableTypeErrorUserHashErrorInternalHashErrorrR   rK   )r>   r   r+   tnamert   bexs          r'   r   z_CodeHasher.to_bytesW  sd   S		&--//d3ii  q6!!dl""|C(( +%%%%%  %%%	&E4>>#w#?#?@@A IIq)))II1vX%%$%S!#]4EF 	 	 	 	- 	- 	-#B,,,	- ##%%%%K##%%%%s+   AC) (E )!D
DDE  E!c                 \    |                      ||          }|                    |           dS )z6Update the provided hasher with the hash of an object.N)r   r2   )r>   r3   r   r+   r   s        r'   r2   z_CodeHasher.update  s-    MM#w''ar&   filenamec                 B   t           s!t          t          j        d                    a t          j                            |          }t                               |          }|rdS t          j	        || 
                                          pt          j        |          S )Nzserver.folderWatchBlacklistF)_FOLDER_BLACK_LISTr   r   
get_optionospathabspathis_blacklistedr   file_is_in_folder_glob_get_main_script_directoryfile_in_pythonpath)r>   r   filepathfile_is_blacklisteds       r'   _file_should_be_hashedz"_CodeHasher._file_should_be_hashed  s     " 	!0!"?@@" " 7??8,,0??II 	5/d5577
 
 4)(33	4r&   c                 \   t          j        d-i t          }t          t          j        j                  r"|                     t                              S t          t                    st          t                    rS t          j                  | j        v re| j        t          j                           }	  |          }n$# t          $ r}t          ||          d}~ww xY w|                     |          S t          t                     r                                S t          t$                    r"|                     t'                              S t          t(                    rt+                    S t          t,          t.          f          r0D ]}|                     |||           |                                S t          t4                    rB                                D ]}|                     |||           |                                S dS du rdS du rdS t          j        d          st          j        d	          rd
dl}t=                    t>          k    r                     tB          d
          	 d|j"        #                              $                                z  S # tJ          $ r% dtM          j'        tL          j(                  z  cY S w xY wt          j        d          r|                     |j)                   j*        tV          k    r?d
dl,}	|	j-        .                    d
          }
|
/                    j0        tb                    |                     |2                                           |                                S tg          j4                  r&t          j5                                                  S tm          fdtn          D                       r|                     d          S t          j        d          st          j        d          r"|                     t5                              S t          j        d          r&t          j8                                                  S t          tr                    rt          j        d-i t          }|                     |j:                   |                     |;                                           |                     |<                                           |                                S t{          d          rt          t|          j?                  st          t          jA                  rt          dd          }|                     ||           |                     |t          jD        E                    |                     |                     |;                                           |                                S t          t                    r!|                     jG        jH        g          S t          t|          jI                  st          t|          jJ                  rd|                     |;                                           |                     |<                                           |                                S tm          d t                    jL        D                       rĉjM        jN        }|r|d
         jO        |d         jO        gnd}|rLt5          t          jQ        t          |d                                         d                               |d<   S                                }dD ]}|d         T                    |d           |                     ||g          S t          j        d          raS                                }|d         T                    dd           |d         T                    dd           |                     |          S t          j        d          r&t          j5                                                  S t          j        d          r"|                     t                              S tm          d  t                    jL        D                       r"|                     t                              S t          j        d!          r"|                     t                              S t          j        d"          st          j        d#          r@|                     U                                ,                                jV        g          S tm          fd$t          D                       r"|                     t                              S t          j        d%          r"|                     t                              S tg          jX                  rDt          d&d          }||                     |          S jY        Z                    d'          r$|                     jY        d(j5                  S t          d)d          }|J | [                    |j\                  ret                    }t          d*d          }||                     |||           |                    | ^                    ||+                     n6|                     |jY                   |                     |j5                   |                                S tg          j_                  r'|t          d,          | ^                    |          S tg          ja                  r|                     j5                  S tg          jb                  r|                     j5                  S t          t          jd                  r{t          j        d-i t          }|                     |je                   |                     |jf                   |                     |jg                   |                                S 	 S                                }n"# t          $ r}t          |          d}~ww xY w|D ]}|                     |||           |                                S ).zHash objects to bytes, including code with dependencies.

        Python's built in `hash` does not produce consistent results across
        runs.
        md5)	hash_funcN   0T   1Fr   zpandas.core.series.Seriesr   )nrandom_states   %sr   )r   c              3   B   K   | ]}t          j        |          V  d S r9   r   r   rW   typenamer   s     r'   rY   z(_CodeHasher._to_bytes.<locals>.<genexpr>  s0      RRh"311RRRRRRr&   zbuiltins.mappingproxyzbuiltins.dict_itemszbuiltins.getset_descriptorname
wonthappenc              3   F   K   | ]}t          j        |          d k    V  dS )zsqlalchemy.pool.base.PoolNr   r   rW   rX   s     r'   rY   z(_CodeHasher._to_bytes.<locals>.<genexpr>  sG       
 
 a  $??
 
 
 
 
 
r&   r   c                     | d         S )Nr   r%   )ts    r'   <lambda>z'_CodeHasher._to_bytes.<locals>.<lambda>(  s
    qt r&   )rt   )_overflow_lock_pool_conn_fairy_threadconnsloggerr   zsqlalchemy.engine.base.Engineurlr   znumpy.ufunczsocket.socketc              3   F   K   | ]}t          j        |          d k    V  dS )ztorch.nn.modules.module.ModuleNr   r   s     r'   rY   z(_CodeHasher._to_bytes.<locals>.<genexpr>J  sG       
 
 a  $DD
 
 
 
 
 
r&   z(tensorflow.python.client.session.Sessionztorch.Tensorztorch._C._TensorBasec              3   B   K   | ]}t          j        |          V  d S r9   r   r   s     r'   rY   z(_CodeHasher._to_bytes.<locals>.<genexpr>X  s0      TTh"311TTTTTTr&   zYtensorflow.python.saved_model.load.Loader._recreate_base_user_object.<locals>._UserObject__wrapped__	streamlit.__code____defaults__r   z)context must be defined when hashing coder   )ihashlibnewr   r   unittestmockMockr   rF   r   r   r   rP   r   rR   r   rQ   r   r   hashr   r   r   r   r2   digestdictr   r   pandasrz   _PANDAS_ROWS_LARGEsample_PANDAS_SAMPLE_SIZEr   hash_pandas_objectsum	TypeErrorpickledumpsHIGHEST_PROTOCOLshaper   _NP_SIZE_LARGEnumpyrandomRandomStatechoiceflat_NP_SAMPLE_SIZEtobytesr   r   r   any_FFI_TYPE_NAMESr    r   r   tellgetvaluehasattrioIOBasetempfile_TemporaryFileWrappergetattrr   r   getmtimer   patternflagsStringIOBytesIOr   	__bases___creatorr}   r   r:   r;   sorted
__reduce__rK   detachgrad_KERAS_TYPE_NAMESr   r   
startswithr   co_filenamer   _code_to_bytesr   RuntimeErrorismoduleisclass	functoolspartialargsr   keywordsr   )r>   r   r+   hr   outputr   itempdnpstateobj_namecargsreduce_dataattrwrappedr   defaultss    `                r'   r   z_CodeHasher._to_bytes  su    K0000c8=-.. F	 ==C)))U## A	z#y'A'A A	J#C((D,<<<()?)D)DEIB"3 B B B#ByAAAAB ==(((S!! t	::<<U## q	==c+++S!! n	 %%%dE]++ k	 . .AtW----88::T"" f			 . .AtW----88::[4D[[4E\\4s$ABB X	iFW,G
 G
 X	  3xx---jj#6QjGGJrw99#>>BBDDDD J J J v|C1HIIIIIIJ
 sO44 J	KK39%%%x>))""""	--a00ll38/lBBKK3;;==)))88::s## ~	,,..///RRRR/RRRRR {	==&&&s$;<< x		@Q&A
 A
 x	 ==c+++s$@AA s	)0022333\** p	 44^44AKK38$$$KK388::&&&KK3<<>>***88::S&!! f	sBI&&f	 #x=>>f	 sFL99HKK8$$$KK27++H55666KK388::&&&88::W%% V	==#+sy!9:::R[)) S	ZRZ-H-H S	 KK388::&&&KK3<<>>***88:: 
 
#YY(
 
 
 
 
 L	 L,EHMWU1X+U1X-CDDSWE  +uQx~~//^^DDD  a ..**K / / A""4....==+u!5666s$CDD j	..**KNud+++Nx...==---sM22 b	,,..///sO44 ^	==C))) 
 
#YY(
 
 
 
 
 [	 ==C)))s$NOO U	==C)))sN33 R	y7H'8
 8
 R	 ==#**,,"4"4"6"6!ABBBTTTTBSTTTTT M	==C)))g
 
 J	 ==C)))s## D	c=$77G"}}W---~((55 O }}%MNNN3
D11D###**4+;<< 	-&s++"3=='KK8W555,,T7,EEFFFF As~...As|,,,88::^C   +	"#NOOO&&sG444c"" &	 ==..._S!! 	 ==...Y.// 	 44^44AKK38$$$KK38$$$KK3<(((88::3!nn.. 3 3 3)"c2223 $ . .AtW----88::sB    C 
C-C((C-.K ,K=<K=s 
s;&s66s;c                    t          j        di t          }|                     ||j                   d |j        D             }|                     |||           |j                            ||           t          ||          D ]}|                     |||           |j        	                                 |
                                S )Nr   c                 f    g | ].}t          |t                    r|                    d           ,|/S )z	.<lambda>)r   rQ   endswith)rW   r   s     r'   
<listcomp>z._CodeHasher._code_to_bytes.<locals>.<listcomp>  sN     
 
 
a%%
 ./ZZ-D-D

 
 
r&   r   r   )r   r   r   r2   co_code	co_constsr   rH   get_referenced_objectsrK   r   )r>   r   r+   r   r0  constsrefs          r'   r(  z_CodeHasher._code_to_bytes  s    K0000 	At|$$$
 
^
 
 

 	Avw'''4d+++)$88 	) 	)CKK3((((xxzzr&   c                      ddl } ddl}|                     |j                                                  }t          |j                  S )z6Get the absolute path to directory of the main script.r   N)pathlib__main__Path__file__resolverQ   parent)rF  rG  abs_main_paths      r'   r   z&_CodeHasher._get_main_script_directory  sI     	  X%677??AA='(((r&   r9   )r   r   r    r^   r   HashFuncsDictr?   rQ   rC   r   r   r   r   r2   r   r   r   r(  staticmethodr   r%   r&   r'   r1   r1   ;  sg       EE 8M#:    , #        ' 'C '(7*; 'u ' ' ' 'R # 0A T    
4s 4t 4 4 4 4"OS O8G+< O O O O Ob G 5    * 	) 	) 	) 	) \	) 	) 	)r&   r1   c                    d d }g fd}t          j        |           D ]}	 |j        |j        }|j        dv r=|j        |j        v r ||j        |j                            nv ||j                   nd|j        dv r" ||j        j        |j                            n9|j        dk    rE	  |t          j	        |j                             n	# t          $ r  ||j                   Y nw xY w|j        dv rV                    |j                   nt          t                    rd|j        z   z  nt          |j                  n|j        dk    rr|j        |j        = d nm|j        dk    rr|j        |j        <   d nN|j        d	k    r*|j        |j        v r ||j        |j                            n                               d # t           $ r}t#          || |
          d }~ww xY wS )Nc                 :                                    | d S r9   )rr   )r   refstoss    r'   set_tosz'get_referenced_objects.<locals>.set_tos  s#    ?KKr&   )LOAD_GLOBAL	LOAD_NAME)
LOAD_DEREFLOAD_CLOSUREIMPORT_NAME)LOAD_METHOD	LOAD_ATTRIMPORT_FROMr   DELETE_FAST
STORE_FAST	LOAD_FAST)lineno)disget_instructionsstarts_lineopnameargvalr   r   r\   	importlibimport_moduleImportErrorrr   r   rQ   r  r   rR   r   )r   r+   r_  rS  operQ  rR  s         @@r'   rB  rB    s   CFD      "4(( )8 )8(	8 ~)y8889//GGOBI67777GBI&&&&<<<,RY78888m++'GI3BI>>????" ' ' 'GBI&&&&&'III;KK	****S)) 23?*CC!#ry11CCm+++$RY/l**s*.1 +k))bi7;K.K.K(34444 ?KK$$$C 	8 	8 	847777	8 Ks=   B
G!2"CG!C30G!2C33C,G!!
H+G==Hc                       e Zd ZdZdS )r   z<Placeholder class for return values when None is meaningful.N)r   r   r    r^   r%   r&   r'   r   r     s        FFDr&   r   c                   $     e Zd Z fdZd Z xZS )r   c                     |                      ||          }t          t          |                               |           |                     |j                   d S r9   )_get_messagesuperr   r?   with_traceback__traceback__r>   orig_exc
failed_objmsg	__class__s       r'   r?   zUnhashableTypeError.__init__  sT    *55!4((11#666H233333r&   c                 R    t          ||          }d|z                      d          S )Nam  
Cannot hash object of type `%(failed_obj_type_str)s`, found in %(object_part)s
%(object_desc)s.

While caching %(object_part)s %(object_desc)s, Streamlit encountered an
object of type `%(failed_obj_type_str)s`, which it does not know how to hash.

To address this, please try helping Streamlit understand how to hash that type
by passing the `hash_funcs` argument into `@st.cache`. For example:

```
@st.cache(hash_funcs={%(failed_obj_type_str)s: my_hash_func})
def my_func(...):
    ...
```

If you don't know where the object of type `%(failed_obj_type_str)s` is coming
from, try looking at the hash chain below for an object that you do recognize,
then pass that to `hash_funcs` instead:

```
%(hash_stack)s
```

Please see the `hash_funcs` [documentation](https://docs.streamlit.io/library/advanced-features/caching#the-hash_funcs-parameter)
for more details.
            rU   _get_error_message_argsstripr>   rr  rs  r.  s       r'   rm  z UnhashableTypeError._get_message  s2    &x<<
6 78 %++;	r&   )r   r   r    r?   rm  __classcell__ru  s   @r'   r   r     sG        4 4 4 4 4
" " " " " " "r&   r   c                   6     e Zd Zd fd	Zd ZdedefdZ xZS )r   Nc                     t          |          j        | _        |r|                     |||          }n|                     |||          }t          t          |                               |           |                     |j	                   d S r9   )
r   r   alternate_name_get_message_from_func_get_message_from_codern  r   r?   ro  rp  )r>   rr  cached_func_or_coder   r_  rt  ru  s         r'   r?   zUserHashError.__init__=  s    "8nn5 	U--h8KYWWCC--h8KVTTCmT""++C000H233333r&   c                     t          ||          }t          |d          rd|j        z  |d<   nd|d<   d|z                      d          S )Nr   z`%s()`hash_func_name
a functionaf  
%(orig_exception_desc)s

This error is likely due to a bug in %(hash_func_name)s, which is a
user-defined hash function that was passed into the `@st.cache` decorator of
%(object_desc)s.

%(hash_func_name)s failed when hashing an object of type
`%(failed_obj_type_str)s`.  If you don't know where that object is coming from,
try looking at the hash chain below for an object that you do recognize, then
pass that to `hash_funcs` instead:

```
%(hash_stack)s
```

If you think this is actually a Streamlit bug, please
[file a bug report here](https://github.com/streamlit/streamlit/issues/new/choose).
            rU   )rx  r  r   ry  )r>   rr  cached_funcr   r.  s        r'   r  z$UserHashError._get_message_from_funcH  se    &x==9j)) 	2%-	0B%BD!""%1D!"& '( %+++	r&   rr  r_  c                    t          ||          }t          ||          }d                    |          }t          j        |                              d          }||d<   |j        |d<   ||d<   d|z                      d          S )N rU   failing_lines_strr   r_  a  
%(orig_exception_desc)s

Streamlit encountered an error while caching %(object_part)s %(object_desc)s.
This is likely due to a bug in `%(filename)s` near line `%(lineno)s`:

```
%(failing_lines_str)s
```

Please modify the code above to address this.

If you think this is actually a Streamlit bug, you may [file a bug report
here.] (https://github.com/streamlit/streamlit/issues/new/choose)
        )rx  _get_failing_linesrZ   textwrapdedentry  r'  )r>   rr  cached_coder_  r.  failing_linesr  s          r'   r  z$UserHashError._get_message_from_codeg  s    &x==*;??GGM22$O,=>>DDTJJ$5 !&2ZX
   %++#	r&   NN)	r   r   r    r?   r  BaseExceptionr   r  r{  r|  s   @r'   r   r   <  so        	4 	4 	4 	4 	4 	4  >} SV        r&   r   c                   @     e Zd ZdZdedef fdZdededefdZ xZ	S )r   z;Exception in Streamlit hashing code (i.e. not a user error)rr  rs  c                     |                      ||          }t          t          |                               |           |                     |j                   d S r9   )rm  rn  r   r?   ro  rp  rq  s       r'   r?   zInternalHashError.__init__  sT    *55&&//444H233333r&   r-   c                 R    t          ||          }d|z                      d          S )Na  
%(orig_exception_desc)s

While caching %(object_part)s %(object_desc)s, Streamlit encountered an
object of type `%(failed_obj_type_str)s`, which it does not know how to hash.

**In this specific case, it's very likely you found a Streamlit bug so please
[file a bug report here.]
(https://github.com/streamlit/streamlit/issues/new/choose)**

In the meantime, you can try bypassing this error by registering a custom
hash function via the `hash_funcs` keyword in @st.cache(). For example:

```
@st.cache(hash_funcs={%(failed_obj_type_str)s: my_hash_func})
def my_func(...):
    ...
```

If you don't know where the object of type `%(failed_obj_type_str)s` is coming
from, try looking at the hash chain below for an object that you do recognize,
then pass that to `hash_funcs` instead:

```
%(hash_stack)s
```

Please see the `hash_funcs` [documentation](https://docs.streamlit.io/library/advanced-features/caching#the-hash_funcs-parameter)
for more details.
            rU   rw  rz  s       r'   rm  zInternalHashError._get_message  s3    &x<<
< => %++A 	r&   )
r   r   r    r^   r  r   r?   rQ   rm  r{  r|  s   @r'   r   r     sz        EE4 4C 4 4 4 4 4 4
%] % % % % % % % % % %r&   r   rr  rs  c                    t           j        j        }t           j        j        }t	          j        |          }d}||d}na|t          j        u rd}nPt          |d          rd|j	         d}nd}|t          j
        u rd}n!|t          j        u rd	}n|t          j        u rd
}t          |           |t           j                                        ||dS )Nr  	somethingza code blockr   `z()`r  zthe arguments ofzthe body ofzthe return value of)orig_exception_descfailed_obj_type_str
hash_stackobject_descobject_part)r/   r0   r)   r*   r   rP   r   r$   r  r   r!   r"   r#   rQ   r]   )rr  rs  r)   r*   r  r  r  s          r'   rx  rx    s    %1K%1K#0<<Kk1!	
0	0	0$ ;
++ 	'7k2777KK&K*666,KKJ888'KKJ:::/K  #8}}2!)6688""  r&   r_  c                     t          j        |           \  }}||z
  }t          |dz   t          |                    }|||         }|S )a;  Get list of strings (lines of code) from lineno to lineno+3.

    Ideally we'd return the exact line where the error took place, but there
    are reasons why this is not possible without a lot of work, including
    playing with the AST. So for now we're returning 3 lines near where
    the error took place.
    r   )r   getsourcelinesminrz   )r   r_  source_linessource_linenostartendliness          r'   r  r    sQ     #*"8">">L-]"E
eai\**
+
+Cs#ELr&   r  )Jr^   r:   r`  enumr,  r   re  r   r  r   r  r   r  r  rg   unittest.mockr   rb   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   streamlit.errorsr   r   streamlit.folder_black_listr   'streamlit.runtime.uploaded_file_managerr   streamlit.utilr   r   r   r  r  r   r   r  r%  
namedtupler   rQ   rM  Enumr   r5   r7   r`   r/   rm   r   r   r   r   r   r1   rB  r   r   r   r   r  rx  r  r%   r&   r'   <module>r     s   " !     



            				 				  



            L L L L L L L L L L L L L L L L L L L L 8 8 8 8 8 8 8 8 8 8 8 8 N N N N N N N N 7 7 7 7 7 7 @ @ @ @ @ @ ) ) ) ) ) )    
 U 
  
     !+
 ,L,L,L
M
M U3S	>*HcUCZ,@@A        "&*.$ $	$ $ #s(#	$
 g$ '$ 
$ $ $ $&/L /L /L /L /L /L /L /Ld       0 kmmF( F( F( F( F( F( F( F(RP' P P P P8S 8U 8 8 8 8
%hsm % % % % %PK) K) K) K) K) K) K) K)\?' ?d3i ? ? ? ?D	 	 	 	 	 	 	 	( ( ( ( (/ ( ( (VI I I I I) I I IX- - - - -2 - - -` m    cSVh        FS T#Y      r&   