rL i+dZddlmZddlZddlmZddlZddlZddlm Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlmZddlmZd d lmZd d lmZmZe j@d Z!GddejDZ"GddejFZ$GddejJjLZ'dZ(ejRGddeZ*y#e$rZededZ[wwxYw)z7Displays Agg images in the browser, with interactivity.)contextmanagerN)BytesIO)Pathz$The WebAgg backend requires Tornado.)_Backend)Gcf)backend_webagg_core) TimerAsyncio TimerTornadocntjjjj SN)tornadoioloopIOLoopinstancestarth/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/backends/backend_webagg.pyr's"7>>((11399;r)targetc:eZdZejZedddZy)FigureManagerWebAggN)blockcZtjdjtjtjtj }t jdr$ddl}|j|std|ntd|tjy)Nzhttp://{address}:{port}{prefix})addressportprefixzwebagg.open_in_browserrzTo view figure, visit ) WebAggApplication initializeformatrr url_prefixmplrcParams webbrowseropenprintr)clsrurlr%s r pyplot_showzFigureManagerWebAgg.pyplot_show-s$$&/66%--"''$//71 <<0 1 ??3'.se45 *3%0 1!r)__name__ __module__ __qualname__coreNavigationToolbar2WebAgg_toolbar2_class classmethodr*rrrrr*s"33O"&""rrceZdZeZy)FigureCanvasWebAggN)r+r,r-r manager_classrrrr3r3@s'Mrr3ceZdZdZdZGddej jZGddej jZ Gddej jZ Gdd ej jZ Gd d ej jZ Gd d ejjZdfd ZeddZedZxZS)rFceZdZdZy)WebAggApplication.FavIconc|jdd|jttjdj y)N Content-Typez image/pngzimages/matplotlib.png) set_headerwriterr# get_data_path read_bytesselfs rgetzWebAggApplication.FavIcon.getIs9 OONK 8 JJtC--/355?Z\ CrNr+r,r-r@rrrFavIconr7Hs CrrBc*eZdZddfd ZdZxZS)"WebAggApplication.SingleFigurePager"c 6||_t|||fi|yr r"super__init__r? applicationrequestr"kwargs __class__s rrJz+WebAggApplication.SingleFigurePage.__init__O(DO G [' s ron_closez$WebAggApplication.WebSocket.on_closes LL * *4 0rctj|}|ddk(r |d|_ytj|j }||j |yy)Ntypesupports_binaryvalue)jsonloadsrrrYr\ handle_json)r?messager]s r on_messagez&WebAggApplication.WebSocket.on_messages[jj)Gv"33'.w'7$--dkk:&''0'rcL|jtj|yr ) write_messagerdumps)r?contents r send_jsonz%WebAggApplication.WebSocket.send_jsons   tzz'2 3rc|jr|j|dydj|jdj dd}|j|y)NT)rtzdata:image/png;base64,{}base64 rE)rrr!encodereplace)r?blobdata_uris r send_binaryz'WebAggApplication.WebSocket.send_binarysU##""4"55<<KK)11$;=""8,rN) r+r,r-rr&rrrrrrr WebSocketr~s  ' 1 1 4 -rrc R|r|ddk(r|ddk7sJdt||dztjjdt j jif|dztjjdttjdif|d z|jf|d z|jd |if|d z|jd |if|d z|jf|dz|jf|dz|j fgt j jy)NrrSz6url_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_path)rIrJrwebStaticFileHandlerr.rget_static_file_pathrr#r<rBrarjrprr|)r?r"rOs rrJzWebAggApplication.__init__sX a=C'JrNc,A IH IA ....$22GGIJL ....$s002H=>@ o-t||<l*D,A,A +-e#T%8%8 +-m+TZZ8o-t~~>@@ ; @22GGIC ! Krc|jry||}||_d}|tjd|_n||_tjd|_||j tjdD].} |j ||j||_d|_ytd#t$r(}|jtjk7rYd}~hd}~wwxYw)NrFc3Kttd|D] }||z t|dz D]#}|tjd|zd|zz%yw)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)rangeminrandomrandint)rnis r random_portsz2WebAggApplication.initialize..random_portss`3q!9% Qh 1q5\ ;V^^BFAE::: ;sAAzwebagg.addressz webagg.portzwebagg.port_retrieszSThe webagg server could not be started because an available port could not be foundT) initializedr"r#r$rrlistenOSErrorerrno EADDRINUSE SystemExit)r(r"rrappres rr zWebAggApplication.initializes ?? Z(# ; ?,,'78CK!CK<< . !$.C!DF +D  4-    +*+ + 77e.../ sB;; C,C''C,cddl} |jd_jry tj j jfdtfd}d_tdtjj|5jdddy#t$rYwxYw#1swYyxYw)NrTcjtdtjj d_y)NzServer is stoppedF)stopr'sysstdoutflushstarted)r(rsrshutdownz)WebAggApplication.start..shutdowns, KKM % & JJ   CKrc3Ktjtjfd} dtjtj|y#tjtj|wxYww)Nc&jSr )add_callback_from_signal)sigframerrs rrz?WebAggApplication.start..catch_sigint..s6#B#B8#Lr)signalSIGINT) old_handlerrrs r catch_sigintz-WebAggApplication.start..catch_sigintsL -- LNK : fmm[9 fmm[9s)A?A%A?&A<<A?z"Press Ctrl+C to stop WebAgg server)asyncioget_running_loopr RuntimeErrorrrrrrr'rrrr)r(rrrrs` @@rrzWebAggApplication.starts   $ $ &CK ;;  &&//1  :  :  23  ^  LLN  M   L  sB<"C < CC C)rE)rENN)r+r,r-rrrrRequestHandlerrBrarjrpr| websocketWebSocketHandlerrrJr1r rr_r`s@rrrDsKGC'++,,C '7;;55'$ C33 C# **#(7;;--(%-G%%66%-N&KP++Z++rrcJddl}tjddl} |j |j}ttjjdj}|jj!|}|j#tj$|tj&j(|j*tj,j/dS#t $r+t jst jYwxYw)Nrzipython_inline_figure.html)rrUrVrWrzutf-8)tornado.templaterr rrrwebagg_server_threadis_alivernumberrr.rr read_texttemplateTemplategenerater"r/rVrWrdecode)rwrrr\tplts ripython_inline_displayr,s  ")  " ]]F t''<<>+ --6Y[!!#&A :: ++//99}}  # #  % &,VG_ 5 )#,,. & & ()sC..1D"!D"ceZdZeZeZy)_BackendWebAggN)r+r,r-r3 FigureCanvasr FigureManagerrrrrrCs %L'Mrr)+__doc__ contextlibrriorrrupathlibrrrr threading tornado.webrtornado.iolooptornado.websocket ImportErrorerrr matplotlibr#matplotlib.backend_basesrmatplotlib._pylab_helpersrrEr r.r r ThreadrrFigureCanvasWebAggCorer3r Applicationrrexportrrrrrs=&   H-)) (y'' ;="$22",(44(e //eP5. (X((S H = >CGHs CC* C%%C*