
    #Yh                         d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z dZ G d d          Z G d d	          Zdd
ZddZ	 	 	 	 	 	 	 d	 ddZdS )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                       e Zd Zd Zd ZdS )MockRequestc                      t          d          S )Ns   GET /)IO)selfargskwargss      [D:\DownLoads\facial_attendance_system-main\venv311\Lib\site-packages\altair/utils/server.pymakefilezMockRequest.makefile   s    (||    c                     d S N )r	   responses     r   sendallzMockRequest.sendall       r   N)__name__
__module____qualname__r   r   r   r   r   r   r      s2              r   r   c                        e Zd Zd Zd Zd ZdS )
MockServerc                 D     |t                      |d         |            d S )Nr   )r   )r	   ip_portHandlers      r   __init__zMockServer.__init__$   s$    wqz400000r   c                     d S r   r   r	   s    r   serve_foreverzMockServer.serve_forever'   r   r   c                     d S r   r   r   s    r   server_closezMockServer.server_close*   r   r   N)r   r   r   r   r    r"   r   r   r   r   r   #   sA        1 1 1      r   r   c                 H     i  G  fddt           j                  }|S )Nc                       e Zd Z fdZdS )#generate_handler.<locals>.MyHandlerc                 .   | j         dk    rm|                     d           |                     dd           |                                  | j                                                                       dS | j         v r}| j                  \  }}|                     d           |                     d|           |                                  | j                            |                                           dS |                     d           dS )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_GETz*generate_handler.<locals>.MyHandler.do_GET3   s   yC""3'''  ===  """
  /////e##(-di(8%g""3'''  >>>  """
  !1!122222$$$$$r   N)r   r   r   r5   )r3   r4   s   r   	MyHandlerr%   2   s3        	% 	% 	% 	% 	% 	% 	% 	%r   r6   )r   BaseHTTPRequestHandler)r4   r3   r6   s   `` r   generate_handlerr8   .   sR    }% % % % % % % %F1 % % %" r   2   c           	         t          j        fdt          |          D             t          j        d|z  d|z            z             }|D ]`t          j        t
          j        t
          j                  }|                    | f          }|	                                 |dk    rc S ad}t          |          )z*Find an open port near the specified port.c              3   "   K   | ]	}|z   V  
d S r   r   ).0iports     r   	<genexpr>z!find_open_port.<locals>.<genexpr>I   s'      $$a$$$$$$r      r   zno open ports found)	itertoolschainrangerandomrandintsocketAF_INETSOCK_STREAM
connect_exclose
ValueError)ipr>   nportssresultmsgs    `     r   find_open_portrS   F   s    O$$$$588$$$tfnR!VQU.K.K'K E   M&.&*<==r4j))				Q;;KKK 
C
S//r   	127.0.0.1"  Treturnc                 `   t          |          t          | |          }|t          j        f|          }	n |f|          }	|r-	 t           t          t                     n# t          $ r Y nw xY wt          d d d           t          j	        
                                 |r-fd}
t          j        |
                                           	 |	                                 n&# t          t           f$ r t          d           Y nw xY w|	                                 dS )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                  8    t          j        d  d           S )Nzhttp://rX   )
webbrowseropen)rM   r>   s   r   bzserve.<locals>.b   s$    ?#8R#8#8$#8#8999r   )targetz
stopping Server...)rS   r8   r   
HTTPServer__IPYTHON__printJUPYTER_WARNING	NameErrorsysstdoutflush	threadingThreadstartr    KeyboardInterrupt
SystemExitr"   )r4   rM   r>   	n_retriesr3   jupyter_warningopen_browserhttp_serverr   srvrr\   s    ``        r   serverp   V   s   B "dI..DtU++G "dW55{B:w// #	#K /""""  	 	 	D	 

?r
?
?D
?
?
?@@@J +	: 	: 	: 	: 	: 	: 	"""((***&z* & & &$%%%%%& 	s$   A+ +
A87A8C4 4 DDr   )r9   )rT   rU   r9   NTTN)rV   N)__doc__rB   rE   rG   rc   rf   rZ   httpr   ior   r   ra   r   r   r8   rS   rp   r   r   r   <module>rt      s9          



                                     0   $ 	
A 
A A A A A Ar   