Ë
    ìì�i×#  ã                   ó°   — 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y)z&Data downloading and reading functionsé    )ÚlogN)Úpathé   )Úappdata_dirÚresource_dirs)ÚStdoutProgressIndicatorÚurlopenc                   ó   — e Zd ZdZy)ÚInternetNotAllowedErrorzxPlugins that need resources can just use get_remote_file(), but
    should catch this error and silently ignore it.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úz/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/imageio/core/fetching.pyr   r      s   „ ñð 	r   r   c                   ó   — e Zd ZdZy)Ú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   c                 ó¾  — d}|| z   }t        j                  | «      }|}|xs t        d«      }t        «       }|j	                  d|«       |D �]ã  }	t        j
                  |	|«      }
t        j                  |
«      sŒ0|s¨|r¢||	k7  r�t        j                  j                  ||«      }t        j                  t        j                  |«      «      s;t        j                  t        j                  t        j                  |«      «      «       t        j                  |
|«       |c S |
c S t        |t         «      sŒët#        j$                  |d«      }t#        j&                  t        j(                  |
«      «      }||k\  r¨|r¢||	k7  r�t        j                  j                  ||«      }t        j                  t        j                  |«      «      s;t        j                  t        j                  t        j                  |«      «      «       t        j                  |
|«       |c S |
c S t+        d|z  «        n t        j,                  dd«      j/                  «       dv rt1        d	«      ‚|s
t3        «       ‚t        j
                  ||«      }
