
    9i#                         S r SSKJr  SSKrSSKJr  SSKrSSKrSSKrSSK	J
r
Jr  SSK	JrJr   " S S	\5      r " S
 S\5      rSS jrSS jrSS jrS rS rg)z&Data downloading and reading functions    )logN)path   )appdata_dirresource_dirs)StdoutProgressIndicatorurlopenc                       \ rS rSrSrSrg)InternetNotAllowedError   zpPlugins that need resources can just use get_remote_file(), but
should catch this error and silently ignore it.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       U/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/imageio/core/fetching.pyr   r      s     	r   r   c                       \ rS rSrSrSrg)NeedDownloadError   zIs raised when a remote file is requested that is not locally
available, but which needs to be explicitly downloaded by the user.
r   Nr   r   r   r   r   r      s    r   r   c                 `   SnX@-   n[         R                  " U 5      nUnU=(       d    [        S5      n[        5       nUR	                  SU5        U GH  n	[         R
                  " X5      n
[         R                  " U
5      (       d  M7  U(       d  U(       a  Xy:w  a  [        R                  R                  Xv5      n[         R                  " [         R                  " U5      5      (       d>  [        R                  " [         R                  " [         R                  " U5      5      5        [        R                  " X5        Us  $ U
s  $ [        U[         5      (       d  GM  ["        R$                  " US5      n["        R&                  " [         R(                  " U
5      5      nX:  a  U(       a  Xy:w  a  [        R                  R                  Xv5      n[         R                  " [         R                  " U5      5      (       d>  [        R                  " [         R                  " [         R                  " U5      5      5        [        R                  " X5        Us  $ U
s  $ [+        SU-  5          O   [        R,                  " SS5      R/                  5       S;   a  [1        S	5      eU(       d
  [3        5       e[         R
                  " X5      n
[         R                  " [         R                  " U
5      5      (       d>  [        R                  " [         R                  " [         R                  " U
5      5      5        [        R,                  " S
S5      (       a-  [5        S5       H  n [7        XZ5        U
s  $    [7        XZ5        U
$ [7        XZ5        U
$ ! [8         a    ["        R:                  " S5         MR  f = f)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.CONTINUOUS_INTEGRATIONF   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_filerK       s{   : JI

C[[FO9;y#9I?DKK9773'99X!"'= "_ EI88BJJy$9::BJJrzz)/D$EFKK4$$.#..njABKK$9:>&?+A$&GGLL$I	!xx

9(=>>KK

2::i3H(IJH8((#O;nLM5 : 
yy&+1137KK%*
 	
 !! wwy)H88BJJx())
BJJrzz(345	yy)511qA C*  &OC"   

3 s   N		 N-,N-c                    [        S[        R                  R                  U5      -  5        US-   nSnSn/ n[	        S5       H  n [        U SS9n[        UR                  S   R                  5       5      n	[        U	5      n
[        S	US
-   X
4-  5        [        US5      n[        XUS9  UR                  (       d  UR                  5         [        R                  " X15        USL a"  [         R"                  R%                  SU-  5         Ub%  UR                  (       d  UR                  5           g  g  g   [-        S[        R                  R                  U5      -  5      e! [&         a2  nUR)                  U5        [        S[+        U5      -  5         SnAOSnAff = f Ub'  UR                  (       d  UR                  5         GM  GM  GM  ! Ub#  UR                  (       d  UR                  5         f f f = f)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.)r5   r(   r   basenamer8   r	   intheadersstrip_sizeof_fmtopen_chunk_readclosedcloser-   movesysstdoutwrite	Exceptionappendr0   r:   )rA   	file_nameprint_destinationtemp_file_name
local_filerQ   errorstriesremote_file	file_sizesize_stres               r   r9   r9      s   $ 
	 " 0 0 ;	<
 (NJLFq	'!#s3KK//0@AGGIJI"9-H1UQY4NNOnd3JlK$$  "KK2 D(

  !6!BC
 %!(($$& ) &+ 2 Cggy)*
 	
  	=MM!2SV;<<	=<%!(($$& ) &z%!(($$& ) &s+   CE  
F*(FGFG(G5c                 &   Un[        U R                  S   R                  5       5      nXS-  n[        S5      nUR	                  SSU5         U R                  U5      nU[        U5      -  nU(       d  O[        XqU5        M5  UR                  S5        g)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.
rO   Downloadingr   bytesDoneN)	rS   rT   rU   r   startreadlen_chunk_writefinish)responserd   
chunk_sizerQ   bytes_so_far
total_sizeprogresschunks           r   rX   rX      s    &  L X%%&67==?@JJ&}5HNN2w
+
j)E
"U1  OOFr   c                     UR                  U 5        UR                  [        U 5      5        [        R                  " S5        g)z1Write a chunk to file and update the progress barr   N)r^   increase_progressrq   r1   r;   )ry   rd   rx   s      r   rr   rr      s-    Us5z*JJqMr   c                     / SQn/ SQn U S:  aZ  [        [        [        U S5      5      [        U5      S-
  5      n[	        U 5      SU-  -  nX   nX#   nSU-  nUR                  XE5      $ U S:X  a  S$ S$ )	z,Turn number of bytes into human-readable str)rm   kBMBGBTBPB)r   r   r   r"   r"   r"   r   i   z{0:.%sf} {1}r   z0 bytesz1 byte)minrS   r   rq   floatformat)numunitsdecimalsexponentquotientunitnum_decimalsformat_strings           r   rV   rV      s    3E!H"
Qws3sD>*CJN;:h.)&5##H33q9.h.r   )NFT)T)i    r   )r   mathr   r(   r   r#   r\   r-   r1   r   r   r   r   r	   r:   r   r   rK   r9   rX   rr   rV   r   r   r   <module>r      sW   
 -  	  
   ( .	g 	 `F8
v"J/r   