+
    i+                        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                  n    \         P                  P                  P                  4       P	                  4       # N)tornadoioloopIOLoopinstancestart     ڂ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/matplotlib/backends/backend_webagg.py<lambda>r   '   s     7>>((11399;r   )targetc                   P   a  ] tR t^*t o ]P
                  t]RR/R l4       tRt	V t
R# )FigureManagerWebAggblockNc               |   \         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   urlr#   s   &$  r   pyplot_show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NavigationToolbar2WebAgg_toolbar2_classclassmethodr(   __static_attributes____classdictcell____classdict__s   @r   r   r   *   s)     33O"$ " "r   r   c                       ] tR t^@t]tRtR# )FigureCanvasWebAggr   N)r*   r+   r,   r-   r   manager_classr2   r   r   r   r7   r7   @   s    'Mr   r7   c                     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                   &   a  ] tR t^Ht o R tRtV tR# )WebAggApplication.FavIconc                    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_path
read_bytesselfs   &r   getWebAggApplication.FavIcon.getI   s9    OONK8JJtC--/355?Z\Cr   r   Nr*   r+   r,   r-   rD   r2   r3   r4   s   @r   FavIconr;   H   s     	C 	Cr   rG   c                   @   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__rC   applicationrequestr    kwargs	__class__s   &&&$,r   rN   +WebAggApplication.SingleFigurePage.__init__O       (OG[<V<r   c           	        \        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_managerrQ   hostr    renderr.   r/   r[   r\   )rC   fignummanagerrY   s   &&  r   rD   &WebAggApplication.SingleFigurePage.getS   st    [F))&1GT\\..//@BFKK$77AA~~  'r   r    	r*   r+   r,   r-   rN   rD   r2   r3   __classcell__rS   r5   s   @@r   SingleFigurePagerI   N   s     	=r 	=	' 	'r   rh   c                   @   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    rJ   c               6   < W0n         \        SV `  ! W3/ VB  R # r   rL   rO   s   &&&$,r   rN   )WebAggApplication.AllFiguresPage.__init__a   rU   r   c           	        R V P                   P                   V P                   R2pV P                  RV P                  V\	        \
        P                  P                  4       4      \        P                  P                  R7       R# )rW   rX   zall_figures.html)r   rY   figuresr[   N)rQ   r_   r    r`   sortedr   figsitemsr.   r/   r[   )rC   rY   s   & r   rD   $WebAggApplication.AllFiguresPage.gete   se    T\\..//@BFKK"sxx~~/077AA  Cr   rd   re   rg   s   @@r   AllFiguresPagerj   `   s     	=r 	=	C 	Cr   rs   c                   &   a  ] tR t^nt o R tRtV tR# )WebAggApplication.MplJsc                    V P                  R R4       \        P                  P                  4       pV P	                  V4       R# )r=   zapplication/javascriptN)r>   r.   r   get_javascriptr?   )rC   
js_contents   & r   rD   WebAggApplication.MplJs.geto   s1    OON,DE11@@BJJJz"r   r   NrF   r4   s   @r   MplJsru   n   s     	# 	#r   rz   c                   &   a  ] tR t^vt o R tRtV tR# )WebAggApplication.Downloadc                F   \        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# )r=   binary)r   N)r]   r   r^   r>   	mimetypes	types_maprD   r   r\   figuresavefigr?   getvalue)rC   ra   fmtrb   buffs   &&&  r   rD   WebAggApplication.Download.getw   st    [F))&1GOO	 3 3 7 7X FH9DNN!!))$);JJt}}'r   r   NrF   r4   s   @r   Downloadr|   v   s     	( 	(r   r   c                   B   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                    \        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)r]   ra   r   r^   rb   add_web_sockethasattrr   )rC   ra   s   &&r   r$    WebAggApplication.WebSocket.open   sU    f+DK..t{{;DLLL''-t]++  & ,r   c                <    V P                   P                  V 4       R # r   )rb   remove_web_socketrB   s   &r   on_close$WebAggApplication.WebSocket.on_close   s    LL**40r   c                    \         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# )typesupports_binaryvalueN)jsonloadsr   r   r^   ra   handle_json)rC   messagerb   s   && r   
on_message&WebAggApplication.WebSocket.on_message   s[    jj)G v"33'.w'7$--dkk: &''0 'r   c                P    V P                  \        P                  ! V4      4       R # r   )write_messager   dumps)rC   contents   &&r   	send_json%WebAggApplication.WebSocket.send_json   s    tzz'23r   c                    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,{}base64
rJ   N)r   r   r   encodereplace)rC   blobdata_uris   && r   send_binary'WebAggApplication.WebSocket.send_binary   sX    ###""4"55<<KK)11$;=""8,r   )ra   rb   r   N)r*   r+   r,   r-   r   r$   r   r   r   r   r2   r3   r4   s   @r   	WebSocketr      s(     	'	1	1	4	- 	-r   r   c                  < 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# )    rX   z6url_prefix must start with a "/" and not end with one.z/_static/(.*)pathz/_images/(.*)imagesz/favicon.icoz	/([0-9]+)r    z/?z
/js/mpl.jsz/([0-9]+)/wsz/([0-9]+)/download.([a-z0-9.]+))template_pathN)rM   rN   r   webStaticFileHandlerr.   r   get_static_file_pathr   r!   r@   rG   rh   rs   rz   r   r   )rC   r    rS   s   &&r   rN   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                   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)Nrd   c              3     "   \        \        ^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].
N)rangeminrandomrandint)r   nis   && r   random_ports2WebAggApplication.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   listenOSErrorerrno
EADDRINUSE
SystemExit)r&   r    r   r   appr   es   &&&&   r   r   WebAggApplication.initialize   s    ??? Z(#
	; ?,,'78CK!K<<. !$.C!DFD

4-
  F *+ +   77e... /s   CD D  Dc                  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)r   NTc                     < SP                  4        \        R 4       \        P                  P	                  4        RS n        R# )zServer is stoppedFN)stopr%   sysstdoutflushstarted)r&   r   s   r   shutdown)WebAggApplication.start.<locals>.shutdown  s,    KKM%&JJCKr   c               3     <"   \         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P                  S4      # r   )add_callback_from_signal)sigframer   r   s   &&r   r   ?WebAggApplication.start.<locals>.catch_sigint.<locals>.<lambda>  s    6#B#B8#Lr   N)signalSIGINT)old_handlerr   r   s    r   catch_sigint-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_loopr   RuntimeErrorr   r   r   r   r   r%   r   r   r   r   )r&   r   r   r   r   s   f  @@r   r   WebAggApplication.start   s    	$$& CK;;;	 &&//1	  
	: 
	: 23