t        j                  t        j                  |
«      «      s;t        j                  t        j                  t        j                  |
«      «      «       t        j,                  d
d«      r.t5        d«      D ]  }	 t7        ||
«       |
c S  t7        ||
«       |
S t7        ||
«       |
S # t8        $ r t#        j:                  d«       Y ŒQw xY w)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_filerG       s�  € ð: J€IØ
�eÑ
€CÜ�[‰[˜Ó€Fà€OØÒ9¤;¨yÓ#9€IÜ‹?€DØ‡K�K��9Ôàó ˆÜ—7‘7˜3 Ó'ˆÜ�9‰9�XÕÙ!Ù" ¸#Ò'=Ü "§¡§¡¨_¸fÓ E�IäŸ8™8¤B§J¡J¨yÓ$9Ô:ÜŸ™¤B§J¡J¬r¯z©z¸)Ó/DÓ$EÔFÜ—K‘K ¨)Ô4Ø$Ò$Ø’Ü˜.¬#Õ.ÜŸ™ n°jÓA�ÜŸ™¤B§K¡K°Ó$9Ó:�Ø˜E’>Ù&¨?¸cÒ+AÜ$&§G¡G§L¡L°À&Ó$I˜	ä!Ÿx™x¬¯
©
°9Ó(=Ô>ÜŸK™K¬¯
©
´2·:±:¸iÓ3HÓ(IÔJÜŸ™ H¨iÔ8Ø(Ò(Ø#’OäÐ;¸nÑLÔMÙð5ô: 
‡y�yÐ&¨Ó+×1Ñ1Ó3Ð7KÑKÜ%ð*ó
ð 	
ñ ÜÓ!Ð!ô �w‰w�y &Ó)€HÜ�8‰8”B—J‘J˜xÓ(Ô)Ü
�‰”B—J‘JœrŸz™z¨(Ó3Ó4Ô5ä	‡y�yÐ)¨5Ô1ä�q“ò 	ˆAð Ü˜C Ô*Ø’ð	ô ˜˜XÔ&ØˆOä�C˜Ô"Øˆøô ò  Ü—
‘
˜3–ð ús   ÌL;Ì;MÍMc                 óÆ  — t        dt        j                  j                  |«      z  «       |dz   }d}d}g }t	        d«      D ]ë  }	 t        | d¬«      }t        |j                  d   j                  «       «      }	t        |	«      }
t        d	|d
z   | |
fz  «       t        |d«      }t        |||¬«       |j                  s|j                  «        t        j                  ||«       |du r"t         j"                  j%                  d|z  «       	 |� |j                  s|j                  «         y y y t-        dt        j                  j                  |«      z  «      ‚# t&        $ r2}|j)                  |«       t        dt+        |«      z  «       Y d}~nd}~ww xY w	 |€�Œ\|j                  r�Œj|j                  «        �Œ|# |�|j                  s|j                  «        w w w xY w)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   ƒ   sÔ  € ô$ 
ð	Ü "§¡× 0Ñ 0°Ó ;ñ	<ôð
  Ñ(€NØ€JØ€LØ€FÜ�q“ò 
ˆð	'ä! #¨sÔ3ˆKÜ˜K×/Ñ/Ð0@ÑA×GÑGÓIÓJˆIÜ" 9Ó-ˆHÜÐ1°U¸Q±YÀÀXÐ4NÑNÔOä˜n¨dÓ3ˆJÜ˜ Z¸lÕKà×$Ò$Ø× Ñ Ô"Ü�K‰K˜¨	Ô2Ø  DÑ(Ü—
‘
× Ñ Ð!6¸Ñ!BÔCØð
 Ð%Ø!×(Ò(Ø×$Ñ$Ö&ñ )ñ &ð+
ô2 ðCä�g‰g×Ñ˜yÓ)ñ*ó
ð 	
øô ò 	=Ø�M‰M˜!ÔÜÐ2´S¸³VÑ;×<Ñ<ûð	=úà<àÒ%Ø!×(Ô(Ø×$Ñ$Ö&øð Ð%Ø!×(Ò(Ø×$Ñ$Õ&ð )ð &ús+   ÁCEÅ	FÅ$(FÆF>ÆFÆF>Æ>"G c                 ó  — |}t        | j                  d   j                  «       «      }||z  }t        d«      }|j	                  dd|«       	 | j                  |«      }|t        |«      z  }|snt        |||«       Œ0|j                  d«       y)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   ÚbytesÚ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€HØ‡N�N�2�w 
Ô+à
Ø—‘˜jÓ)ˆØœ˜E›
Ñ"ˆÙØÜ�U˜J¨Ô1ð ð ‡O�O�FÕr   c                 ó„   — |j                  | «       |j                  t        | «      «       t        j                  d«       y)z1Write a chunk to file and update the progress barr   N)rZ   Úincrease_progressrm   r-   r7   )ru   r`   rt   s      r   rn   rn   ã   s-   € à×Ñ�UÔØ×Ñœs 5›zÔ*Ü‡J�Jˆq…Mr   c                 óê   — g d¢}g d¢}	 | dkD  r]t        t        t        | d«      «      t        |«      dz
  «      }t	        | «      d|z  z  }||   }||   }d|z  }|j                  ||«      S | dk(  rdS dS )	z,Turn number of bytes into human-readable str)ri   Ú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   rm   ÚfloatÚformat)ÚnumÚunitsÚdecimalsÚexponentÚquotientÚunitÚnum_decimalsÚformat_strings           r   rR   rR   ê   sˆ   € â3€EÚ!€HØ"Ø
ˆQ‚wÜ”sœ3˜s D›>Ó*¬C°«J¸©NÓ;ˆÜ˜“:  h¡Ñ.ˆØ�X‰ˆØ Ñ)ˆØ&¨Ñ5ˆØ×#Ñ# H¨dÓ3Ð3Ø˜qšˆ9Ð. hÐ.r   )NFT)T)i    r   )r   Úmathr   r$   r   r   rX   r)   r-   r   r   r   r   r	   r6   r   r   rG   r5   rT   rn   rR   r   r   r   ú<module>rŠ      sW   ðñ
 -å Û 	Ý Û 
Û Û ç (ß .ô	˜gô 	ô˜ô ó`óF8
óv"òJó/r   