
    ch                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r  Sr " S S5      r " S S	5      rSS
 jrSS jr       S SS jjrg)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.
c                        \ rS rSrS rS rSrg)MockRequest   c                     [        S5      $ )Ns   GET /)IO)selfargskwargss      fC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\altair/utils/server.pymakefileMockRequest.makefile   s    (|    c                     g N )r
   responses     r   sendallMockRequest.sendall       r   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__r   r   r   r   r      s    r   r   c                   &    \ rS rSrS rS rS rSrg)
MockServer#   c                 .    U" [        5       US   U 5        g )Nr   )r   )r
   ip_portHandlers      r   __init__MockServer.__init__$   s    wqz40r   c                     g r   r   r
   s    r   serve_foreverMockServer.serve_forever'   r   r   c                     g r   r   r&   s    r   server_closeMockServer.server_close*   r   r   r   N)r   r   r   r   r#   r'   r*   r   r   r   r   r   r   #   s    1r   r   c                 N   ^ ^ Tc  0 m " UU 4S jS[         R                  5      nU$ )Nc                   $   > \ rS rSrU U4S jrSrg)#generate_handler.<locals>.MyHandler2   c                   > U R                   S:X  a]  U R                  S5        U R                  SS5        U R                  5         U R                  R                  TR                  5       5        gU R                   T;   an  TU R                      u  pU R                  S5        U R                  SU5        U R                  5         U R                  R                  UR                  5       5        gU R                  S5        g)zRespond to a GET request./   zContent-typez	text/htmli  N)pathsend_responsesend_headerend_headerswfilewriteencode
send_error)r
   content_typecontentfileshtmls      r   do_GET*generate_handler.<locals>.MyHandler.do_GET3   s    yyC""3'  =  "

  /e#(-dii(8%""3'  >  "

  !12$r   r   N)r   r   r   r   r?   r   )r=   r>   s   r   	MyHandlerr.   2   s    	% 	%r   rA   )r   BaseHTTPRequestHandler)r>   r=   rA   s   `` r   generate_handlerrC   .   s,    }% %F11 %" r   c           	        ^ [         R                  " U4S j[        U5       5       T[        R                  " SU-  SU-  5      -   5      nU Hc  m[
        R
                  " [
        R                  [
        R                  5      nUR                  U T45      nUR                  5         US:w  d  Ma  Ts  $    Sn[        U5      e)z*Find an open port near the specified port.c              3   .   >#    U  H
  nTU-   v   M     g 7fr   r   ).0iports     r   	<genexpr>!find_open_port.<locals>.<genexpr>I   s     $8a8s      r   zno open ports found)	itertoolschainrangerandomrandintsocketAF_INETSOCK_STREAM
connect_exclose
ValueError)iprH   nportssresultmsgs    `     r   find_open_portr^   F   s    OO$58$tfnnR!VQU.K'KE MM&..&*<*<=r4j)		Q;K   C
S/r   c                 &  ^^ [        TTU5      m[        X5      nUc  [        R                  " TT4U5      n	OU" TT4U5      n	U(       a   [          [        [        5        [        ST ST S35        [        R                  R                  5         U(       a)  UU4S jn
[        R                  " U
S9R                  5          U	R                  5         U	R#                  5         g! [         a     Nf = f! [        [         4 a    [        S5         N>f = f)a-  
Start a server serving the given HTML, and (optionally) open a browser.

Parameters
----------
html : string
    HTML to serve
ip : string (default = '127.0.0.1')
    ip address at which the HTML will be served.
port : int (default = 8888)
    the port at which to serve the HTML
n_retries : int (default = 50)
    the number of nearby ports to search if the specified port is in use.
files : dictionary (optional)
    dictionary of extra content to serve
jupyter_warning : bool (optional)
    if True (default), then print a warning if this is used within Jupyter
open_browser : bool (optional)
    if True (default), then open a web browser to the given HTML
http_server : class (optional)
    optionally specify an HTTPServer class to use for showing the
    figure. The default is Python's basic HTTPServer.
NzServing to http://:z/    [Ctrl-C to exit]c                  <   > [         R                  " ST  ST 35      $ )Nzhttp://r`   )
webbrowseropen)rX   rH   s   r   bserve.<locals>.b   s    ??WRD$#899r   )targetz
stopping Server...)r^   rC   r   
HTTPServer__IPYTHON__printJUPYTER_WARNING	NameErrorsysstdoutflush	threadingThreadstartr'   KeyboardInterrupt
SystemExitr*   )r>   rX   rH   	n_retriesr=   jupyter_warningopen_browserhttp_serverr"   srvrrd   s    ``        r   servery   V   s    B "dI.Dt+G  "dW5B:w/	# /" 
rd!D6)>
?@JJ	: 	"((*& 	+  		$ z* &$%&s$   C" C2 "
C/.C/2DDr   )r/   )z	127.0.0.1i"  r/   NTTN)returnN)__doc__rM   rP   rR   rl   ro   rb   httpr   ior   r	   rj   r   r   rC   r^   ry   r   r   r   <module>r~      sq       
      0$ 	
A 
Ar   