+
     Gi|  c                   st    ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	R]P                  R3R ltRR ltR# )    NTFc           
     sL  aaa RR loRR loRoVVV3R lp\         P                  P                  V P                  R,           4      '       g?   \        P
                  P                  P                  V RRV P                  R,           .4       VP                  RR	4      pV P                  R
,           V,           R	,           \        P                  ! VP                  R4      4      P                  4       ,           p\         P                  P                  V4      '       d7   V'       d   V# \        P
                  P                  P                  V RV.4       \        P                  ! VRV,           4        \        P                   P#                  V4      ;_uu_ 4       p\%        VR4      ;_uu_ 4       p	\&        P(                  ! WhP*                  P-                  R4      V3RR7      P/                  4        \0        P2                  ! W4       RRR4       RRR4       RoV#   + '       g   i     L; i  + '       g   i     RoT# ; i  \        P4                  P6                   dC   p
T
P8                  R8X  d,   T'       d$   \        P:                  ! RT,           4        Rp
?
R# h Rp
?
ii ; i)a#  Download a file to disk.

:param url: the http(s) address of to the file to download
:param prefix: for the cache, to make it easier to find (cache files
               get a hash of the URL after the prefix)
:param cache: if True, and url is cached, do not download it again
:param loglevel: change to logging.DEBUG to only display the download
                 message in 'waydroid log', not in stdout. We use
                 this when downloading many APKINDEX files at once, no
                 point in showing a dozen messages.
:param allow_404: do not raise an exception when the server responds
                  with a 404 Not Found error. Only display a warning on
                  stdout (no matter if loglevel is changed).
:returns: path to the downloaded file in the cache or None on 404 c                 s:    \        \        V 4      R ,          V4      # )i@B )roundZint)ZnumBytesdecimalPlacess   &&'/usr/lib/waydroid/tools/helpers/http.pyfromBytesToMBZdownload.<locals>.fromBytesToMB    s    S]7*M::    c                 sb    R pW,
          pV^8  d   VR,          pRp\        WR,          V4      V3# )MB/si  zkB/s)r   )lastSizecurrentSize	timeTakenr   Z	speedUnitZsizeDifferences   &&&&  r   getDownloadSpeedZ"download.<locals>.getDownloadSpeed#   s?    	$-A D NI n.>	JJr   Fc           	      s
  < S	! V 4      p \        \        V 4      4      p^ p\        P                  ! 4       pR	pS'       g   S	! \        P                  P                  V4      4      p\        P                  ! 4       pS
! W6Wt,
          R7      pTpTp\        V4      P                  V4      p\        V^ ,          4      P                  ^4       RV^,           2p\        RV RV  RV R2RR7       \        P                  ! ^4       K  R# )
r    )r	   Z z[Downloading] z MB/z MB    z	(approx.))ZendN)r    r   )	ZlenZstrtimeospathZgetsizeZrjustZprintZsleep)Z	totalSizeZdestinationPathZtotalSizeStrLenr   ZlastSizeChangeAtZdownloadSpeedr   ZsizeChangeAtdownloadEndedr   r
   s   &&      r   progressZdownload.<locals>.progress5   s     "),	 c)n- 99;!'(HIK99;L,&7M
 #H+ k*00AK"=#34::1=>aa@P?QRM $[Mi[V_`fijJJqM-  r   z/cache_httpZmkdirz-pZ/Z_z/cache_http/zutf-8ZrmzDownloading Zwbzcontent-lengthT)ZtargetargsZdaemonNi  zWARNING: file not found: )i   )r   r   ZexistsZworktoolsZhelpersZrunZuserZreplacehashlibZsha256ZencodeZ	hexdigestloggingZlogurllibrequesturlopenZopen	threadingZThreadheadersZgetZstartshutilZcopyfileobjerror	HTTPErrorcodeZwarning)r   urlZprefixZcacheZloglevelZ	allow_404r   r   responseZhandleer   r   r
   s   &&&&&&     @@@r   downloadr       s   $;K" M&R 77>>$))m344tgtTYY5N%OP ^^C%FII&/#5NN3::g./99;<D	ww~~dKtdD\2 KK.3./^^##C((HdD!!V   8H8H8L8LM]8^`d7enrsyy{""84	 " ) M K "! )( M K <<!! 66S=YOO7#=>	s[   1'I H,-AH	H,I H)$H,,H?	7I ?I J#!J:JJJ#c                s*   \         P                  ! RV ,           4       Vf   / p \        P                  P	                  WR7      p\        P                  P                  V4      ;_uu_ 4       p^VP                  4       3uuRRR4       #   + '       g   i     R# ; i  \         d   pRu Rp?# Rp?i\        P                  P                   d   pTP                  R3u Rp?# Rp?i\        P                  P                   d   pRu Rp?# Rp?ii ; i)zFetch the content of a URL and returns it as string.

:param url: the http(s) address of to the resource to fetch
:param headers: dict of HTTP headers to use
:returns: status and str with the content of the response
zRetrieving N)r    )ir!   )ir!   )r   Zverboser   r   ZRequestr   ZreadZ
ValueErrorr   r   r   ZURLError)r   r   Zreqr   r   s   &&   r   retriever"      s     OOMC'(nn$$S$:^^##C((H' )(((  <<!! vvrz<<   sl   AB ,B	>
B 	B	B B D(B/)D/ DDC$D$ DDDDD)N)r   r   r   r   r   Zurllib.requestr   Ztools.helpers.runr   r   ZINFOr    r"   ) r   r   <module>r#      s9      	      '+W\\nbr   