§
    2?Äj¼#  ã                   ó¾   — d Z ddlmZ ddlZddlmZ ddlZddlZddlZddl	m
Z
mZ ddl	mZmZ  G d„ d	e¦  «        Z G d
„ de¦  «        Zdd„Zdd„Zdd„Zd„ Zd„ ZdS )z&Data downloading and reading functionsé    )ÚlogN)Úpathé   )Úappdata_dirÚresource_dirs)ÚStdoutProgressIndicatorÚurlopenc                   ó   — e Zd ZdZdS )ÚInternetNotAllowedErrorzxPlugins that need resources can just use get_remote_file(), but
    should catch this error and silently ignore it.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úFC:\Projects\Historical\venv\Lib\site-packages\imageio/core/fetching.pyr   r      s   € € € € € ðð ð 	€Dr   r   c                   ó   — e Zd ZdZdS )ÚNeedDownloadErrorzŠIs raised when a remote file is requested that is not locally
    available, but which needs to be explicitly downloaded by the user.
    Nr   r   r   r   r   r      s   € € € € € ðð ð ð r   r   FTc                 óæ  — d}|| z   }t          j        | ¦  «        }|}|pt          d¦  «        }t          ¦   «         }|                     d|¦  «         |D �]ß}	t          j        |	|¦  «        }
t          j        |
¦  «        �r²|s£|r�||	k    r—t          j                             ||¦  «        }t          j	        t          j
        |¦  «        ¦  «        s8t          j        t          j        t          j
        |¦  «        ¦  «        ¦  «         t          j        |
|¦  «         |c S |
c S t          |t           ¦  «        røt#          j        |d¦  «        }t#          j        t          j        |
¦  «        ¦  «        }||k    r£|r�||	k    r—t          j                             ||¦  «        }t          j	        t          j
        |¦  «        ¦  «        s8t          j        t          j        t          j
        |¦  «        ¦  «        ¦  «         t          j        |
|¦  «         |c S |
c S t+          d|z  ¦  «          n�Œát          j        dd¦  «                             ¦   «         dv rt1          d	¦  «        ‚|st3          ¦   «         ‚t          j        ||¦  «        }
t          j	        t          j
        |
¦  «        ¦  «        s8t          j        t          j        t          j
        |
¦  «        ¦  «        ¦  «         t          j        d
¦  «        r\t5          d¦  «        D ]:}	 t7          ||
¦  «         |
c S # t8          $ r t#          j        d¦  «         Y Œ7w xY wt7          ||
¦  «         |
S t7          ||
¦  «         |
S )a�  Get a the filename for the local version of a file from the web

    Parameters
    ----------
    fname : str
        The relative filename on the remote data repository to download.
        These correspond to paths on
        ``https://github.com/imageio/imageio-binaries/``.
    directory : str | None
        The directory where the file will be cached if a download was
        required to obtain the file. By default, the appdata directory
        is used. This is also the first directory that is checked for
        a local version of the file. If the directory does not exist,
        it will be created.
    force_download : bool | str
        If True, the file will be downloaded even if a local copy exists
        (and this copy will be overwritten). Can also be a YYYY-MM-DD date
        to ensure a file is up-to-date (modified date of a file on disk,
        if present, is checked).
    auto : bool
        Whether to auto-download the file if its not present locally. Default
        True. If False and a download is needed, raises NeedDownloadError.

    Returns
    -------
    fname : str
        The path to the file on the local system.
    z7https://github.com/imageio/imageio-binaries/raw/master/Úimageior   z%Y-%m-%dzFile older than %s, updating...ÚIMAGEIO_NO_INTERNETÚ )Ú1ÚtrueÚyeszeWill not download resource from the internet because environment variable IMAGEIO_NO_INTERNET is set.ÚCIé   g      à?)ÚopÚnormcaser   r   ÚinsertÚjoinÚisfileÚosr   ÚisdirÚdirnameÚmakedirsÚabspathÚshutilÚcopyÚ
