+
     ]i+  c                   s   R t ^ RIHt ^ RIt^ RIHt ^ RIt^ RIt^ RIH	t	 ^ RI
t
^ RIt^ RIt^ RIt ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^RIHt ^R	IHtHt ]P@                  ! R
 R7      t! ! R R]PD                  4      t" ! R R]PF                  4      t$ ! R R]PJ                  PL                  4      t'R t(]PR                   ! R R]4      4       t*R#   ] d   t]! R4      ]hRtAii ; i)z7Displays Agg images in the browser, with interactivity.)contextmanagerN)BytesIO)Pathz$The WebAgg backend requires Tornado.)_Backend)Gcf)backend_webagg_core)TimerAsyncioTimerTornadoc                  sn    \         P                  P                  P                  4       P	                  4       # N)tornadoioloopIOLoopinstancestart     I/usr/lib64/python3.14/site-packages/matplotlib/backends/backend_webagg.py<lambda>r   '   s     7>>((11399;r   )Ztargetc                   sP   a  ] tR t^*t o ]P
                  t]RR/R l4       tRt	V t
R# )FigureManagerWebAggblockNc               s|   \         P                  4        R P                  \         P                  \         P                  \         P
                  R7      p\        P                  R,          '       d+   ^ RIpVP                  V4      '       g   \        RV 24       M\        RV 24       \         P                  4        R# )zhttp://{address}:{port}{prefix})addressportprefixzwebagg.open_in_browserNzTo view figure, visit )WebAggApplication
initializeformatr   r   
url_prefixmplrcParams
webbrowseropenprintr   )clsr   Zurlr   s   &$  r   pyplot_showZFigureManagerWebAgg.pyplot_show-   s    $$&/66%--"''$// 7 1
 <<011??3''.se45*3%01!r   r   )__name__
__module____qualname____firstlineno__coreNavigationToolbar2WebAggZ_toolbar2_classclassmethodr!   __static_attributes____classdictcell____classdict__   @r   r   r   *   s)     33O"$ " "r   r   c                   s    ] tR t^@t]tRtR# )FigureCanvasWebAggr   N)r"   r#   r$   r%   r   Zmanager_classr)   r   r   r   r.   r.   @   s    'Mr   r.   c                   s  a a ] tR t^Dt oRtRt ! R R]P                  P                  4      t	 ! R R]P                  P                  4      t
 ! R R]P                  P                  4      t ! R R	]P                  P                  4      t ! R
 R]P                  P                  4      t ! R R]P                  P                  4      tRV 3R llt]RR l4       t]R 4       tRtVtV ;t# )r   Fc                   s&   a  ] tR t^Ht o R tRtV tR# )WebAggApplication.FavIconc                s    V P                  R R4       V P                  \        \        P                  ! 4       R4      P                  4       4       R# )Content-Typez	image/pngzimages/matplotlib.pngN)
set_headerwriter   r   get_data_pathZ
read_bytesself   &r   getZWebAggApplication.FavIcon.getI   s9    OONK8JJtC--/355?Z\Cr   r   Nr"   r#   r$   r%   r7   r)   r*   r+   r-   r   FavIconr/   H   s     	C 	Cr   r9   c                   s@   a a ] tR t^Nt oRR/V 3R lltR tRtVtV ;t# )"WebAggApplication.SingleFigurePager    c               6   < W0n         \        SV `  ! W3/ VB  R # r   r   super__init__r5   Zapplicationrequestr   Zkwargs	__class__   &&&$,r   r?   Z+WebAggApplication.SingleFigurePage.__init__O       (OG[<V<r   c           	     s   \        V4      p\        P                  ! V4      pR V P                  P                   V P
                   R2pV P                  RV P
                  VV\        P                  P                  VP                  R7       R# )ws:///zsingle_figure.html)r   ws_urifig_id	toolitemscanvasN)intr   get_fig_managerrA   hostr   renderr&   r'   rI   rJ   )r5   fignummanagerrG   s   &&  r   r7   Z&WebAggApplication.SingleFigurePage.getS   st    [F))&1GT\\..//@BFKK$77AA~~  'r   r   	r"   r#   r$   r%   r?   r7   r)   r*   __classcell__rB   r,      @@r   SingleFigurePager:   N   s     	=r 	=	' 	'r   rV   c                   s@   a a ] tR t^`t oRR/V 3R lltR tRtVtV ;t# ) WebAggApplication.AllFiguresPager   r;   c               r<   r   r=   r@   rC   r   r?   Z)WebAggApplication.AllFiguresPage.__init__a   rD   r   c           	     s   R V P                   P                   V P                   R2pV P                  RV P                  V\	        \
        P                  P                  4       4      \        P                  P                  R7       R# )rE   rF   zall_figures.html)r   rG   ZfiguresrI   N)rA   rM   r   rN   Zsortedr   ZfigsZitemsr&   r'   rI   )r5   rG      & r   r7   Z$WebAggApplication.AllFiguresPage.gete   se    T\\..//@BFKK"sxx~~/077AA  Cr   rQ   rR   rT   rU   r   AllFiguresPagerW   `   s     	=r 	=	C 	Cr   rY   c                   s&   a  ] tR t^nt o R tRtV tR# )WebAggApplication.MplJsc                s    V P                  R R4       \        P                  P                  4       pV P	                  V4       R# )r0   zapplication/javascriptN)r1   r&   r   Zget_javascriptr2   )r5   Z
