
    7Thu                        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  S SKrS SK	r	S SK
JrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJrJrJrJrJr  S	S
KJr  \R:                  " S5      r\R:                  " S5      r\R@                  " S5      r!S r" " S S\5      r# " S S\5      r$\R:                  " S5      r%S r& " S S\5      r' " S S\5      r(SS jr)SS jr*SS jr+\" \+5      r,g)    N)copy)urlparse)AbstractAsyncStreamedFileAsyncFileSystemsyncsync_wrapper)DEFAULT_CALLBACK)FSTimeoutError)AbstractBufferedFile)DEFAULT_BLOCK_SIZEglob_translate
isfilelikenullcontexttokenize   )AllBytesz6<(a|A)\s+(?:[^>]*?\s+)?(href|HREF)=["'](?P<url>[^"']+)z-(?P<url>http[s]?://[-a-zA-Z0-9@:%_+.~#?&/=]+)zfsspec.httpc                  6   #    [         R                  " S0 U D6$ 7f)N )aiohttpClientSession)kwargss    S/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/http.py
get_clientr       s       *6**s   c                   B  ^  \ rS rSrSrSrSSSSSSSSS\S4U 4S jjr\S	 5       r	S
 r
\S 5       rS r\S 5       r\U 4S j5       rS"S jrS"S jr\" \5      rS rS#S jrS\4S jrS\SS4S jrS rS r      S$S jrS%S jrS rS rS&S jr S r!S'S  jr"S!r#U =r$$ )(HTTPFileSystem$   a  
Simple File-System for fetching data via HTTP(S)

``ls()`` is implemented by loading the parent page and doing a regex
match on the result. If simple_link=True, anything of the form
"http(s)://server.com/stuff?thing=other"; otherwise only links within
HTML href tags will be used.
/TNbytesFc                   > [         TU ]  " U 4XxS.UD6  Ub  UO[        U l        Xl        X0l        XPl        X`l        U	=(       d    0 U l        Xl	        Xl
        Xl        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)a	  
NB: if this is called async, you must await set_client

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')}``
get_client: Callable[..., aiohttp.ClientSession]
    A callable which takes keyword arguments and constructs
    an aiohttp.ClientSession. It's state will be managed by
    the HTTPFileSystem class.
storage_options: key-value
    Any other parameters passed on to requests
