U
    ?h!                     @   sf   d dl Zd dlZd dlmZmZ d dlZd dlZd dlZd dl	m
Z
 edZdd Ze
dd ZdS )	    N)URLError	HTTPError)contextmanagerz'http://|https://|ftp://|file://|file:\\c                 C   s   t | tot| dk	S )z-Return True if string is an http or ftp path.N)
isinstancestr	URL_REGEXmatch)filename r
   A/var/www/html/venv/lib/python3.8/site-packages/skimage/io/util.pyis_url   s    
r   c                 c   s   t | rtj| }tj|j\}}zLtjd|d,}tj	
| }||  W 5 Q R X W 5 Q R X |jV  W nB ttfk
r   t|j  Y q ttttfk
r    Y qX t|j n| V  dS )z>Yield name of file from the given resource (i.e. file or url).F)deletesuffixN)r   urllibparseurlparseospathsplitexttempfileNamedTemporaryFilerequesturlopenwritereadnamer   r   removeFileNotFoundErrorFileExistsErrorPermissionErrorBaseException)resource_nameZurl_components_extfur
   r
   r   file_or_url_context   s$    " r&   )urllib.parser   urllib.requesturllib.errorr   r   r   rer   
contextlibr   compiler   r   r&   r
   r
   r
   r   <module>   s   