^^LLN ^M  		L ^^s   C 3CCCC0	r   )rJ   )rJ   NN)r*   r+   r,   r-   r   r   r   r   RequestHandlerrG   rh   rs   rz   r   	websocketWebSocketHandlerr   rN   r1   r   r   r2   r3   rf   rg   s   @@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                 Z   ^ 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)r   Nzipython_inline_figure.html)r   rZ   r[   r\   r   zutf-8)tornado.templater   r   r   r   r   webagg_server_threadis_aliver   numberr   r.   r   r   	read_texttemplateTemplategenerater    r/   r[   r\   r   decode)r   r   r   ra   tplts   &     r   ipython_inline_displayr   ,  s      ")  "
 ]]F
t''<<>+--6Y[ !!#&A:: ++//99}}##  %
 &,VG_5  )#,,.. &&()s   C. .$D*D*)D*c                       ] tR tRt]t]tRtR# )_BackendWebAggiC  r   N)	r*   r+   r,   r-   r7   FigureCanvasr   FigureManagerr2   r   r   r   r   r   C  s    %L'Mr   r   )+__doc__
contextlibr   r   ior   r   r   pathlibr   r   r   r   	threadingtornado.webr   tornado.iolooptornado.websocketImportErrorerrr   
matplotlibr!   matplotlib.backend_basesr   matplotlib._pylab_helpersr   rJ   r   r.   r   r	   Threadr   r   FigureCanvasWebAggCorer7   r   Applicationr   r   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-