js_contentrX   r   r7   ZWebAggApplication.MplJs.geto   s1    OON,DE11@@BJJJz"r   r   Nr8   r+   r-   r   MplJsrZ   n   s     	# 	#r   r[   c                   s&   a  ] tR t^vt o R tRtV tR# )WebAggApplication.Downloadc                sF   \        V4      p\        P                  ! V4      pV P                  R \        P
                  P                  VR4      4       \        4       pVP                  P                  P                  WBR7       V P                  VP                  4       4       R# )r0   binary)r   N)rK   r   rL   r1   	mimetypesZ	types_mapr7   r   rJ   figureZsavefigr2   Zgetvalue)r5   rO   ZfmtrP   Zbuffs   &&&  r   r7   ZWebAggApplication.Download.getw   st    [F))&1GOO	 3 3 7 7X FH9DNN!!))$);JJt}}'r   r   Nr8   r+   r-   r   Downloadr\   v   s     	( 	(r   r`   c                   sB   a  ] tR t^t o RtR tR tR tR tR t	Rt
V tR# )	WebAggApplication.WebSocketTc                s    \        V4      V n        \        P                  ! V P                  4      V n        V P                  P                  V 4       \        V R 4      '       d   V P                  R4       R# R# )set_nodelayTN)rK   rO   r   rL   rP   Zadd_web_socketZhasattrrb   )r5   rO      &&r   r   Z WebAggApplication.WebSocket.open   sU    f+DK..t{{;DLLL''-t]++  & ,r   c                s<    V P                   P                  V 4       R # r   )rP   Zremove_web_socketr4   r6   r   on_closeZ$WebAggApplication.WebSocket.on_close   s    LL**40r   c                s    \         P                  ! V4      pVR ,          R8X  d   VR,          V n        R# \        P                  ! V P
                  4      pVe   VP                  V4       R# R# )Ztypesupports_binaryZvalueN)jsonZloadsre   r   rL   rO   Zhandle_json)r5   ZmessagerP      && r   
on_messageZ&WebAggApplication.WebSocket.on_message   s[    jj)G v"33'.w'7$--dkk: &''0 'r   c                sP    V P                  \        P                  ! V4      4       R # r   )write_messagerf   Zdumps)r5   Zcontentrc   r   	send_jsonZ%WebAggApplication.WebSocket.send_json   s    tzz'23r   c                s    V P                   '       d   V P                  VR R7       R# RP                  VP                  R4      P	                  RR4      4      pV P                  V4       R# )T)r]   zdata:image/png;base64,{}Zbase64Z
r;   N)re   ri   r   ZencodeZreplace)r5   ZblobZdata_urirg   r   send_binaryZ'WebAggApplication.WebSocket.send_binary   sX    ###""4"55<<KK)11$;=""8,r   )rO   rP   re   N)r"   r#   r$   r%   re   r   rd   rh   rj   rk   r)   r*   r+   r-   r   	WebSocketra      s(     	'	1	1	4	- 	-r   rl   c                s  < V'       d$   V^ ,          R8X  d   VR,          R8w  g   Q R4       h\         SV `  VR,           \        P                  P                  R\
        P                  P                  4       /3VR,           \        P                  P                  R\        \        P                  ! 4       R4      /3VR,           V P                  3VR,           V P                  R	V/3VR
,           V P                  R	V/3VR,           V P                  3VR,           V P                  3VR,           V P                   3.\
        P                  P                  4       R7       R# )    rF   z6url_prefix must start with a "/" and not end with one.z/_static/(.*)Zpathz/_images/(.*)Zimagesz/favicon.icoz	/([0-9]+)r   z/?z