isinstanceÚstrÚtimeÚstrptimeÚgmtimeÚgetctimeÚprintÚgetenvÚlowerr   r   ÚrangeÚ_fetch_fileÚIOErrorÚsleep)ÚfnameÚ	directoryÚforce_downloadÚautoÚ	_url_rootÚurlÚnfnameÚgiven_directoryÚdirsÚdirÚfilenameÚ	filename2ÚntimeÚftimeÚis                  r   Úget_remote_filerG       sP  € ð: J€IØ
�eÑ
€CÝŒ[˜ÑÔ€Fà€OØÐ9¥;¨yÑ#9Ô#9€IÝ‰?Œ?€DØ‡K‚K��9ÑÔÐàð ñ ˆÝ”7˜3 Ñ'Ô'ˆÝŒ9�XÑÔñ 	Ø!ð  Ø"ð % ¸#Ò'=Ð'=Ý "¤§¢¨_¸fÑ EÔ E�Iåœ8¥B¤J¨yÑ$9Ô$9Ñ:Ô:ð GÝœ¥B¤J­r¬z¸)Ñ/DÔ/DÑ$EÔ$EÑFÔFÐFÝ”K ¨)Ñ4Ô4Ð4Ø$Ð$Ð$Ð$Ø���Ý˜.­#Ñ.Ô.ð Ýœ n°jÑAÔA�Ýœ¥B¤K°Ñ$9Ô$9Ñ:Ô:�Ø˜E’>�>Ø&ð )¨?¸cÒ+AÐ+AÝ$&¤G§L¢L°À&Ñ$IÔ$I˜	å!œx­¬
°9Ñ(=Ô(=Ñ>Ô>ð KÝœK­¬
µ2´:¸iÑ3HÔ3HÑ(IÔ(IÑJÔJÐJÝœ H¨iÑ8Ô8Ð8Ø(Ð(Ð(Ð(Ø#�O�O�OåÐ;¸nÑLÑMÔMÐMØ�Eùõ 
„yÐ&¨Ñ+Ô+×1Ò1Ñ3Ô3Ð7KÐKÐKÝ%ð*ñ
ô 
ð 	
ð ð "ÝÑ!Ô!Ð!õ Œw�y &Ñ)Ô)€HÝŒ8•B”J˜xÑ(Ô(Ñ)Ô)ð 6Ý
Œ•B”J�rœz¨(Ñ3Ô3Ñ4Ô4Ñ5Ô5Ð5å	„y��„ð å�q‘”ð 	ð 	ˆAð Ý˜C Ñ*Ô*Ð*Ø���øÝð  ð  ð  Ý”
˜3‘”���ð øøøõ ˜˜XÑ&Ô&Ð&ØˆOå�C˜Ñ"Ô"Ð"Øˆs   ÌL+Ì+MÍMc                 ó  — t          dt          j                             |¦  «        z  ¦  «         |dz   }d}d}g }t	          d¦  «        D �]”}	 t          | d¬¦  «        }t          |j        d                              ¦   «         ¦  «        }	t          |	¦  «        }
t          d	|d
z   | |
fz  ¦  «         t          |d¦  «        }t          |||¬¦  «         |j        s|                     ¦   «          t          j        ||¦  «         |du r"t           j                             d|z  ¦  «         	 |�|j        s|                     ¦   «           dS  dS  dS # t&          $ r>}|                     |¦  «         t          dt+          |¦  «        z  ¦  «         Y d}~nd}~ww xY w	 |�|j        s|                     ¦   «          �Œr# |�|j        s|                     ¦   «          w w w xY wt-          dt          j                             |¦  «        z  ¦  «        ‚)aÛ  Load requested file, downloading it if needed or requested

    Parameters
    ----------
    url: string
        The url of file to be downloaded.
    file_name: string
        Name, along with the path, of where downloaded file will be saved.
    print_destination: bool, optional
        If true, destination of where file was saved will be printed after
        download finishes.
    resume: bool, optional
        If true, try to resume partially downloaded files.
    z?Imageio: %r was not found on your computer; downloading it now.z.partNr   é   g      @)ÚtimeoutúContent-LengthzTry %i. Download from %s (%s)r   Úwb)Úinitial_sizeTzFile saved as %s.
zError while fetching file: %s.zhUnable to download %r. Perhaps there is no internet connection? If there is, please report this problem.)r1   r$   r   Úbasenamer4   r	   ÚintÚheadersÚstripÚ_sizeof_fmtÚopenÚ_chunk_readÚclosedÚcloser)   ÚmoveÚsysÚstdoutÚwriteÚ	ExceptionÚappendr,   r6   )r=   Ú	file_nameÚprint_destinationÚtemp_file_nameÚ
local_filerM   ÚerrorsÚtriesÚremote_fileÚ	file_sizeÚsize_strÚes               r   r5   r5   ƒ   sx  € õ$ 
ð	Ý "¤× 0Ò 0°Ñ ;Ô ;ñ	<ñô ð ð
  Ñ(€NØ€JØ€LØ€FÝ�q‘”ð 
ñ 
ˆð	'å! #¨sÐ3Ñ3Ô3ˆKÝ˜KÔ/Ð0@ÔA×GÒGÑIÔIÑJÔJˆIÝ" 9Ñ-Ô-ˆHÝÐ1°U¸Q±YÀÀXÐ4NÑNÑOÔOÐOå˜n¨dÑ3Ô3ˆJÝ˜ Z¸lÐKÑKÔKÐKàÔ$ð #Ø× Ò Ñ"Ô"Ð"ÝŒK˜¨	Ñ2Ô2Ð2Ø  DÐ(Ð(Ý”
× Ò Ð!6¸Ñ!BÑCÔCÐCØð
 Ð%Ø!Ô(ð 'Ø×$Ò$Ñ&Ô&Ð&Ð&Ð&Ð&ð &Ð%Ð%ð'ð 'ð 'øõ ð 	=ð 	=ð 	=Ø�MŠM˜!ÑÔÐÝÐ2µS¸±V´VÑ;Ñ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<øøøøð	=øøøà<àÐ%Ø!Ô(ð 'Ø×$Ò$Ñ&Ô&Ð&ùøð Ð%Ø!Ô(ð 'Ø×$Ò$Ñ&Ô&Ð&Ð&ð &ð'øøøõ ðCåŒg×Ò˜yÑ)Ô)ñ*ñ
ô 
ð 	
s+   ÁCEÅ
FÅ4FÆF<ÆFÆF<Æ<!Gé    c                 ó\  — |}t          | j        d                              ¦   «         ¦  «        }||z  }t          d¦  «        }|                     dd|¦  «         	 |                      |¦  «        }|t          |¦  «        z  }|snt          |||¦  «         Œ<|                     d¦  «         dS )aö  Download a file chunk by chunk and show advancement

    Can also be used when resuming downloads over http.

    Parameters
    ----------
    response: urllib.response.addinfourl
        Response to the download request in order to get file size.
    local_file: file
        Hard disk file where data should be written.
    chunk_size: integer, optional
        Size of downloaded chunks. Default: 8192
    initial_size: int, optional
        If resuming, indicate the initial size of the file.
    rK   ÚDownloadingr   ÚbytesTÚDoneN)	rO   rP   rQ   r   ÚstartÚreadÚlenÚ_chunk_writeÚfinish)Úresponser`   Ú
chunk_sizerM   Úbytes_so_farÚ
total_sizeÚprogressÚchunks           r   rT   rT   ¾   s¼   € ð&  €Lõ �XÔ%Ð&6Ô7×=Ò=Ñ?Ô?Ñ@Ô@€JØ�,Ñ€Jå& }Ñ5Ô5€HØ‡N‚N�2�w 
Ñ+Ô+Ð+ð2Ø—’˜jÑ)Ô)ˆØ�˜E™
œ
Ñ"ˆØð 	ØÝ�U˜J¨Ñ1Ô1Ð1ð2ð ‡O‚O�FÑÔÐÐÐr   c                 óœ   — |                      | ¦  «         |                     t          | ¦  «        ¦  «         t          j        d¦  «         dS )z1Write a chunk to file and update the progress barr   N)rZ   Úincrease_progressrn   r-   r7   )rv   r`   ru   s      r   ro   ro   ã   sA   € à×Ò�UÑÔÐØ×Ò�s 5™zœzÑ*Ô*Ð*Ý„Jˆq�M„M€M€M€Mr   c                 ó*  — g d¢}g d¢}	 | dk    r{t          t          t          | d¦  «        ¦  «        t          |¦  «        dz
  ¦  «        }t	          | ¦  «        d|z  z  }||         }||         }d|z  }|                     ||¦  «        S | dk    rdndS )	z,Turn number of bytes into human-readable str)rj   ÚkBÚMBÚGBÚTBÚPB)r   r   r   r   r   r   r   i   z{0:.%sf} {1}r   z0 bytesz1 byte)ÚminrO   r   rn   ÚfloatÚformat)ÚnumÚunitsÚdecimalsÚexponentÚquotientÚunitÚnum_decimalsÚformat_strings           r   rR   rR   ê   s¦   € à3Ð3Ð3€EØ!Ð!Ð!€HØ"Ø
ˆQ‚w€wÝ•s�3˜s D™>œ>Ñ*Ô*­C°©J¬J¸©NÑ;Ô;ˆÝ˜‘:”:  h¡Ñ.ˆØ�XŒˆØ Ô)ˆØ&¨Ñ5ˆØ×#Ò# H¨dÑ3Ô3Ð3Ø˜qš˜ˆ9ˆ9 hÐ.r   )NFT)T)rg   r   )r   Úmathr   r$   r   r   rX   r)   r-   r   r   r   r   r	   r6   r   r   rG   r5   rT   ro   rR   r   r   r   ú<module>r‹      sD  ðð
 -Ð ,à Ð Ð Ð Ð Ð Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø 
€
€
€
Ø €€€Ø €€€à (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .ð	ð 	ð 	ð 	ð 	˜gñ 	ô 	ð 	ðð ð ð ð ˜ñ ô ð ð`ð `ð `ð `ðF8
ð 8
ð 8
ð 8
ðv"ð "ð "ð "ðJð ð ð/ð /ð /ð /ð /r   