a
    ø£BeÙ  ã                	   @   sn   d Z ddlZddlZddlZddlZdd„ ZdddddddddœZd	d
„ Zddd„Zg d¢Z	e
dœdd„ZdS )zKA module with various utility methods for authorization in Jupyter Server.
é    Nc                   C   s   t jdtdd� dS )zDEPRECATED, does nothingzCjupyter_server.auth.utils.warn_disabled_authorization is deprecatedé   )Ú
stacklevelN)ÚwarningsÚwarnÚDeprecationWarning© r   r   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_server/auth/utils.pyÚwarn_disabled_authorization   s
    ýr	   ÚreadÚwriteÚexecute)ÚGETÚHEADÚOPTIONSÚPOSTÚPUTÚPATCHÚDELETEZ	WEBSOCKETc            	      C   s|   ddl m}  g }|  ¡ D ]}|r| |¡ qi }|D ]0}t |¡}|j}|jD ]}|d }|||< qNq4dD ]}d||< qj|S )zÂReturns a dictionary with all of Jupyter Server's
    request handler URL regex patterns mapped to
    their resource name.

    e.g.
    { "/api/contents/<regex_pattern>": "contents", ...}
    r   )ÚJUPYTER_SERVICE_HANDLERS)z/terminals/websocket/(\w+)z/api/terminalsz/api/terminals/(\w+)Z	terminals)Zjupyter_server.serverappr   ÚvaluesÚextendÚ	importlibÚimport_moduleZAUTH_RESOURCEZdefault_handlers)	r   ÚmodulesÚmod_nameZresource_mapZhandler_moduleÚmodÚnameÚhandlerZ	url_regexr   r   r   Úget_regex_to_resource_map    s    


r   c                 C   s<   |s
t ƒ }| ¡ D ]$\}}t |¡}| | ¡r|  S qdS )zºFinds the JupyterHandler regex pattern that would
    match the given URL and returns the resource name (str)
    of that handler.

    e.g.
    /api/contents/... returns "contents"
    N)r   ÚitemsÚreÚcompileÚ	fullmatch)ÚurlZregex_mappingÚregexZauth_resourceÚpatternr   r   r   Úmatch_url_to_resource@   s    

r&   )9ZMetisZAdrasteaZAmaltheaZThebeÚIoZEuropaZGanymedeZCallistoZThemistoZLedaZErsaZPandiaZHimaliaZLysitheaZElaraZDiaZCarpoZValetudoZEuporieZEuphemeZHelikeZEuantheZHermippeZ	PraxidikeZThyoneZ	ThelxinoeZAnankeZMnemeZOrthosieZ	HarpalykeZIocasteZErinomeZAitneZHerseZTaygeteZEukeladeZCarmeZIsonoeZAutonoeZPhilophrosyneZCylleneZPasitheeZPasiphaeZSpondeZEurydomeZKalykeZHegemoneZKaleZ
KallichoreZChaldeneZArcheZEireneZKoreZ	MegacliteZAoedeZ
CallirrhoeZSinope)Úreturnc                   C   s   t t dtt ƒd ¡ S )z‰
    Get a random user-name based on the moons of Jupyter.
    This function returns names like "Anonymous Io" or "Anonymous Metis".
    r   é   )Úmoons_of_jupyterÚrandomÚrandintÚlenr   r   r   r   Úget_anonymous_username¤   s    r.   )N)Ú__doc__r   r+   r    r   r	   ZHTTP_METHOD_TO_AUTH_ACTIONr   r&   r*   Ústrr.   r   r   r   r   Ú<module>   s$   
ø 
S