L idZddlZddlZddlZddlZddlZddlZddlmZddl m Z dZ GddZ Gdd Zd d Zdd Z d dd Zy)z A Simple server used to show altair graphics from a prompt or script. This is adapted from the mpld3 package; see https://github.com/mpld3/mpld3/blob/master/mpld3/_server.py N)server)BytesIOz Note: if you're in the Jupyter notebook, Chart.serve() is not the best way to view plots. Consider using Chart.display(). You must interrupt the kernel to cancel this command. ceZdZdZdZy) MockRequestctdS)NsGET /)IO)selfargskwargss Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/altair/utils/server.pymakefilezMockRequest.makefiles (|cyN)r responses r sendallzMockRequest.sendall rN)__name__ __module__ __qualname__r rrrr rrs  rrceZdZdZdZdZy) MockServerc.|t|d|y)Nr)r)r ip_portHandlers r __init__zMockServer.__init__$s wqz40rcyrrr s r serve_foreverzMockServer.serve_forever'rrcyrrrs r server_closezMockServer.server_close*rrN)rrrrr r"rrr rr#s1  rrcJiGfddtj}|S)NceZdZfdZy)#generate_handler..MyHandlerc|jdk(r]|jd|jdd|j|jj j y|jvro|j\}}|jd|jd||j|jj |j y|jdy)zRespond to a GET request./z Content-typez text/htmliN)path send_response send_header end_headerswfilewriteencode send_error)r content_typecontentfileshtmls r do_GETz*generate_handler..MyHandler.do_GET3syyC""3'  =  "   /e#(-dii(8% g""3'  >  "   !12$rN)rrrr5)r3r4sr MyHandlerr%2s %rr6)rBaseHTTPRequestHandler)r4r3r6s`` r generate_handlerr8.s' }%F11%" rc rtjfdt|Dtjd|zd|zz}|D]`t j t j t j}|j|f}|j|dk7s^cSd}t|)z*Find an open port near the specified port.c3(K|] }|z ywrr).0iports r z!find_open_port..Is$a$srzno open ports found) itertoolschainrangerandomrandintsocketAF_INET SOCK_STREAM connect_exclose ValueError)ipr=nportssresultmsgs ` r find_open_portrRFs OO$58$tfnnR!VQU.K'K E MM&..&*<*< =r4j)  Q;K  C S/rct|t||}|tjf|} n |f|} |r tt t t dddtjj|r*fd} tj| j | j| j#y#t$rYwxYw#tt f$rt dY.bs??WRD$#89 9r)targetz stopping Server...)rRr8r HTTPServer __IPYTHON__printJUPYTER_WARNING NameErrorsysstdoutflush threadingThreadstartr KeyboardInterrupt SystemExitr") r4rLr= n_retriesr3jupyter_warning open_browser http_serverrsrvrrXs `` r serverlVsB "dI .DtU+G  "dW5B:w/ #  / " rd!D6)> ?@JJ : "((*&  +   $ z *& $%&s$C7C' C$#C$'DDr)2)z 127.0.0.1i"rmNTTN)returnN)__doc__rArDrFr_rbrVhttpriorrr]rrr8rRrlrrr rrsq     0 $  A Ar