/js/mpl.jsz/([0-9]+)/wsz/([0-9]+)/download.([a-z0-9.]+))Ztemplate_pathNi)r>   r?   r	   webZStaticFileHandlerr&   r   get_static_file_pathr   r   r3   r9   rV   rY   r[   rl   r`   )r5   r   rB   s   &&r   r?   ZWebAggApplication.__init__   sX   a=C'JrNc,A IHIA 	 ....$22GGIJL
 ....$s002H=>@
 o-t||< l*D,A,A
+- e#T%8%8
+- m+TZZ8 o-t~~> @@ ;@ 22GGIC 	 !	Kr   c                s   V P                   '       d   R # V ! VR7      pWn        R pVf   \        P                  R,          V n        MW0n        \        P                  R,          V n        V! V P
                  \        P                  R,          4       F%  p VP                  W P                  4       W n         M	  \        R4      hRV n         R #   \         d,   pTP                  \        P                  8w  d   h  R p?Kn  R p?ii ; i)NrQ   c              3  s   "   \        \        ^V4      4       F  pW,           x  K  	  \        V^,
          4       F1  pV \        P                  ! RV,          ^V,          4      ,           x  K3  	  R# 5i)z
Generate a list of n random ports near the given port.

The first 5 ports will be sequential, and the remaining n-5 will be
randomly selected in the range [port-2*n, port+2*n].
Ni)ZrangeZminrandomZrandint)r   ZnZirg   r   random_portsZ2WebAggApplication.initialize.<locals>.random_ports   sS      3q!9%h &1q5\V^^BFAE::: "s   A0A2zwebagg.addresszwebagg.portzwebagg.port_retrieszSThe webagg server could not be started because an available port could not be foundT)initializedr   r   r   r   r   ZlistenZOSErrorerrnoZ
EADDRINUSEZ
SystemExit)r    r   r   r   Zapprq   Zes   &&&&   r   r   ZWebAggApplication.initialize   s    ??? Z(#
	; ?,,'78CK!K<<. !$.C!DFD

4-
  F *+ +   77e... /s   CD D  Dc                s  a aa ^ RI p VP                  4        RS n        S P                  '       d   R#  \        P
                  P                  P                  4       oV V3R lo\        VV3R l4       pRS n        \        R4       \        P                  P                  4        V! 4       ;_uu_ 4        SP                  4        RRR4       R#   \         d     Li ; i  + '       g   i     R# ; i)rm   NTc                  s   < SP                  4        \        R 4       \        P                  P	                  4        RS n        R# )zServer is stoppedFN)Zstopr   sysstdoutflushstarted)r    r
   s   r   shutdownZ)WebAggApplication.start.<locals>.shutdown  s,    KKM%&JJCKr   c               3   s  <"   \         P                   ! \         P                  VV3R  l4      p  Rx  \         P                   ! \         P                  V 4       R#   \         P                   ! \         P                  T 4       i ; i5i)c                 s&   < SP                  S4      # r   )Zadd_callback_from_signal)ZsigZframer
   rx   s   &&r   r   Z?WebAggApplication.start.<locals>.catch_sigint.<locals>.<lambda>  s    6#B#B8#Lr   N)signalZSIGINT)Zold_handlerr
   rx   s    r   catch_sigintZ-WebAggApplication.start.<locals>.catch_sigint  sK      --LNK:fmm[9fmm[9s   +BA 'B'BBz"Press Ctrl+C to stop WebAgg server)asyncioget_running_looprw   RuntimeErrorr	   r
   r   r   r    r   rt   ru   rv   r   )r    r{   rz   r
   rx   s   f  @@r   r   ZWebAggApplication.start   s    	$$& CK;;;	 &&//1	  
	: 
	: 23

^^LLN ^M  		L ^^s   C 3CCCC0	r   )r;   )r;   NN)r"   r#   r$   r%   rr   rw   r	   rn   ZRequestHandlerr9   rV   rY   r[   r`   Z	websocketZWebSocketHandlerrl   r?   r(   r   r   r)   r*   rS   rT   rU   r   r   r   D   s     KGC'++,, C'7;;55 '$C33 C#** #(7;;-- (%-G%%66 %-N&KP + +Z + + +r   r   c                 sZ   ^ RI p\        P                  4        ^ RIp VP	                  4        V P                  p\        \        P                  P                  4       R4      P                  4       pVP                  P!                  V4      pVP#                  \        P$                  V\        P&                  P(                  V P*                  \        P,                  R7      P/                  R4      #   \
         d2    \        P                  4       '       g   \        P                  4         Li ; i)rm   Nzipython_inline_figure.html)r   rH   rI   rJ   r   zutf-8)Ztornado.templater   r   r{   r|   r}   webagg_server_threadZis_aliver   Znumberr   r&   r   ro   Z	read_textZtemplateZTemplateZgenerater   r'   rI   rJ   r   Zdecode)r_   r	   r{   rO   ZtplZts   &     r   ipython_inline_displayr   ,  s      ")  "
 ]]F
t''<<>+--6Y[ !!#&A:: ++//99}}##  %
 &,VG_5  )#,,.. &&()s   C. .$D*D*)D*c                   s    ] tR tRt]t]tRtR# )_BackendWebAggiC  r   N)	r"   r#   r$   r%   r.   ZFigureCanvasr   ZFigureManagerr)   r   r   r   r   r   C  s    %L'Mr   r   )+Z__doc__Z
contextlibr    rs   Zior   rf   r^   Zpathlibr   rp   rt   ry   Z	threadingZtornado.webr	   Ztornado.ioloopZtornado.websocketZImportErrorZerrr}   Z
matplotlibr   Zmatplotlib.backend_basesr   Zmatplotlib._pylab_helpersr   r;   r   r&   r   r   ZThreadr~   r   ZFigureCanvasWebAggCorer.   rn   ZApplicationr   r   Zexportr   r   r   r   <module>r      s    = &       
  H  - ) )  !'';= "$22 ",(44 (e// eP5. 
(X ( (S	  H
=
>CGHs   C C-	C((C-