U
    ARd                     @   sV   d dl Z d dlZd dlmZ e dZeedddZeee dddZd	d
 Z	dS )    N)Optionalzt(?P<base>https:\/\/?(gist\.)?github.com\/)(?P<account>([\w\.]+\/){1,2})(?P<blob_or_raw>(blob|raw))?(?P<suffix>(.+)?))urlreturnc                 C   sJ   t | }|rF| }|d dkr.djf |S |d dkr>| S | d S | S )zCheck url to see if it describes a GitHub Gist "blob" URL.

    If so, returns a new URL to get the "raw" script.
    If not, returns URL unchanged.
    Zblob_or_rawZblobz{base}{account}raw{suffix}rawz/raw)_GITBLOB_REmatch	groupdictformat)r   r   Zmdict r
   6/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/url_util.pyprocess_gitblob_url   s    
r   c                 C   s"   d| krd|  } t j| }|jS )z8Return the hostname of a URL (with or without protocol).z://z	http://%s)urllibparseurlparsehostname)r   parsedr
   r
   r   get_hostname5   s    r   c                 C   s.   ddl }|jd|  ddd |j|dd dS )	z#Pretty-print a URL on the terminal.r   Nz  %s: FZblue)nlZfgT)Zbold)clickZsecho)titler   r   r
   r
   r   	print_url@   s    r   )
rer   typingr   compiler   strr   r   r   r
   r
   r
   r   <module>   s   