cache_type, cache_options: defaults used in open
)asynchronousloopNuse_listings_cacheFlistings_expiry_time	max_pathsskip_instance_cache)super__init__r   
block_sizesimple_linkssame_schema
cache_typecache_optionsclient_kwargsr   encodedr   _sessionr   popr"   )selfr)   r(   same_schemesize_policyr+   r,   r    r!   r-   r   r.   storage_optionsrequest_options	__class__s                 r   r'   HTTPFileSystem.__init__0   s    T 	WLWW(2(>*DV(&$**0b$% /"1"5"56JE"R2D9K.148%    c                     g)Nhttpr   r1   s    r   fsidHTTPFileSystem.fsidq   s    r8   c                 >    [         R                  " XR                  S9$ )N)r.   )yarlURLr.   r1   urls     r   
encode_urlHTTPFileSystem.encode_urlu   s    xx\\22r8   c                     U b+  U R                  5       (       a   [        XR                  SS9  g [        USS 5      nUb  UR                  5         g g ! [        [        [
        4 a     N9f = f)Ng?)timeout
_connector)
is_runningr   closeTimeoutErrorr
   NotImplementedErrorgetattr_close)r!   session	connectors      r   close_sessionHTTPFileSystem.close_sessionx   sm     1 1T==#6 G\48	  ! !.2EF s   A A)(A)c                 8  #    U R                   c|  U R                  " SSU R                  0U R                  D6I S h  vN U l         U R                  (       d6  [
        R                  " X R                  U R                  U R                   5        U R                   $  N\7f)Nr!   r   )r/   r   r!   r-   r    weakreffinalizerP   r;   s    r   set_sessionHTTPFileSystem.set_session   sm     == "&//"Wtyy"WDDVDV"WWDM$$  '9'9499dmmT}} Xs   9BBABc                     U$ )z-For HTTP, we always want to keep the full URLr   )clspaths     r   _strip_protocolHTTPFileSystem._strip_protocol   s	     r8   c                 F   > [         TU ]  U5      n[        U5      S:  a  U$ g)N    )r&   _parentlen)rX   rY   parr6   s      r   r_   HTTPFileSystem._parent   s&     god#s8a<Jr8   c           	      4  #    U R                   R                  5       nUR                  U5        [        R	                  U5        U R                  5       I S h  vN nUR                  " U R                  U5      40 U R                   D6 IS h  vN nU R                  Xa5         UR                  5       I S h  vN nU R                  (       a?  [        R                  U5      [        R                  U5       Vs/ s H  oS   PM	     sn-   n	O([        R                  U5       Vs/ s H  oS   PM	     n	n S S S 5      IS h  vN   [        5       n
[!        U5      nW	 GHj  n[#        U[$        5      (       a  US   nUR'                  S5      (       a,  [)        U5      S:  a  UR*                   SUR,                   U 3nUR'                  S5      (       a  U R.                  (       a;  UR'                  UR1                  S5      S-   5      (       a  U
R3                  U5        M  UR5                  SS5      R'                  UR5                  SS5      R1                  S5      S-   5      (       a  U
R3                  U5        GM  GM!  US;  d  GM*  U
R3                  SR7                  UR1                  S5      UR9                  S5      /5      5        GMm     U
(       d=  UR;                  S5      (       a'  U R=                  UR1                  S5      SS	9I S h  vN n
U(       a/  U
 Vs/ s H!  nUS UR;                  S5      (       a  S
OSS.PM#     sn$ [?        U
5      $  GN GN GNs  snf s  snf ! [         a    / n	 GN=f = f GN6! , IS h  vN  (       d  f       GNL= f Ns  snf 7f)Nr      r   z://r:   https)z..z../F)detail	directoryfilenamesizetype) r   r   updateloggerdebugrU   getrC   _raise_not_found_for_statustextr)   ex2findallexUnicodeDecodeErrorsetr   
isinstancetuple
startswithr`   schemenetlocr*   rstripaddreplacejoinlstripendswith_ls_realsorted)r1   rB   rf   r   kwrN   rrr   ulinksoutpartsls                r   r   HTTPFileSystem._ls_real   s    [[
		&S((**;;ts3Ct{{CCq,,Q4VVX~$$KK-rzz$?O0P?O!1?O0PPE+-::d+;<+;aqT+;E<E DC eA!U##aD||C  SVaZ||nC~aS9||F####SZZ_s5J(K(KGGAJYYw/::KK077<sB  GGAJ	 M)GGCHHcjjoqxx}%EFG# $ s||C((cjjoeDDC  A	  +,::c??K
   #;W +C &0P<%  DCCC> Es   ANM4NMNM6"M 5M6A M 6MM 	M6
M !M/M 1M62N=M3>E NBNNN(N?NNM 
M  M0,M6/M00M63N6N<M?=N		NNc                    #    U R                   (       a   XR                  ;   a  U R                  U   nU$ U R                  " U4SU0UD6I S h  vN nX@R                  U'   U$  N7f)Nrf   )r"   dircacher   )r1   rB   rf   r   r   s        r   _lsHTTPFileSystem._ls   s`     ""smm';--$C 
 cC&CFCCC!$MM#
 Ds   A
A#A!A#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)statusFileNotFoundErrorraise_for_status)r1   responserB   s      r   rq   *HTTPFileSystem._raise_not_found_for_status   s'     ??c!#C((!!#r8   c                 j  #    U R                   R                  5       nUR                  U5        [        R	                  U5        Uc  UbG  X#:X  a  gUR                  S0 5      R                  5       nU R                  XU5      I S h  vN US'   XeS'   U R                  5       I S h  vN nUR                  " U R                  U5      40 UD6 IS h  vN nUR                  5       I S h  vN n	U R                  X5        S S S 5      IS h  vN   U	$  N Nl NC N- N! , IS h  vN  (       d  f       W	$ = f7f)Nr8   headersRange)r   r   rm   rn   ro   r0   _process_limitsrU   rp   rC   readrq   )
r1   rB   startendr   r   r   rN   r   r   s
             r   	_cat_fileHTTPFileSystem._cat_file   s     [[
		&S|ffY+002G%)%9%9#c%JJGG#yM((**;;ts3:r::a.C,,Q4 ;: 
  K*:  ;:: 
s~   BD3DD3#D$*D3DD3D&D'D<D3DD3D3D3DD3D0D!D0+D3i  P c                   #    U R                   R                  5       nUR                  U5        [        R	                  U5        U R                  5       I S h  vN nUR                  " U R                  U5      40 UD6 IS h  vN n [        UR                  S   5      n	UR                  U	5        U R                  X5        [        U5      (       a  Un
O[        US5      n
 SnU(       aW  UR                   R#                  U5      I S h  vN nU
R%                  U5        UR'                  [)        U5      5        U(       a  MW  [        U5      (       d  U
R+                  5         S S S 5      IS h  vN   g  GN N! [        [        4 a    S n	 Nf = f N! [        U5      (       d  U
R+                  5         f f = f NJ! , IS h  vN  (       d  f       g = f7f)Nzcontent-lengthwbT)r   r   rm   rn   ro   rU   rp   rC   intr   
ValueErrorKeyErrorset_sizerq   r   opencontentr   writerelative_updater`   rI   )r1   rpathlpath
chunk_sizecallbackr   r   rN   r   rk   outfilechunks               r   	_get_fileHTTPFileSystem._get_file   so     [[
		&U((**;;tu5<<<199%567 d#,,Q6%  ud+$"#)).."<<EMM%(,,SZ8 e
 "%((MMO+ =<< +< )  = "%((MMO )) =<<<s   AGE2*GE5GF9E7AF9!'FF	6F F9!G,F7-G5G7F	F9FF9F#F44F97G9G?G GGpost	overwritec                   ^^^#    US:w  a  [        S5      eUUU4S jnU R                  R                  5       n	U	R                  U5        U R	                  5       I S h  vN n
UR                  5       nUS;  a  [        SU< 35      e[        X5      nU" U R                  U5      4SU" 5       0U	D6 IS h  vN nU R                  X5        S S S 5      IS h  vN   g  N~ N( N	! , IS h  vN  (       d  f       g = f7f)Nr   zExclusive writec                 
  >#    [        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(       a9  U7v   TR                  [        U5      5        UR                  T5      nU(       a  M9  S S S 5        g ! , (       d  f       g = f7f)NFrbTr   r   rk   )rx   ioIOBaser   r   r   seekrL   r   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&C2)	D2
D <D)r   putz.method has to be either 'post' or 'put', not: data)
rK   r   r   rm   rU   lowerr   rL   rC   rq   )r1   r   r   r   r   methodmoder   r   r   rN   methresps    ` ``        r   	_put_fileHTTPFileSystem._put_file  s      ;%&788	/. [[
		&((**(@
K  w'.HZ\HRHHD,,T9 IHH + IHHHs[   AC<CAC<5C6C<9C"C<C C<C< C<"C9(C+)C95C<c                   #    U R                   R                  5       nUR                  U5         [        R	                  U5        U R                  5       I S h  vN nUR                  " U R                  U5      40 UD6I S h  vN nU IS h  vN   UR                  S:  sS S S 5      IS h  vN   $  NY N1 N( N! , IS h  vN  (       d  f       g = f! [        R                   a     gf = f7f)Ni  F)r   r   rm   rn   ro   rU   rp   rC   r   r   ClientError)r1   rY   r   r   rN   r   s         r   _existsHTTPFileSystem._exists?  s     [[
		&	LL ,,..Gkk$//$"7>2>>Aqxx#~ qq />qqq"" 		s   ,C-(C B1)C B3
C B5C B9C +B7,C 0C-1C 3C 5C 7C 9C?C CC C-C C*'C-)C**C-c                 D   #    U R                   " U40 UD6I S h  vN $  N7fN)r   )r1   rY   r   s      r   _isfileHTTPFileSystem._isfileK  s     \\$1&1111s     c                 l   US:w  a  [         eUb  UOU R                  nU R                  R                  5       n	U R                  U	S'   U	R                  U5        0 n
U=(       d.    U
R                  U R                  " U40 UD65      =(       d    U
S   n[        U R                  U R                  5      nU(       ac  U(       a\  U
R                  SS5      (       aE  [        U U4UUUUU=(       d    U R                  U=(       d    U R                  U R                  S.U	D6$ [        U U4UU R                  U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    rk   partialT)rN   r(   r   rk   r+   r,   r!   )r   r!   rN   )rK   r(   r   r   r    rm   infor   r!   rU   rp   HTTPFiler+   r,   HTTPStreamFile)r1   rY   r   r(   
autocommitr+   r,   rk   r   r   r   rN   s               r   _openHTTPFileSystem._openN  s-   2 4<%%#-#9Zt
[[!..>
		&Mt{{499T#<V#<=Mftyy$"2"23$488It#<#<  %%8+At/A/AYY   " YY  r8   c                    #    U R                  5       I S h  vN nUc   U R                  " U40 UD6I S h  vN S   n[        U U4U R                  UUS.UD6$  NA N$! [         a     N+f = f7f)Nrk   )r!   rN   rk   )rU   _infor   AsyncStreamFiler!   )r1   rY   r   rk   r   rN   s         r   
open_asyncHTTPFileSystem.open_async  s     ((**<"jj888&A 
 
 
 	
 + 9$ sA   A,AA,A AA A,A 
A)&A,(A))A,c                 B    [        XR                  U R                  5      $ )z;Unique identifier; assume HTTP files are static, unchanging)r   r   protocolrA   s     r   ukeyHTTPFileSystem.ukey  s    [[$--88r8   c           	        #    0 nU R                  5       I Sh  vN nS HY  n UR                  [        U R                  U5      4UUS.U R                  DUD6I Sh  vN 5        UR                  S5      b    OM[     USS.UES	S
0E$  Nn N-! [         a1  nUS:X  a  [        U5      Ue[        R                  SUS9   SnAM  SnAff = f7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).
N)headrp   )r3   rN   rk   rp   r^   )exc_inforj   rk   rl   rh   )
rU   rm   
_file_inforC   r   rp   	Exceptionr   rn   ro   )r1   rB   r   r   rN   policyexcs          r   r   HTTPFileSystem._info  s      ((**%F/$,$* ' ++	
 !  88F#/ 0 && TBTB66BB+ +
  /U?+C0c9R#.	/sJ   C	B	C	8BB	
B6C		B
C&C;C	CC	c           	        #    Ub  US:  a  [        S5      eSSKnUR                  S5      nU R                  U5      nU=(       d    UR                  S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[        Xx5      n	UR                  S	S
5      n
[        U5      (       dQ  U R                  " U40 UD6I Sh  vN (       a&  U
(       d  U/$ XR                  " U40 UD6I Sh  vN 0$ U
(       d  / $ 0 $ SUSU	 ;   a6  USU	 R                  S5      n	USU	S-    nXS-   S R                  S5      S-   nOSnXS-   S R                  S5      S-   nSU;   a4  Ub/  UR	                  S5      nXS R                  S5      S-   nX-
  U-   nOSnU R                  " U4USSS.UD6I Sh  vN n[        X(       a  SOS-   5      nUR                  " U5      n[!        UR#                  5       5       VVs0 s Hg  u  nnUR%                  UR'                  S5      5      (       d  M-  U(       d0  US   S:X  a'  UR                  S5      (       a  UR'                  S5      OUU_Mi     nnnU
(       a  U$ [)        U5      $  GN GN Ns  snnf 7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.
Nrd   zmaxdepth must be at least 1r   r   )z/**z/**[rf   Fr^   z**T)maxdepthwithdirsrf   rl   rg   )r   rer   rZ   findr`   minr0   	has_magicr   r   rindexcount_findr   compiler   itemsmatchr}   list)r1   rY   r   r   r   ends_with_slashappend_slash_to_dirnameidx_star	idx_bracemin_idxrf   rootdepthidx_double_starsdepth_double_starsallpathspatternpr   r   s                       r   _globHTTPFileSystem._glob  s     HqL:;;--,##D)"1"QT]]=5Q%)YYs^q%8499S>c$i&*iin&9DIIcNs4y	h*He,\\$1&111 6M 

4(B6(B"BCCIID'N"8Gn++C0G'A+&D1'--c2Q6ED1'--c2Q6E4<##'99T? %)*;%<%B%B3%G!%K"2X=
 4
@F
 
 !R!HI**W% "(.."23

 44}}QXXc]+.LK/JJsOO   4 	 

 J9a 2 #C,


sP   C:K<J3=)K&J6'B>K%J9&AK.,J;>J;K6K9K;Kc                    #     [        U R                  U5      I S h  vN 5      $  N! [        [        4 a     gf = f7f)NF)boolr   r   r   )r1   rY   s     r   _isdirHTTPFileSystem._isdir  s9     	dhhtn,--,!:. 		s(   >( &( >( ;>;>c                 l  #    U R                  U5      nUR                  S0 5      n[        [        U5      5      US'   U R	                  5       I Sh  vN nUR
                  " U4X&S.UD6 ISh  vN nUR                  5         SSS5      ISh  vN   g NC N' N	! , ISh  vN  (       d  f       g= f7f)a(  
Write bytes to a remote file over HTTP.

Parameters
----------
path : str
    Target URL where the data should be written
value : bytes
    Data to be written
mode : str
    How to write to the file - 'overwrite' or 'append'
**kwargs : dict
    Additional parameters to pass to the HTTP request
r   Content-LengthN)r   r   )rZ   r0   strr`   rU   r   r   )	r1   rY   valuer   r   rB   r   rN   r   s	            r   
_pipe_fileHTTPFileSystem._pipe_file  s      ""4(**Y+$'E
O !((**;;sJJ6JJa  KJJ +JJJJsZ   AB4BB4.B/B42BB4BB4B4B4B1 B#!B1-B4)r/   r(   r,   r+   r-   r.   r   r   r*   r)   r"   )T)NN)r   NNNNN)r   Nr   )r   )%__name__
__module____qualname____firstlineno____doc__sepr   r'   propertyr<   rC   staticmethodrP   rU   classmethodrZ   r_   r   r   r   lsrq   r   r	   r   r   r   r   r   r   r   r   r  r
  r  __static_attributes____classcell__r6   s   @r   r   r   $   s     C ?&B  3 
 
    0d 
c	B$& (1;K$D !0:d
2 7r
 9 CDGR! !r8   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\" \5      r	S r
S r\" \5      rSrU =r$ )r   i&  aC  
A file-like object pointing to a remote HTTP(S) resource

Supports only reading, with read-ahead of a predetermined 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: aiohttp.ClientSession 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Xl        Xl        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 supportedrh   ri   )fsrY   r   r(   r+   r,   r   )rK   r    r!   rB   rN   detailsr&   r'   )r1   r!  rB   rN   r(   r   r+   r,   rk   r!   r    r   r6   s               r   r'   HTTPFile.__init__?  sg     4<%&?@@(	 #6B 	
!!'	
 	
r8   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   )locrk   	blocksize
_fetch_allr   r&   r   )r1   lengthr6   s     r   r   HTTPFile.read^  s}     aZDHHMYY*tyyDNN/JOO99z!TXX-v6Fw|F##r8   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I Sh  vN nU ISh  vN   UR                  5         UR                  5       I Sh  vN n[	        [        U5      SSUS9U l        [        U5      U l        SSS5      ISh  vN   gg Ns Nj ND N! , ISh  vN  (       d  f       g= f7f)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)rk   fetcherr&  r   )rn   ro   rx   cacher   rN   rp   r!  rC   rB   r   r   r   r`   rk   )r1   r   r   s      r   async_fetch_allHTTPFile.async_fetch_allu  s      	~dV,-$**h//ll&&tww'9'9$(('CSt{{SSAq""$FFHn%S44c
  H	 qq 0S$ qqqsl   BDC;
DC=D$D:C?;.D)D4D5D=D?DDD	D
DD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+|\*))NNNrd   r   N-r   )rp   r   r   splitr   )r1   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                  U R
                   SUS    35        U R                  R                  " U R                  R                  U R
                  5      4SU0UD6I S	h  vN nU IS	h  vN   UR                  S
:X  a   S	S	S	5      IS	h  vN   gUR                  5         UR                  S:H  =(       dU    U R                  UR                  5      S   U:H  =(       d-    [        UR                  R                  SUS-   5      5      X!-
  :*  nU(       a  UR                  5       I S	h  vN nOUS:  a  [!        S5      eSn/ n UR"                  R                  S5      I S	h  vN n	U	(       a)  UR%                  U	5        U['        U	5      -  nXU-
  :  a  OOOMV  SR)                  U5      S	X!-
   nUsS	S	S	5      IS	h  vN   $  GNb GNZ GN< N Nk N! , IS	h  vN  (       d  f       g	= f7f)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 z: r1  r   bytes=rd   r   z : Ni  r8      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   )rn   ro   r   r   r0   rB   rN   rp   r!  rC   r   r   r7  r   r   r   r   r   appendr`   r   )
r1   r   r   r   r   r   response_is_ranger   clr   s
             r   async_fetch_rangeHTTPFile.async_fetch_range  s#     	'vRwau=>!!#**Y+002#E7!C!G95zWW%5$678,,""GGtxx(
29
=C
 
 1xx3 11   C P,,QYY7:eCPqyy}}%5sQw?@CKO  !FFHn M  "#)).."77E

5)c%j(e+! ,   hhsmMck2S 11
 $ % 8? 111s   CI H7
I  H:!I $I6I H=I BII 9IIAI%I 1I2I :I =I  III IIII )r    r,  r"  r!   rN   rk   rB   )NNr   r   NNNF)r  r  r  r  r  r'   r   r-  r   r'  r7  r?  _fetch_ranger  r  r  s   @r   r   r   &  sU    8 
>$.%" o.J!9v   12Lr8   r   z([*[])c                 4    [         R                  U 5      nUS L$ r   )magic_checksearch)r3  r   s     r   r   r     s    q!Er8   c                   b   ^  \ rS rSrSU 4S jjrS	S jrS
S jr\" \5      rS r	U 4S jr
SrU =r$ )r   i  c                 "  >^ ^^ TR                  SS5      T l        TT l        UT l        UT l        US:w  a  [
        eTS S.T l        [        TT ]   " SUTUSS.TD6  UU U4S jn[        T R                  U5      T l
        UR                  T l        g )	Nr    Fr   r   noner!  rY   r   r+   c                     >#    TR                   R                  " TR                  R                  T5      40 TD6R	                  5       I S h  vN n TR                  R                  U T5        U $  N"7fr   )rN   rp   r!  rC   
__aenter__rq   )r   r   r1   rB   s    r   cor$HTTPStreamFile.__init__.<locals>.cor  sY     ll&&tww'9'9#'>I&ITTVVAGG//37H Ws   AA0A.#A0r   )r0   r    rB   r!   rN   r   r"  r&   r'   r   r   )	r1   r!  rB   r   r!   rN   r   rM  r6   s	   ` `   ` r   r'   HTTPStreamFile.__init__  s    "JJ~u=	4< #T2QBStQ&Q	
 dii%GG	r8   c                 ^    US:X  a  US:X  a  g XR                   :X  a  US:X  a  g [        S5      e)Nr   rd   zCannot seek streaming HTTP file)r%  r   )r1   r%  whences      r   r   HTTPStreamFile.seek  s0    !8!((?v{:;;r8   c                    #    U R                   R                  R                  U5      I S h  vN nU =R                  [	        U5      -  sl        U$  N$7fr   )r   r   r   r%  r`   )r1   numr   s      r   _readHTTPStreamFile._read  s<     FFNN'',,CH
 -s   )AA%Ac                 @   #    U R                   R                  5         g 7fr   )r   rI   r;   s    r   rM   HTTPStreamFile._close  s     s   c                    > [         R                  " U R                  5       U R                  5        [        TU ]  5         g r   )asynciorun_coroutine_threadsaferM   r!   r&   rI   r1   r6   s    r   rI   HTTPStreamFile.close   s&    ((		Br8   )r    r"  r!   r   rN   rB   )r   NN)r   rA  )r  r  r  r  r'   r   rU  r   r   rM   rI   r  r  r  s   @r   r   r     s-    $<
 D r8   r   c                   D   ^  \ rS rSr SU 4S jjrSS jrU 4S jrSrU =r$ )r   i  c                    > X l         XPl        S U l        US:w  a  [        eUS S.U l        Xpl        [        TU ]  XUSS9  X`l        g )Nr   r   rI  rJ  )	rB   rN   r   r   r"  r   r&   r'   rk   )	r1   r!  rB   r   r!   rN   rk   r   r6   s	           r   r'   AsyncStreamFile.__init__  sM     4< #T2BtG	r8   c                   #    U R                   c  U R                  R                  " U R                  R	                  U R
                  5      40 U R                  D6R                  5       I S h  vN nU R                  R                  X R
                  5        X l         U R                   R                  R                  U5      I S h  vN nU =R                  [        U5      -  sl        U$  N| N&7fr   )r   rN   rp   r!  rC   rB   r   rL  rq   r   r   r%  r`   )r1   rT  r   r   s       r   r   AsyncStreamFile.read  s     66>ll&&""488,04jlA GG//88<FFFNN'',,CH

 -s%   A)C,+C(,AC,C*%C,*C,c                    >#    U R                   b!  U R                   R                  5         S U l         [        TU ]  5       I S h  vN   g  N7fr   )r   rI   r&   r\  s    r   rI   AsyncStreamFile.close  s3     66FFLLNDFgmos   A AA	A)r"  r   r   rN   rk   rB   )r   NNNrA  )	r  r  r  r  r'   r   rI   r  r  r  s   @r   r   r     s    @D	 r8   r   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I S h  vN nUR                  5         U IS h  vN   UR	                  5       I S h  vN nS S S 5      IS h  vN   U(       a8  [        US5       n	U	R                  U5        U	R                  W5        S S S 5        g W$  N No NY NK! , IS h  vN  (       d  f       N`= f! , (       d  f       g = f7f)Nr   r:  r1  rd   r   zr+b)r   r0   rp   r   r   r   r   r   )
rN   rB   r   r   rh   r   r   r   r   r   s
             r   	get_rangerf  %  s     [[]FjjB',,.Gwaay1GGkk#9w9&99AqFFHn q$!FF5MGGCL  
 	: qqq s   ADC"D4C$5D8C*C&C*DC(D4#DD$D&C*(D*D0C31D=D
DDc                   #    [         R                  SU 5        UR                  5       nUR                  SS5      nUR	                  S0 5      R                  5       nSUS'   XSS'   0 nUS:X  a  UR
                  " U 4SU0UD6I Sh  vN nO2US	:X  a  UR                  " U 4SU0UD6I Sh  vN nO[        S
U 35      eU ISh  vN   UR                  5         SUR                  ;   a?  SUR                  ;  d  UR                  S   S;   a  [        UR                  S   5      US'   O=SUR                  ;   a-  [        UR                  S   R                  S5      S   5      US'   SUR                  ;   a$  UR                  S   R                  S5      S   US'   UR                  R	                  S5      S:X  a  SUS'   [        UR                  5      US'   S H6  nUR                  R	                  U5      (       d  M%  UR                  U   Xh'   M8     SSS5      ISh  vN   U$  GN GN| GNe N! , ISh  vN  (       d  f       U$ = f7f)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 %sallow_redirectsTr   identityzAccept-Encodingr   Nrp   z)size_policy must be "head" or "get", got r  zContent-Encoding)ri  r^   rk   r0  r   rd   zContent-Type;r   mimetypezAccept-RangesrI  Fr   rB   )ETagzContent-MD5Digest)rn   ro   r   r0   rp   r   	TypeErrorr   r   r   r2  	partitionr  rB   )	rB   rN   r3   r   arr   r   r   checksum_fields	            r   r   r   6  s     LL,c2[[]F	%t	,B::i$))+D(D	9Df,,sABA&AA		++c@2@@@CK=QRRq	qyy( "2aii@R6S X 7  #199-=#>?V		)qyy9??DQGHDLQYY& yy8BB3GJD99==)V3 $DO!%%jU?Nyy}}^,,'(yy'@$ @1 q8 KC B@ qqq8 Kss   BIH!#I(H$)IH'ID0H,:H,IH*I$I'I*I,I2H53I?Ic                    #    Uc  [        5       I S h  vN n[        U /UQ7SU0UD6I S h  vN nUR                  S5      $  N. N7f)NrN   rk   )r   r   rp   )rB   rN   argsr   r   s        r   
_file_sizert  i  sG     "$CB4BB6BBD88F %Bs   AAAAAAr   )r   )-rZ  r   loggingr   rS   r   urllib.parser   r   r?   fsspec.asynr   r   r   r   fsspec.callbacksr	   fsspec.exceptionsr
   fsspec.specr   fsspec.utilsr   r   r   r   r   cachingr   r   ru   rs   	getLoggerrn   r   r   r   rE  r   r   r   rf  r   rt  	file_sizer   r8   r   <module>r     s     	  	   !   V V - , ,   ZZMNjjEF			=	)+!_ !Dk3# k3\ jj"
&) &R/ @"0f $	r8   