
    et1                     Z   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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d	lmZ  ej        e          j        Z ej        e          j        d
z  dz  ZddZddZd Zd Z ddZ!ddZ"ddZ#ddZ$ddZ%ddZ&dS )z9
Utilities for building custom models included in panel.
    N)Model   )configpanel_extension)RESOURCE_URLS)ReactiveHTML)BasicTemplate)Designdistbundledc                    |                      d          d                                         }|D ]}|                    d          s\t          |                                 z  |z  }|j                            dd           t          j        t          dz  |z  |           t|                     d          d         }	 t          j
        |          }nT# t          $ rG 	 t          j
        |d	
          }n,# t          $ r}t          d|  d| d| d          |d }~ww xY wY nw xY w	 | d}	t          j
        |	          }
n:# t          $ r- 	 t          j
        |	d	
          }
n# t          $ r d }
Y nw xY wY nw xY w|                    t          j                  rEt          j        j        |                    t          j        d                               d           }nZt          j        j        t          j        j        |                     d          dd                                d          dd           }|p|}t                              ||          }|j                            dd           t)          |          }|r*t)          |                              |          s|d| z  }|                    d          rCt-          |d          5 }|                    |j                   d d d            n# 1 swxY w Y   nY|j                            d          }t-          |dd          5 }|                    |           d d d            n# 1 swxY w Y   |
rZt-          | ddd          5 }|                    |
j                            d                     d d d            n# 1 swxY w Y   d S )N.httpTparentsexist_oktheme?r   FverifyzFailed to fetch z dependency: z. Errored with z.map /z//r   .ttfwbutf-8wencoding)splitlower
startswith
BUNDLE_DIRparentmkdirshutilcopyfileBASE_DIRrequestsget	ExceptionConnectionErrorr   npm_cdnospathjoinreplacejoinpathstrendswithopenwritecontentdecode)namefilesexplicit_dirext
model_namebundle_file	dest_pathresponseemap_filemap_responsebundle_pathobj_dirfilenamefr7   s                   .lib/python3.11/site-packages/panel/compiler.pywrite_bundled_filesrI       s   C$**,,J ,> ,>%%f-- 	"TZZ\\1K?I""4$"???OHw.<iHHH!'',,Q/	|K00HH 	 	 	#<EBBB   %ZtZZ+ZZVWZZZ  		$%+++H#<11LL 	$ 	$ 	$$'|HUCCC $ $ $#$	$
 !!&.11 	c',(;(;FNB(O(O(U(UVY(Z(Z[KK',k6G6G6M6Mabb6Q(R(X(XY\(](]^_^`^`(abK,*&&w<<dT:::x== 	"s8}}--c22 	"	C		!HV$$ 	!h%% *()))* * * * * * * * * * * * * * * &--g66Ghg666 !!   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 	>'''w??? >1,33G<<===> > > > > > > > > > > > > > >W,> ,>s    C
D& C76D&7
D DD  D&%D&*E
E;E&%E;&E52E;4E55E;:E;K>>L	L	6MM	M	:.N44N8	;N8	Fc                    |r-|                     d          d                                         nd}	 t          j        | d                   }n,# t          $ r t          j        | d         d          }Y nw xY wt          j                    }|                    |j                   |	                    d           t          j        |          }|                     d	g           }|D ]Tj                            | d
                   r                                s8j                            | d
         d          }t!          fd|D                       rut#          j        j        |                     d           }	| d                             dt"          j        j                  }
|rt*                              ||
|	          nt*                              |
|	          j                            dd           |                    j                  }t5                    |r9                    d          r$d d                             d          rdz  t!          fddD                       rS|                                }t          d          5 }|                    |           d d d            n# 1 swxY w Y   |                                                    d          }t          dd          5 }|                    |           d d d            n# 1 swxY w Y   V|                                 d S )Nr   r   r   tarFr   r   )fileobjexcludesrcc              3   L   K   | ]}t          j         j        |          V  d S N)fnmatchr9   ).0exctarfs     rH   	<genexpr>z(write_bundled_tarball.<locals>.<genexpr>_   s1      BB3wty#..BBBBBB    r   destTr   z.jsindexz.mjsc              3   B   K   | ]}                     |          V  d S rP   r4   rR   ftrF   s     rH   rU   z(write_bundled_tarball.<locals>.<genexpr>n   1      SSx  $$SSSSSSrV   r   z.eotz.woffz.woff2r   r   r   r   )r    r!   r)   r*   r+   ioBytesIOr6   r7   seektarfiler5   r9   r"   isfiler1   anyr.   r/   r0   sepr#   r2   r$   r%   extractfiler3   r4   readr8   close)tarballr9   moduler=   r@   rG   tar_objrM   r/   rD   r?   fobjr7   rF   rT   s                @@rH   write_bundled_tarballrn   P   s   04<C$**,,,"J><// > > ><u===>

AGGHFF1IIIl1%%%Gkk)R((G ! !y##GEN33 	4;;== 	y  44BBBB'BBBBB 	glDJJsOO4FO++C==	 	C!**:y+NNHH!**9kBBHdT:::""49--x== 	#h''.. 	#}H  )) #F"SSSS/RSSSSS 	!iikkGh%% !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! iikk((11Ghg666 !!   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !MMOOOOOs5   A &A98A9*KK	K	L44L8	;L8	c                   	
 	 t          j        |d                   }n,# t          $ r t          j        |d         d          }Y nw xY wt          j                    }|                    |j                   |                    d           t          j	        |          }|                    dg           }|
                                D ]|

                    |d         d          }t          
fd|D                       s
                    d	          rP|                    d	t          j        j                  }t"                              | |          		j                            d
d
           |                    
          }t-          	          	t          	fddD                       r?t/          	d          5 }|                    |           d d d            n# 1 swxY w Y   *t/          	dd          5 }|                    |                    d                     d d d            n# 1 swxY w Y   ~|                                 d S )NzipFr   r   rM   rN   r   c              3   B   K   | ]}t          j         |          V  d S rP   )rQ   )rR   rS   zipfs     rH   rU   z$write_bundled_zip.<locals>.<genexpr>   s/      ==cwtS))======rV   r   Tr   c              3   B   K   | ]}                     |          V  d S rP   r[   r\   s     rH   rU   z$write_bundled_zip.<locals>.<genexpr>   r^   rV   r_   r   r   r   r   )r)   r*   r+   r`   ra   r6   r7   rb   zipfileZipFilenamelistr1   re   r4   r.   r/   rf   r#   r2   r$   r%   rh   r3   r5   r8   ri   )r9   resourcer@   rG   zip_objrM   r/   rD   fdatarF   rr   s            @@rH   write_bundled_ziprz   x   s   ?<00 ? ? ?<>>>?

AGGHFF1IIIoa  Gll9b))G  "" / /||HUOR00====W===== 	sASAS 	ll344&&t[99dT:::T""x==SSSS/RSSSSS 	/h%%                hg666 /!W--.../ / / / / / / / / / / / / / /MMOOOOOs3    &AAG((G,	/G,	)H<<I 	I 	c           	         t          | t          |j                            di                                                     t
          d           t          | t          |j                            di                                                     t
          d           g }|j                            di                                           D ]7\  }}||j                            di           vr|                    |           8t          | |dd           |j                            di                                           D ]}t          |           d S )Ncssjs
js_modulesrj   mjs)r<   )	rI   list
_resourcesr*   valuesr#   itemsappendrn   )r9   	componentr~   tar_name	js_modulerj   s         rH   write_component_resourcesr      sG   d9#7#;#;E2#F#F#M#M#O#OPPR\^cdddd9#7#;#;D"#E#E#L#L#N#NOOQ[]abbbJ(377bIIOOQQ ) ))9/33IrBBBBi(((j$E::::'++Ir::AACC ' 'g&&&&' 'rV   Tc                     t          j                    D ]D\  }}| rt          d| d           d|v rt          ||           /d|v rt	          ||           Ed S )NzBundling shared resource r   rp   rK   r9   )r   r   printrz   rn   )verboseexternalr9   rw   s       rH   bundle_resource_urlsr      s    '-// 7 7h 	75d555666HdH----h!(66667 7rV   c           	      6   t          j        t                                                    D ]\  }}| rt	          d| d           |j                            dd          r|rt          ||           t          j	        t          j        |                    j        }t          |                                z  }|                    dd           t!          j        t#          |dz                      D ]7}t%          j        ||t(          j                            |          z             8|j        }t1          |t2                    s|r|gng }|D ]}|                                }|j        dd          D ]^}	t7          |	t                    st1          |	j        t2                    r|	j        n|	j        g}
||
v r|	j                                        }_t          |z  }|                    dd           t%          j        ||t(          j                            |          z             |j        }t1          |t2                    s|r|gng }|D ]}|                                }|j        dd          D ]^}	t7          |	t                    st1          |	j        t2                    r|	j        n|	j        g}||v r|	j                                        }_t          |z  }t%          j        ||t(          j                            |          z             Đd S )N	Bundling 
 resourcesbundleTr   *.cssr   )paramconcrete_descendentsr	   r   r   r   r*   r   pathlibPathinspectgetfiler$   r#   r!   r%   globr3   r&   r'   r.   r/   basename_css
isinstancer   __mro__
issubclass__name___js)r   r   r9   templatetemplate_dirdest_dirr|   template_css	tmpl_nameclstmpl_csstmpl_dest_dirtemplate_jsr}   tmpl_jss                  rH   bundle_templatesr      s   4]CCIIKK ,F ,Fh 	0.d.../// ""8T22 	6x 	6%dH555 |GOH$=$=>>E

,td3339S!78899 	C 	CCOCBG,<,<S,A,A!ABBBB  },-- 	B-9AL>>rL 
	H 
	HC

I'+ 5 5!#}55 '1#(D'A'AQ388z(?? # 2 2 4 4I&2Mt<<<OC1A1A#1F1F!FGGGG l+t,, 	?+6>;--BK 		F 		FB

I'+ 5 5!#}55 %/%>%>M#''SWI== # 2 2 4 4I&2MOB0@0@0D0D DEEEE		FG,F ,FrV   c                    t          j        t                                                    D ]G\  }}| rt	          d| d           |j                            dd          r|rt          ||           Ht          dz  }|	                    dd           t          j
        t          t          dz  dz  dz                      D ]7}t          j        ||t          j                            |          z             8d S )	Nr   z design resourcesr   Tr   r   r|   r   )r   r   r
   r   r   r   r*   r   r#   r%   r   r3   r(   r&   r'   r.   r/   r   )r   r   r9   designtheme_bundle_dir
design_csss         rH   bundle_themesr      s   26::@@BB 4 4f 	75d555666   400 	4X 	4%dF333!G+4$777iHw$6$>$H I IJJ U U

$4rw7G7G
7S7S$STTTTU UrV   c                    t           j                                        D ]&}|                    d          rt	          |           '|sd S i i i }}}t          j        t                                                    }t          t          j
                                                  d |D             z   }|D ]?\  }}	|                    d          s| rt          d| d           t          |	dd           }
t          |	dd           }|	}|	j        dd          D ]:}t          |dd           }||
|||
k    r|r|||j        <   n
|
||j        <    n|};t          |	d	d           }|	}|	j        dd          D ]-}t          |d	d           }|||||k    r|||j        <    n|}.t          |	d
d           }|	}|	j        dd          D ]-}t          |d
d           }|||||k    r|||j        <    n|}.A|                                D ]Q\  }}| rt          d| d           t!          |t"                    rt%          ||           At'          ||           R|                                D ]*\  }}| rt          d| d           t'          ||           +|                                D ]\  }}t'          ||           d S )Nzpanel.modelsc                 4    g | ]}|j          d |j         |fS )r   )
__module__r   )rR   ms     rH   
<listcomp>z!bundle_models.<locals>.<listcomp>   s/    ???Q\
(
(AJ
(
(!	,???rV   zpanel.zCollecting r   __javascript_raw____tarball__r   __css_raw____resources__r   z model JS resourcesr   z model CSS resources)r   _importsr   r"   
__import__r   r   r   r   r   model_class_reverse_mapr   r   getattrr   r   r   dictrn   rI   )r   r   impjs_files	css_filesresource_filesreactivemodelsr9   modelprev_jsfilesprev_jsbundleprev_clsr   jsfilesprev_cssfilescssfilesprev_resources	resources	res_filess                       rH   bundle_modelsr      s   '..00  >>.)) 	sOOO  +-b"iH),77>>@@HU*002233??h???	@   # #ex(( 	 	20000111u&:DAA}d;;=$ 		 		Cc#7>>G\%=$L)@)@  ?2?HX.//2>HX./HH}d;;=$ 	 	CsM488H!m&?%(m*C*C/<	(+,HH >>=$ 	 	C_d;;I"~'A&9+F+F4Bx01HH ")) / /g 	97d777888gt$$ 	/!'55555g....#//++ , ,h 	:8d888999D(++++)//11 - -iD),,,,- -rV   c                 X   t           dz  }|                    dd           t          j        t                    j        j        dz  dz  dz  }t          j        t          |dz                      D ]7}t          j	        ||t          j                            |          z             8d S )NimagesTr   doc_staticicons*)r#   r%   r   r   __file__r$   r   r3   r&   r'   r.   r/   r   )r   r   r   icon_diricons        rH   bundle_iconsr   .  s    H$HNN4$N///|H%%,3e;iG'QH	#hn--.. A Ah)9)9$)?)??@@@@A ArV   c                     t          | |           t          | |           t          | |           t          | |           t	          | |           d S )Nr   r   )r   r   r   r   r   r   s     rH   bundle_resourcesr   6  sg    8<<<<'H5555Wx8888'H55558444444rV   )NN)NF)FT)'__doc__rQ   r   r   r`   r.   r   r&   rc   rt   r   r)   bokeh.modelr   r   r   io.resourcesr   r   r   template.baser	   r   r
   r   r   r$   r(   r#   rI   rn   rz   r   r   r   r   r   r   r    rV   rH   <module>r      s       				 				             + + + + + + + + ' ' ' ' ' ' " " " " " " ( ( ( ( ( (      7<!!(W\(##*V3i?
.> .> .> .>`& & & &P  6	' 	' 	'7 7 7 7.F .F .F .FbU U U U C- C- C- C-JA A A A5 5 5 5 5 5rV   