
    7Thu                     b   S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  SSKJr   SSKrSSKJr  SSKJr  SS	KJrJr  SS
KJrJrJrJr  SSKJr  \R<                  " S5      r\R<                  " S5      r \RB                  " S5      r" " S S\RF                  RH                  5      r% " S S\RL                  5      r' " S S5      r( " S S5      r) " S S\5      r* " S S\5      r+\R<                  " S5      r,S r- " S S\5      r.S  r/S$S! jr0S" r1\1" 5         S# r2g! \\\4 a    Sr Nf = f)%z(This file is largely copied from http.py    N)copy)dumpsloads)urlparseF)_DEFAULT_CALLBACK)register_implementation)AbstractBufferedFileAbstractFileSystem)DEFAULT_BLOCK_SIZE
isfilelikenullcontexttokenize   )AllBytesz6<(a|A)\s+(?:[^>]*?\s+)?(href|HREF)=["'](?P<url>[^"']+)z-(?P<url>http[s]?://[-a-zA-Z0-9@:%_+.~#?&/=]+)zfsspec.httpc                       \ rS rSrSrg)JsHttpException    N__name__
__module____qualname____firstlineno____static_attributes__r       X/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/http_sync.pyr   r      s    sr   r   c                       \ rS rSrSrg)StreamIO!   r   Nr   r   r   r   r   r   !   s     r   r   c                       \ rS rSrSrSS jr\S 5       rS r\S 5       r	\S 5       r
S rS	 r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rSrg)ResponseProxy'   zLooks like a requests responsec                 8    Xl         X l        S U l        S U l        g N)requeststream_data_headers)selfreqr&   s      r   __init__ResponseProxy.__init__*   s    
r   c                     U R                   cW  U R                  R                  R                  5       nU R                  (       a  [        U5      U l         U R                   $ Xl         U R                   $ r$   )r'   r%   responseto_bytesr&   r   )r)   bs     r   rawResponseProxy.raw0   sS    ::%%..0A{{%a[
 zz 
zzr   c                 ,    [        U S5      (       a  U ?g g )Nr'   )hasattrr'   r)   s    r   closeResponseProxy.close:   s    4!!
 "r   c                    U R                   ce  [        U R                  R                  5       R	                  5       R                  S5       Vs/ s H  nUR                  S5      PM     sn5      U l         U R                   $ s  snf )Nz
: )r(   dictr%   getAllResponseHeadersstripsplit)r)   _s     r   headersResponseProxy.headers>   sp    ==   "\\??AGGIOOPVWW GGDMWDM }}s   A?c                 @    [        U R                  R                  5      $ r$   )intr%   statusr5   s    r   status_codeResponseProxy.status_codeI   s    4<<&&''r   c                     U R                   (       d7  [        U R                  U R                  U R                  U R
                  S 5      eg r$   )okr   urlrD   reasonr?   r5   s    r   raise_for_statusResponseProxy.raise_for_statusM   s8    ww!$**DKKt  r   c              /   `   #     U R                   R                  U5      nU(       a  Uv   Og M*  7fr$   )r1   read)r)   	chunksizer>   __outs        r   iter_contentResponseProxy.iter_contentS   s*     ((--	*C	 s   ,.c                 .    U R                   R                  $ r$   )r%   
statusTextr5   s    r   rI   ResponseProxy.reason[   s    ||&&&r   c                      U R                   S:  $ )N  )rD   r5   s    r   rG   ResponseProxy.ok_   s    #%%r   c                 B    U R                   R                  R                  $ r$   )r%   r.   responseURLr5   s    r   rH   ResponseProxy.urlc   s    ||$$000r   c                 6    U R                   R                  5       $ r$   )contentdecoder5   s    r   textResponseProxy.textg   s     ||""$$r   c                 (    SU l         U R                  $ NF)r&   r1   r5   s    r   r]   ResponseProxy.contentl   s    xxr   c                 ,    [        U R                  5      $ r$   )r   r_   r5   s    r   jsonResponseProxy.jsonq   s    TYYr   )r'   r(   r%   r&   N)F)r   r   r   r   __doc__r+   propertyr1   r6   r?   rD   rJ   rQ   rI   rG   rH   r_   r]   re   r   r   r   r   r!   r!   '   s    (     ( ( ' ' & & 1 1 % %   r   r!   c                   d    \ rS rSrS r              SS jrS rS rS rS r	S	 r
S
 rSrg)RequestsSessionShimu   c                     0 U l         g r$   r?   r5   s    r   r+   RequestsSessionShim.__init__v   s	    r   Nc                    SSK JnJn  [        R	                  SX5        U(       d#  U(       d  U(       d  U(       d  U(       d  U(       a  [
        eU(       a  U(       a  [        S5      eUR                  5       nU(       a  UOSnU(       a$  U S[        R                  R                  U5       3nUR                  " XS/UQ76   U	(       a  U	Ul        U(       a,  UR                  5        H  u  nnUR                  UU5        M     UR                  SS	5        S
Ul        U(       a4  UR                  [!        U5      /["        S05      nUR%                  U5        OrU(       aZ  ['        U[(        R*                  5      (       a  UR-                  5       nUR                  U/["        S	05      nUR%                  U5        OUR%                  S 5        [/        UUS9$ )Nr   )BlobXMLHttpRequestzJS request: %s %szUse json= or data=, not bothr   ?FAcceptzapplication/octet-streamarraybufferzapplication/json)r&   )jsrp   rq   loggerdebugNotImplementedError
ValueErrornewurllibparse	urlencodeopentimeoutitemssetRequestHeaderresponseTyper   typesend
isinstanceioIOBaserM   r!   )r)   methodrH   paramsdatar?   cookiesfilesauthr   allow_redirectsproxieshooksr&   verifycertre   rp   rq   r*   extrakvblobs                           r   r%   RequestsSessionShim.requesty   sW   & 	,(&66WE%%D;<<  ""E6<<11&9:;Ce,e,!CK1$$Q* ( 	X'AB(88U4[MD2D+EFDHHTN$		**yy{88TFT+E$FGDHHTNHHTNS00r   c                 *    U R                   " SU40 UD6$ )NGETr%   r)   rH   kwargss      r   getRequestsSessionShim.get       ||E31&11r   c                 *    U R                   " SU40 UD6$ )NHEADr   r   s      r   headRequestsSessionShim.head   s    ||FC2622r   c                 *    U R                   " SU40 UD6$ )NzPOST}r   r   s      r   postRequestsSessionShim.post       ||GS3F33r   c                 *    U R                   " SU40 UD6$ )NPUTr   r   s      r   putRequestsSessionShim.put   r   r   c                 *    U R                   " SU40 UD6$ )NPATCHr   r   s      r   patchRequestsSessionShim.patch   r   r   c                 *    U R                   " SU40 UD6$ )NDELETEr   r   s      r   deleteRequestsSessionShim.delete   s    ||Hc4V44r   rm   )NNNNNNNNNNNNNN)r   r   r   r   r+   r%   r   r   r   r   r   r   r   r   r   r   rj   rj   u   sW     #21h234245r   rj   c                     ^  \ rS rSrSrSrSr       SU 4S jjr\S 5       r	S r
\S\S	\4S
 j5       r\U 4S j5       rSS jrSS jrS rSS jrS\4S jrS\S4S jrS rS rS r      S S jrS rS rS!S jrS rSrU =r$ )"HTTPFileSystem   a$  
Simple File-System for fetching data via HTTP(S)

This is the BLOCKING version of the normal HTTPFileSystem. It uses
requests in normal python and the JS runtime in pyodide.

***This implementation is extremely experimental, do not use unless
you are testing pyodide/pyscript integration***
)httphttps	sync-http
sync-https/c                 |  > [         TU ]  " U 40 UD6  Ub  UO[        U l        Xl        X0l        X@l        XPl        U=(       d    0 U l        Xpl	        Xl
         SSKn	[        R                  S5        [        5       U l        SU l        ['        U5      nUR)                  SS5      U l        UR)                  SS5        UR)                  S	S5        UR)                  S
S5        Xl
        g! [          aK  n
SSKn[        R                  SU
5        UR$                  " S0 U=(       d    0 D6U l        SU l         Sn
A
NSn
A
ff = f)a  

Parameters
----------
block_size: int
    Blocks to read bytes; if 0, will default to raw requests file-like
    objects instead of HTTPFile instances
simple_links: bool
    If True, will consider both HTML <a> tags and anything that looks
    like a URL; if False, will consider only the former.
same_scheme: True
    When doing ls/glob, if this is True, only consider paths that have
    http/https matching the input URLs.
size_policy: this argument is deprecated
client_kwargs: dict
    Passed to aiohttp.ClientSession, see
    https://docs.aiohttp.org/en/stable/client_reference.html
    For example, ``{'auth': aiohttp.BasicAuth('user', 'pass')}``
storage_options: key-value
    Any other parameters passed on to requests
cache_type, cache_options: defaults used in open
Nr   zStarting JS sessionTz'Starting cpython session because of: %sFuse_listings_cachelistings_expiry_time	max_pathsskip_instance_cacher   )superr+   r   
block_sizesimple_linkssame_schema
cache_typecache_optionsclient_kwargsencodedr   ru   rv   rw   rj   session	ExceptionrequestsSessionr   popr   )r)   r   r   same_schemer   r   r   r   storage_optionsru   er   request_options	__class__s                r   r+   HTTPFileSystem.__init__   s   B 	11(2(>*DV(&$**0b%	LL./.0DLDG /"1"5"56JE"R2D9K.148%  	LLBAF#++D}/BDDLDGG	s   /C& &
D;0AD66D;c                     g)Nr   r   r5   s    r   fsidHTTPFileSystem.fsid  s    r   c                 X    [         (       a  [         R                  " XR                  S9$ U$ )N)r   )yarlURLr   r)   rH   s     r   
encode_urlHTTPFileSystem.encode_url  s    488C66
r   pathreturnc                 J    UR                  SS5      R                  SS5      nU$ )z-For HTTP, we always want to keep the full URLzsync-http://zhttp://zsync-https://zhttps://)replace)clsr   s     r   _strip_protocolHTTPFileSystem._strip_protocol  s+     ||NI6>>Z
 r   c                 F   > [         TU ]  U5      n[        U5      S:  a  U$ g)N    )r   _parentlen)r   r   parr   s      r   r   HTTPFileSystem._parent  s&     god#s8a<Jr   c           	      >   U R                   R                  5       nUR                  U5        [        R	                  U5        U R
                  R                  " U R                  U5      40 U R                   D6nU R                  XQ5        UR                  nU R                  (       a?  [        R                  U5      [        R                  U5       Vs/ s H  owS   PM	     sn-   nO'[        R                  U5       Vs/ s H  owS   PM	     nn[        5       n	[        U5      n
U GHl  n[!        U["        5      (       a  US   nUR%                  S5      (       a.  ['        U5      S:  a  U
R(                  S-   U
R*                  -   U-   nUR%                  S5      (       a  U R,                  (       a;  UR%                  UR/                  S5      S-   5      (       a  U	R1                  U5        M  UR3                  SS5      R%                  UR3                  SS5      R/                  S5      S-   5      (       a  U	R1                  U5        GM   GM#  US;  d  GM,  U	R1                  SR5                  UR/                  S5      UR7                  S5      /5      5        GMo     U	(       d5  UR9                  S5      (       a  U R;                  UR/                  S5      SS	9n	U(       a/  U	 Vs/ s H!  nUS UR9                  S5      (       a  S
OSS.PM#     sn$ [=        U	5      $ s  snf s  snf s  snf )Nr      r   z://r   r   )z..z../F)detail	directoryfilenamesizer   )r   r   updaterv   rw   r   r   r   _raise_not_found_for_statusr_   r   ex2findallexsetr   r   tuple
startswithr   schemenetlocr   rstripaddr   joinlstripendswith_ls_realsorted)r)   rH   r   r   kwrr_   ulinksrP   partsls               r   r  HTTPFileSystem._ls_real&  sq   [[
		&SLLT__S1AT[[A((0vvKK%rzz$7G(H7G!17G(HHE#%::d#34#3aqT#3E4eA!U##aD||C  SVaZLL5(5<<7!;||F####SZZ_s5J(K(KGGAJYYw/::KK077<sB  GGAJ	 M)GGCHHcjjoqxx}%EFG# $ s||C((--

3->C  A	  +,::c??K
   #;G )I40s   L;L(Lc                     U R                   (       a   XR                  ;   a  U R                  U   nU$ U R                  " U4SU0UD6nX@R                  U'   U$ )Nr   )r   dircacher  )r)   rH   r   r   rP   s        r   lsHTTPFileSystem.lsT  sT    ""smm';--$C 
 --=F=f=C!$MM#
r   c                 Z    UR                   S:X  a  [        U5      eUR                  5         g)zE
Raises FileNotFoundError for 404s, otherwise uses raise_for_status.
i  N)rD   FileNotFoundErrorrJ   )r)   r.   rH   s      r   r   *HTTPFileSystem._raise_not_found_for_status\  s)     3&#C((!!#r   c                    U R                   R                  5       nUR                  U5        [        R	                  U5        Uc  Ub?  X#:X  a  gUR                  S0 5      R                  5       nU R                  XU5      US'   XeS'   U R                  R                  " U R                  U5      40 UD6nU R                  Xq5        UR                  $ )Nr   r?   Range)r   r   r   rv   rw   r   _process_limitsr   r   r   r   r]   )r)   rH   startendr   r  r?   r  s           r   cat_fileHTTPFileSystem.cat_filed  s    [[
		&S|ffY+002G#33CDGG#yMLLT__S18R8((0yyr   i  P c                    U R                   R                  5       nUR                  U5        [        R	                  U5        U R
                  R                  " U R                  U5      40 UD6n [        UR                  R                  SS 5      =(       d    UR                  R                  SS 5      5      nUR                  U5        U R                  Xq5        [        U5      (       d  [!        US5      nUR#                  USS9 H.  n	UR%                  U	5        UR'                  [)        U	5      5        M0     g ! [        [        [        4 a    S n Nf = f)Ncontent-lengthContent-LengthwbF)decode_unicode)r   r   r   rv   rw   r   r   r   rB   r?   ry   KeyError	TypeErrorset_sizer   r   r~   rQ   writerelative_updater   )
r)   rpathlpath
chunk_sizecallbackr   r  r  r   chunks
             r   get_fileHTTPFileSystem.get_filet  s    [[
		&ULLT__U3:r:			.5 999==!148D 	$((2%  %E^^Ju^EEKK$$SZ0 F Hi0 	D	s   .AD7 7EEr   c                 (  ^^^ UUU4S jnU R                   R                  5       nUR                  U5        UR                  5       nUS;  a  [	        SU< 35      e[        U R                  U5      n	U	" U4SU" 5       0UD6n
U R                  X5        g )Nc               3     >#    [        T[        R                  5      (       a  [        T5      n SnO[	        TS5      n SnU  nU(       a3  TR                  UR                  SS5      5        UR                  S5        OTR                  [        USS 5      5        UR                  T5      nU(       a8  Uv   TR                  [        U5      5        UR                  T5      nU(       a  M8  S S S 5        g ! , (       d  f       g = f7f)NFrbTr   r   r   )r   r   r   r   r~   r   seekgetattrrM   r"  r   )contextuse_seekfr'  r&  r%  r$  s       r   
gen_chunks+HTTPFileSystem.put_file.<locals>.gen_chunks  s      %++%e, ud+A%%affQl3FF1I%%ga&>?z*K,,SZ8FF:.E e s   >DB%C1(	D1
C?;D)r   r   z.method has to be either 'post' or 'put', not: r   )r   r   r   lowerry   r.  r   r   )r)   r$  r#  r%  r&  r   r   r2  r  methresps    ` ``      r   put_fileHTTPFileSystem.put_file  s    	/. [[
		&(@
K  t||V,E3
33((5r   c                 8   SnSnUb3  US:  a-  Uc  U* nSnSnO'U=(       d    U R                  U5      S   nXB-   nOUc  SnU(       dM  Ub+  US:  a%  Ub!  U=(       d    U R                  U5      S   nXC-   nOUc  Sn[        U[        5      (       a  US-  nSU S	U 3$ )
z"Helper for "Range"-based _cat_fileNFr   r   Tr   r   bytes=-)infor   rB   )r)   rH   r  r  r   suffs         r   r  HTTPFileSystem._process_limits  s    {f5tyy~f5]E37$9499S>&#9D*C#s##qwau%%r   c                    U R                   R                  5       nUR                  U5         [        R	                  U5        U R
                  R                  " U R                  U5      40 UD6nUR                  S:  $ ! [         a     gf = f)NrW   F)
r   r   r   rv   rw   r   r   r   rD   r   )r)   r   r   r  r  s        r   existsHTTPFileSystem.exists  st    [[
		&	LL  !6="=A==3&& 		s   AA= =
B
	B
c                 (    U R                   " U40 UD6$ r$   )r@  )r)   r   r   s      r   isfileHTTPFileSystem.isfile  s    {{4*6**r   c           
         US:w  a  [         eUb  UOU R                  nU R                  R                  5       n	U	R	                  U5        U=(       d    U R
                  " U40 UD6S   nU(       aK  U(       aD  [        U U4U R                  UUUU=(       d    U R                  U=(       d    U R                  S.U	D6$ [        U U4UU R                  S.U	D6$ )aS  Make a file-like object

Parameters
----------
path: str
    Full URL with protocol
mode: string
    must be "rb"
block_size: int or None
    Bytes to download in one request; use instance value if None. If
    zero, will return a streaming Requests file-like instance.
kwargs: key-value
    Any other parameters, passed to requests calls
r,  r   )r   r   moder   r   r   )rF  r   )rx   r   r   r   r   r<  HTTPFiler   r   r   HTTPStreamFile)
r)   r   rF  r   
autocommitr   r   r   r   r  s
             r   _openHTTPFileSystem._open  s    2 4<%%#-#9Zt
[[
		&8tyy008$
 %%8+At/A/A
 
 
 " 	
  r   c                 B    [        XR                  U R                  5      $ )z;Unique identifier; assume HTTP files are static, unchanging)r   r   protocolr   s     r   ukeyHTTPFileSystem.ukey  s    [[$--88r   c           	      n   0 nS H[  n UR                  [        U R                  U5      4UU R                  S.U R                  DUD65        UR                  S5      b    OM]     USS.UESS0E$ ! [         a;  nUS:X  a  [        U5      Ue[        R                  [        U5      5         SnAM  SnAff = f)	a  Get info of URL

Tries to access location via HEAD, and then GET methods, but does
not fetch the data.

It is possible that the server does not supply any size information, in
which case size will be given as None (and certain operations on the
corresponding file will not work).
)r   r   )size_policyr   r   Nr   r   r   r   r   )r   
_file_infor   r   r   r   r   r  rv   rw   str)r)   rH   r   r<  policyexcs         r   r<  HTTPFileSystem.info  s     %F',$* $ ++	
 ! 88F#/ 0 && TBTB66BB  'U?+C0c9SX&&	's   AA//
B490B//B4c           	         SSK nUR                  S5      nU R                  U5      nUR                  S5      S:  a  UR                  S5      O
[	        U5      nUR                  S5      S:  a  UR                  S5      O
[	        U5      n[        Xg5      nUR                  SS5      n	[        U5      (       dN  Un
SnU(       a  US	-  nOU R                  U5      (       a  U	(       d  U/$ XR                  U5      0$ U	(       d  / $ 0 $ SUSU ;   a>  USU R                  S5      nUSUS-    n
S
U;   a  SOXS-   S R                  S5      S-   nO#Sn
S
U;   a  SOXS-   S R                  S5      S-   nU R                  " U
4U=(       d    USSS.UD6nSUR                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS 5      R                  S!S"5      R                  S5      -   S-   nUR                  " S#S$U5      nUR                  " S%S&U5      nUR                  " UR                  S$S'5      5      n[!        U5       Vs0 s H?  nUR#                  UR                  SS5      R                  S5      5      (       d  M:  XU   _MA     nnU	(       a  U$ [%        U5      $ s  snf )(z
Find files by glob-matching.

This implementation is idntical to the one in AbstractFileSystem,
but "?" is not considered as a character for globbing, because it is
so common in URLs, often identifying the "query" part.
r   Nr   *[r   Fr   z/*z**r   T)maxdepthwithdirsr   ^\z\\.z\.+z\+z//(z\()z\)|z\|z\^$z\${z\{}z\}z[*]{2}z=PLACEHOLDER=z[*]z[^/]*z.*)rer  r   findr   minr   	has_magicr@  r<  rindexcountr   r   subcompiler  matchlist)r)   r   r[  r   rg  endsindstarindbraceindr   rootdepthind2allpathspatternprP   s                    r   globHTTPFileSystem.glob7  s    	}}S!##D)$(IIcNa$7$))C.SY%)YYs^q%8499S>c$i'$He,DET"" 6M ))D/22IID#J:$$S)D
$(#D DLDd!8:.>.D.DS.IA.MED DLDd79o.C.CC.H1.LE99
#,utD
LR
 T5)e$e$s#e$e$e$e$e$e$e$  	$ &&?G<&&1**W___dCD H%
%}}QYYtS188=> A{N% 	 

 J9
s   ,9L)	Lc                 d     [        U R                  U5      5      $ ! [        [        4 a     gf = frb   )boolr  r  ry   )r)   r   s     r   isdirHTTPFileSystem.isdir  s1    	&&!:. 		s    //)r   r   r   r   r   ru   r   r   r   r   r   )TNT	readaheadNNF)T)NN)r,  NNNNNr$   ) r   r   r   r   rg   rM  sepr+   rh   r   r   classmethodrT  r   r   r  r  r   r  r   r(  r7  r  r@  rC  rJ  rN  r<  r{  r  r   __classcell__r   s   @r   r   r      s     <H
C =&~  
 3 3    ,\$" (1;L16 "+6Z&4+ 2h9C@N` r   r   c                   ^   ^  \ rS rSrSr      S	U 4S jjrS
U 4S jjrS rS rS r	Sr
U =r$ )rG  i  a<  
A file-like object pointing to a remove HTTP(S) resource

Supports only reading, with read-ahead of a predermined block-size.

In the case that the server does not supply the filesize, only reading of
the complete file in one go is supported.

Parameters
----------
url: str
    Full URL of the remote resource, including the protocol
session: requests.Session or None
    All calls will be made within this session, to avoid restarting
    connections where the server allows this
block_size: int or None
    The amount of read-ahead to do, in bytes. Default is 5MB, or the value
    configured for the FileSystem creating this file
size: None or int
    If given, this is the size of the file in bytes, and we don't attempt
    to call the server to find the value.
kwargs: all other key-values are passed to requests calls.
c	           
         > US:w  a  [        S5      eX l        X0l        X(SS.U l        [        T
U ]  " SUUUUUUS.U	D6  g )Nr,  zFile mode not supportedr   r   )fsr   rF  r   r   r   r   )rx   rH   r   detailsr   r+   )r)   r  rH   r   r   rF  r   r   r   r   r   s             r   r+   HTTPFile.__init__  s\     4<%&?@@ #6B 	
!!'	
 	
r   c                 J  > US:  aG  U R                   S:X  a7  U R                  b  U R                  U R                  ::  d  U R                  5         U R                  c  US:  a  U R                  5         O#[	        U R                  U R                   -
  U5      n[
        TU ]  U5      $ )zRead bytes from file

Parameters
----------
length: int
    Read up to this many bytes. If negative, read all content to end of
    file. If the server has not supplied the filesize, attempting to
    read only part of the data will raise a ValueError.
r   )locr   	blocksize
_fetch_allri  r   rM   )r)   lengthr   s     r   rM   HTTPFile.read  s}     aZDHHMYY*tyyDNN/JOO99z!TXX-v6Fw|F##r   c                    [         R                  SU  35        [        U R                  [        5      (       d  U R
                  R                  " U R                  R                  U R                  5      40 U R                  D6nUR                  5         UR                  n[	        [        U5      SSUS9U l        [        U5      U l        gg)zRead whole file in one shot, without caching

This is only called when position is still at zero,
and read() is called without a byte-count.
zFetch all for N)r   fetcherr  r   )rv   rw   r   cacher   r   r   r  r   rH   r   rJ   r]   r   r   )r)   r  rP   s      r   r  HTTPFile._fetch_all  s     	~dV,-$**h//  !3!3DHH!=MMA ))C!s3xTWXDJCDI 0r   c                 "   UR                  SS5      n[        R                  " SU5      nU(       d  gUS   S:X  a  S=pEO0US   R                  S5       Vs/ s H  n[	        U5      PM     snu  pEUS	   S:X  a  SO[	        US	   5      nXEU4$ s  snf )
zParse the Content-Range headerContent-Ranger   zbytes (\d+-\d+|\*)/(\d+|\*))NNNr   rY  Nr;  r   )r   rg  ro  r=   rB   )r)   r?   smr  r  xtotals           r   _parse_content_rangeHTTPFile._parse_content_range  s    KK,HH3Q7#Q43;EC*+A$**S/:/Q#a&/:JE!QqT5   ;s   Bc                    [         R                  SU  SU SU 35        U R                  R                  5       nUR	                  S0 5      R                  5       nSU SUS-
   3US'   [         R                  SU R
                  US   5        U R                  R                  " U R                  R                  U R
                  5      4SU0UD6nUR                  S	:X  a  g
UR                  5         UR                  R                  SUR                  R                  SUS-   5      5      nUR                  S:H  =(       d8    U R                  UR                  5      S   U:H  =(       d    [        U5      X!-
  :*  nU(       a  UR                  nU$ US:  a  [!        S5      eSn/ nUR#                  SS5       H"  n	UR%                  U	5        U['        U	5      -  nM$     S
R)                  U5      SX!-
   nU$ )a  Download a block of data

The expectation is that the server returns only the requested bytes,
with HTTP code 206. If this is not the case, we first check the headers,
and then stream the output - if the data size is bigger than we
requested, an exception is raised.
zFetch range for r9   r;  r?   r:  r   r  z%s : %si  r   r  r     r   zThe HTTP server doesn't appear to support range requests. Only reading this file from the beginning is supported. Open with block_size=0 for a streaming file interface.i   FN)rv   rw   r   r   r   rH   r   r   r  r   rD   rJ   r?   r  rB   r]   ry   rQ   appendr   r   )
r)   r  r  r   r?   r  clresponse_is_rangerP   r'  s
             r   _fetch_rangeHTTPFile._fetch_range  s    	'vRwau=>!!#**Y+002#E7!C!G95Y''*:;LLTWW//9U7UfU==C	 YY]]+QYY]];KSSTW-UVMMS  &((3A6%?&2w#+% 	 ))C  
 QYI  BCu5

5!c%j  6 ((3-#+.C
r   )r  r  r   r   rH   )NNr,  bytesNN)r   r   r   r   rg   r+   rM   r  r  r  r   r  r  s   @r   rG  rG    s:    8 
6$.!!0 0r   rG  z([*[])c                 4    [         R                  U 5      nUS L$ r$   )magic_checksearch)r  ro  s     r   rj  rj  ,  s    q!Er   c                   B   ^  \ rS rSrSU 4S jjrS rSS jrS rSrU =r	$ )	rH  i1  c                 `  > X l         X@l        US:w  a  [        eUS S.U l        [        TU ]  " S
XUSS.UD6  U R                  R                  " U R                  R                  U5      4SS0UD6nU R                  R                  Xb5        UR                  SS5      U l        S	U l        X`l        g )Nr,  rR  r  )r  r   rF  r   r&   Ti   Fr   r   )rH   r   ry   r  r   r+   r   r  r   r   rQ   itleftoverr  )r)   r  rH   rF  r   r   r  r   s          r   r+   HTTPStreamFile.__init__2  s    4< #T2VBtVvVLLTWW//4LTLVL++A3..u-r   c                     [        S5      e)NzCannot seek streaming HTTP file)ry   )r)   argsr   s      r   r-  HTTPStreamFile.seekA  s    :;;r   c                    U R                   /n[        U R                   5      nX1:  d  US:  aR   U R                  R                  5       nU(       a  UR                  U5        OOU[        U5      -  nX1:  a  MJ  US:  a  MR  SR                  U5      nUS:  a  XAS  U l         US U nOSU l         U =R                  [        U5      -  sl        U$ ! [         a     MZ  f = f)Nr   r   )r  r   r  __next__StopIterationr  r   r  )r)   numbufslengrP   s        r   rM   HTTPStreamFile.readD  s    4==!jC!Ggg&&( C CHD jC!G hhtn!8IDMds)CDMCH
 ! s   C 
CCc                 F    U R                   R                  5         SU l        g )NT)r  r6   closedr5   s    r   r6   HTTPStreamFile.closeZ  s    r   )r  r  r  r  r  r   rH   )r,  Nr  )
r   r   r   r   r+   r-  rM   r6   r   r  r  s   @r   rH  rH  1  s    <, r   rH  c                     UR                  5       nUR                  S0 5      R                  5       nSU SUS-
   3US'   U R                  " U4SU0UD6nUR                  5         UR                  $ )Nr?   r:  r;  r   r  )r   r   r   rJ   r]   )r   rH   r  r  r   r?   r  s          r   	get_ranger  _  so    [[]FjjB',,.Gwaay1GGC33F3A99r   c                    [         R                  SU 5        UR                  5       nUR                  SS5      nUR	                  S0 5      R                  5       nXSS'   0 nUS:X  a  UR
                  " U 4SU0UD6nO*US:X  a  UR                  " U 4SU0UD6nO[        SU 35      eUR                  5         SUR                  ;   a  [        UR                  S   5      US	'   OS
UR                  ;   a.  [        UR                  S
   R                  S5      S   5      US	'   OiSUR                  ;   a  [        UR                  S   5      US	'   O=SUR                  ;   a-  [        UR                  S   R                  S5      S   5      US	'   S H6  nUR                  R	                  U5      (       d  M%  UR                  U   Xh'   M8     U$ )zCall HEAD on the server to get details about the file (size/checksum etc.)

Default operation is to explicitly allow redirects and use encoding
'identity' (no compression) to get the true size of the target.
zRetrieve file size for %sr   Tr?   r   r   z)size_policy must be "head" or "get", got r  r   r  r   r   r  zcontent-range)ETagzContent-MD5Digest)rv   rw   r   r   r   r   r  rJ   r?   rB   r=   )	rH   r   rQ  r   arr   r<  r  checksum_fields	            r   rS  rS  i  s    LL,c2[[]F	%t	,B::i$))+D 9DfLL;b;F;		KK:R:6:CK=QRR 199$199%567V	AII	%199_5;;C@CDV	QYY	&199%567V	AII	%199_5;;C@CDV;99==((#$99^#<D  < Kr   c                  |    [        S[        SS9  [        S[        SS9  [        S[        SS9  [        S[        SS9  g )Nr   Tclobberr   r   r   )r   r   r   r   r   registerr    s2    FNDAG^TBKFL.$Gr   c                  <    SSK Jn   [        SU SS9  [        SU SS9  g )Nr   r   r   Tr  r   )fsspec.implementations.httpr   r   r  s    r   
unregisterr    s    :FNDAG^TBr   )r   )3rg   r   loggingrg  urllib.errorr{   urllib.parser   re   r   r   r   r   ImportErrorModuleNotFoundErrorOSErrorfsspec.callbacksr   fsspec.registryr   fsspec.specr	   r
   fsspec.utilsr   r   r   r   cachingr   rn  r   r   	getLoggerrv   error	HTTPErrorr   BytesIOr   r!   rj   r   rG  r  rj  rH  r  rS  r  r  r   r   r   <module>r     s*   . 	  	     ! / 3 @ N N  ZZMNjjEF			=	) 3fll,, 2rzz K  K \H5 H5VL' L^W# Wt jj"
+) +\(XH 	
Cc 	('2 Ds   D   D.-D.