o
     Loj                     @  sV   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 ddd	Z
ddddZdS )    )annotationsN)partial)SimpleHTTPRequestHandlerThreadingHTTPServer)Pathreturn
str | Nonec               	   C  sn   t  t jt j%} z| d |  d W W  d   S  ty,   Y W d   dS w 1 s0w   Y  dS )zEBest-effort local address, so a phone on the same Wi-Fi can reach it.)z	192.0.2.15   r   N)socketAF_INET
SOCK_DGRAMconnectgetsocknameOSError)probe r   ./root/openrights-assistant/openrights/serve.pylan_address	   s   
r   @  rootr   portintNonec              	   C  s   | d   s
tdttt| d}td|f|J}t }td| d |r3td| d| d	 ntd
 td td z|  W n t	yR   td Y n	w W d    d S W d    d S 1 sfw   Y  d S )Nzapp/data/index.jszYArchive not exported. Run: python -m openrights ingest && python -m openrights export-web)	directoryz0.0.0.0z)Open on this computer:  http://localhost:z/app/zOpen on your phone:     http://:z/app/   (same Wi-Fi)z/Open on your phone:     no LAN address detectedz`Install it from the browser menu, then switch the phone to airplane mode to prove it is offline.zStop with Ctrl+C.z	
Stopped.)
exists
SystemExitr   r   strr   r   printserve_foreverKeyboardInterrupt)r   r   handlerserveraddressr   r   r   serve   s(   "r$   )r   r   )r   )r   r   r   r   r   r   )
__future__r   r
   	functoolsr   http.serverr   r   pathlibr   r   r$   r   r   r   r   <module>   s    

