
    7Th?                     4   S SK r S SK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	  S SK
JrJr  S SK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Jr  S S	KJr  S S
KJrJrJ r   \RB                  " S5      r" " S S\#5      r$S r%S r&S r' " S S\RP                  RR                  5      r* " S S\RP                  RV                  5      r,S r- " S S\RP                  R\                  5      r/ " S S\5      r0 " S S\5      r1g! \ a    \(       d  S SKr Nf = f)    N)	lru_cache)chain)TYPE_CHECKINGLiteral)AbstractBufferedFile)AsyncFileSystem)DEFAULT_CALLBACK)
filesystemopensplit_protocol)AsyncFileSystemWrapper)
isfilelikemerge_offset_rangesother_pathszfsspec.referencec                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )ReferenceNotReachable   c                 8   > [         TU ]  " U6   Xl        X l        g N)super__init__	referencetarget)selfr   r   args	__class__s       X/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/reference.pyr   ReferenceNotReachable.__init__   s    $"    c                 :    SU R                    SU R                   3$ )NzReference "z" failed to fetch target r   r   r   s    r   __str__ReferenceNotReachable.__str__$   s    T^^,,Edkk]SSr   r!   )__name__
__module____qualname____firstlineno__r   r#   __static_attributes____classcell__r   s   @r   r   r      s    
T Tr   r   c                 F    [        [        U R                  5       5      5      $ r   )nextitervalues)ds    r   _firstr1   (   s    QXXZ !!r   c                     UR                  U 5      n[        U[        [        45      (       a9  [        US   [        5      (       a   US   (       a  [        US   5      S   $ US   $ g g Nr   )get
isinstancelisttuplestrr   )path
referencesrefs      r   _prot_in_referencesr<   ,   s]    
..
C#e}%%*SVS*A*A,/F~c!f%a(>A> +B%r   c                     [        U [        5      (       a  [        X5      U /0$ 0 nU  H/  n[        X15      nUR                  U/ 5      R	                  U5        M1     U$ r   )r5   r8   r<   
setdefaultappend)pathsr:   outr9   protocols        r   _protocol_groupsrC   2   sZ    %#E6@@
C&t8x$++D1  Jr   c                       \ rS rSrS rSrg)RefsValuesView<   c              #     #    U R                   R                  R                  5        H)  n[        R                  " U5      R                  5       v   M+     U R                   R                  R                  5        S h  vN   U R                   R                  5        Hf  nU R                   R                  U5      n[        U5      S:X  a  U R                   US-      v   MC  U R                   R                  U5       S h  vN   Mh     g  N N7f)Nr   /0)_mapping	zmetadatar/   jsondumpsencode_itemslistdir_get_chunk_sizeslen_generate_all_records)r   valfieldchunk_sizess       r   __iter__RefsValuesView.__iter__=   s     ==**113C**S/((** 4==''..000]]**,E--88?K;1$mmEDL11}}::5AAA - 	1 Bs%   A9D	;D<A?D	;D<
D	D	 Nr%   r&   r'   r(   rV   r)   rX   r   r   rE   rE   <   s    	Br   rE   c                       \ rS rSrS rSrg)RefsItemsViewI   c                 z    [        U R                  R                  5       U R                  R                  5       5      $ r   )ziprI   keysr/   r"   s    r   rV   RefsItemsView.__iter__J   s)    4==%%')=)=)?@@r   rX   NrY   rX   r   r   r[   r[   I   s    Ar   r[   c                 f    SnSn[        U S S S2   US S S2   5       H  u  pEX$U-  -  nX5-  nM     U$ )Nr      )r^   )idxsizesrS   multiss         r   ravel_multi_indexri   N   sH    
CDC"IuTrT{+4x	 , Jr   c                   2   \ rS rSrSr\S 5       r\S 5       r     S"S\S   4S jjr	S	 r
S
 r\S#S j5       r\" 5       S 5       rS$S jrS r\" S5      S 5       rS rS rS rS rS rS rS rS r\S 5       rS rS%S jrS%S jrS rS r S r!S  r"S!r#g)&LazyReferenceMapperW   a[  This interface can be used to read/write references from Parquet stores.
It is not intended for other types of references.
It can be used with Kerchunk's MultiZarrToZarr method to combine
references into a parquet store.
Examples of this use-case can be found here:
https://fsspec.github.io/kerchunk/advanced.html?highlight=parquet#parquet-storagec                     SS K nU$ r3   )numpy)r   nps     r   ro   LazyReferenceMapper.np`   s
    	r   c                     SS K nU$ r3   )pandas)r   pds     r   rs   LazyReferenceMapper.pdf   s
    	r   Nengine)fastparquetpyarrowc                 f   Xl         0 U l        XPl        X`l        X@l        U R                   S-   U l        Uc  [        R                  " S5      OUU l        U R                  R                  U=(       d    U R                   5      U l
        SSKJn  U R                  S:X  a  U" S5      c  [        S5      egg)aH  

This instance will be writable, storing changes in memory until full partitions
are accumulated or .flush() is called.

To create an empty lazy store, use .create()

Parameters
----------
root : str
    Root of parquet store
fs : fsspec.AbstractFileSystem
    fsspec filesystem object, default is local filesystem.
cache_size : int, default=128
    Maximum size of LRU cache, where cache_size*record_size denotes
    the total number of references that can be loaded in memory at once.
categorical_threshold : int
    Encode urls as pandas.Categorical to reduce memory footprint if the ratio
    of the number of unique urls to total number of refs for each variable
    is greater than or equal to this number. (default 10)
engine: Literal["fastparquet","pyarrow"]
    Engine choice for reading parquet files. (default is "fastparquet")
z/{field}/refs.{record}.parqNfiler   )	find_specrw   z)engine choice `pyarrow` is not installed.)rootrU   
cat_threshru   
cache_sizeurlfsspecr
   fsunstrip_protocolout_rootimportlib.utilrz   ImportError)r   r{   r   r   r}   categorical_thresholdru   rz   s           r   r   LazyReferenceMapper.__init__l   s    B 	/$99<</1z&##F+r001FTYYG,;;)#	)(<(DIJJ )E#r   c                 b    US;   a  U R                  5         U R                  U   $ [        U5      e)N)rN   record_sizerJ   )setup__dict__AttributeErrorr   items     r   __getattr__LazyReferenceMapper.__getattr__   s.    99JJL==&&T""r   c                 N  ^  0 T l         T R                  R                  SR                  T R                  S/5      5      T R                   S'   [
        R                  " T R                   S   5      nUS   T l        US   T l        [        T R                  S9U 4S j5       nUT l        g )N/
.zmetadatar   metadata)maxsizec                 j  > TR                   R                  XS9n[        R                  " TR                  R                  U5      5      n TR                  R                  UTR                  S9nUR                   Vs0 s H  oUXE   R                  5       _M     nnU$ s  snf ! [         a    Sn U$ f = f)zcached parquet file loader)rT   record)ru   N)r~   formatioBytesIOr   cat_filers   read_parquetru   columnsto_numpyOSError)rT   r   r9   datadfcrefsr   s          r   	open_refs,LazyReferenceMapper.setup.<locals>.open_refs   s     88???>D::dgg..t45DWW))$t{{)C57ZZ@Z25>>++Z@ K A Ks$   2B" =BB" B" "B21B2)rN   r   r   joinr{   rK   loadsr   rJ   r   r}   r   )r   metr   s   `  r   r   LazyReferenceMapper.setup   s    $(GG$4$4HHdii./%
L! jj\23}-Z 
4??	+		 
,		 #r   c                 x   0 US.nUc,  [         R                  R                  " U 40 U=(       d    0 D6u  p UR                  U 5      (       a  UR	                  U SS9  UR                  U SS9  UR                  SR                  U S/5      [        R                  " U5      R                  5       5        [        X40 UD6$ )a  Make empty parquet reference set

First deletes the contents of the given directory, if it exists.

Parameters
----------
root: str
    Directory to contain the output; will be created
storage_options: dict | None
    For making the filesystem to use for writing is fs is None
fs: FileSystem | None
    Filesystem for writing
record_size: int
    Number of references per parquet file
kwargs: passed to __init__

Returns
-------
LazyReferenceMapper instance
r   r   T	recursiveexist_okr   r   )r   core	url_to_fsexistsrmmakedirspiper   rK   rL   rM   rk   )r{   storage_optionsr   r   kwargsr   s         r   createLazyReferenceMapper.create   s    , k::{{,,TMo6KMHB99T??EE$$E'
D4(
$-.

30F0F0HI"46v66r   c                 >    S U R                    5       n[        U5      $ )zList top-level directoriesc              3   z   #    U  H1  oR                  S 5      (       a  M  UR                  SS5      S   v   M3     g7f).zr   rb   r   N)
startswithrsplit.0ps     r   	<genexpr>.LazyReferenceMapper.listdir.<locals>.<genexpr>   s-     V^<<PTCU#a #^s   ;;)rJ   set)r   dirss     r   rO   LazyReferenceMapper.listdir   s     WT^^V4yr   c                    UR                  S5      nU(       a  US-   OSnU R                  5       nU Vs/ s H4  nUR                  U5      (       d  M  SUR                  U5      ;  d  M2  UPM6     nnU(       Ga  [	        S/S U R
                   5       S U R                   5       5       Vs1 s H4  nUR                  U5      (       d  M  SUR                  U5      ;  d  M2  UiM6     nnUSL a  UR                  U5        [        U5      $ U V	s/ s H  oSSS	.PM
     n
n	U V	s/ s HQ  n	U	S
[        XR
                  ;   a#  [        R                  " U R
                  U	   5      OU R                  U	   5      S	.PMS     nn	[        X-   S S9$ Un[        U R
                   V	s/ s H  oR                  U S35      (       d  M  U	PM!     sn	U R                   V	s/ s H  oR                  U S35      (       d  M  U	PM!     sn	-   5      nU V	s/ s HQ  n	U	S
[        XR
                  ;   a#  [        R                  " U R
                  U	   5      OU R                  U	   5      S	.PMS     nn	U R                  U5      nUSL a  [        U5      [        U5      -   $ U R                  U5      n[!        X5       V	Vs/ s H  u  pUS   (       d  M  U	S
US   S	.PM     nn	nUU-   $ s  snf s  snf s  sn	f s  sn	f s  sn	f s  sn	f s  sn	f s  snn	f )zShortcut file listingsr    r   c              3   $   #    U  H  ov   M     g 7fr   rX   r   names     r   r   )LazyReferenceMapper.ls.<locals>.<genexpr>   s     5ndTn   c              3   $   #    U  H  ov   M     g 7fr   rX   r   s     r   r   r      s     2kdTkr   F	directoryr   r   typesizery   c                     U S   $ )Nr   rX   )rh   s    r   <lambda>(LazyReferenceMapper.ls.<locals>.<lambda>  s    AfIr   keyrc   )rstriprO   r   lstripr   rJ   rN   updatesortedrQ   rK   rL   r   _keys_in_fieldr6   rR   r^   )r   r9   detailpathdashdirnamesr0   r   fothersr   dirinfofileinforT   r_   recsrecrecinfos                    r   lsLazyReferenceMapper.ls   s   {{3!%4#:2<<> 
||H% *-QXXh5G*G  	 

  !N5dnn52dkk2A
 <<)  /2(9K.K    d#f~%RVWRV$k1ERVGW # #D !">>1 

4>>$#78![[. #   ',2EFF"nnLnd4&
0KTnL $K$qz/JtKL
 
  ~~- JJt~~d34T*  	 
 ""5)U?<$t*,,))%0 !_
,	1v <T63r7;, 	 

 '!!w
 X MK
"
s[   KK)K+K	K KK "AK%K*>K*K/
4K/
AK4-K9K9c                    XR                   ;   a  U R                   U   $ XR                  ;   a1  [        R                  " U R                  U   5      R	                  5       $ SU;  d  U R                  U5      (       a  [        U5      eUR                  SS5      u  p#U R                  U5      u  pEnU R                   R                  X$40 5      R                  US5      nUc  [        eU(       a  U$ US:X  a  g U R                  X$5      n/ SQn
U
 Vs/ s H  oU;   a  X   U   OSPM     nnUS   nUb  U$ US   c  [        S	5      eUSS
 SS/:X  a  USS $ USS
 $ ! [        [        [        4 a  n	[        U5      U	eSn	A	ff = fs  snf )zVGet the reference for one key

Returns bytes, one-element list or three-element list.
r   rb   FNr   r   r9   offsetr   rawrc   z1This reference does not exist or has been deleted   )rN   rJ   rK   rL   rM   _is_metaKeyErrorr   _key_to_recordr4   r   
ValueError	TypeErrorFileNotFoundError)r   r   rT   _r   ri
chunk_sizemayber   excr   r   	selectionr   s                 r   _load_one_key!LazyReferenceMapper._load_one_key"  s   
 ++;;s##NN"::dnnS1299;;^t}}S113-::c1%!%!4!4S!9J488UC=NL1_	)>>%0D 4AHIAITWR[47	Im?JQ<NOOQq>aV#Ra= !} I'89 	)3-S(	) Js   5E FE>-E99E>i   c                 2   UR                  SS5      u  p#U R                  U5      n[        U5      S:X  a  gUR                  S5       Vs/ s H  n[	        U5      PM     nn[        Xd5      nXpR                  -  nXpR                  -  n	X[        U5      4$ s  snf )z3Details needed to construct a reference for one keyr   rb   r   )r   r   r   .)r   rP   rQ   splitintri   r   )
r   r   rT   chunkrU   r   	chunk_idxchunk_numberr   r   s
             r   r   "LazyReferenceMapper._key_to_recordJ  s     zz#q)++E2{q %*[[%56%5SV%5	6(@!1!11,,,3{+++	 7s   	Bc                    XR                   ;  ag  U R                  U S3   n[        US   US   5       VVs/ s H  u  p4[        R                  " X4-  5      PM     nnnU=(       d    S/U R                   U'   U R                   U   $ s  snnf )z6The number of chunks along each axis for a given fieldz/.zarrayshapechunksrb   )rU   rJ   r^   mathceil)r   rT   zarrayrh   r   
size_ratios         r   rP   $LazyReferenceMapper._get_chunk_sizesW  s    (((^^ugX$67F-0&BR-S-STQ		!% -S   '1&7QCDU#&&	s   $Bc                     U R                  X5      n[        [        UR                  5       6 5      n[	        U5      S:X  a	  S U 5       $ [	        U5      S:X  a  US   $ S U 5       $ )z8The references for a given parquet file of a given fieldr   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r6   r   ts     r   r   7LazyReferenceMapper._generate_record.<locals>.<genexpr>g  s     (RDGGR   rb   r   c              3   Z   #    U  H!  oS    (       d  [        USS  5      OUS    v   M#     g7f)r   Nr  r  s     r   r   r  m  s'     Br!tD2AK15rs   )+)r   r.   r^   r/   rQ   )r   rT   r   r   its        r   _generate_record$LazyReferenceMapper._generate_recorda  s^    ~~e,#t{{}%&t9>(R((Y!^; CrBBr   c              #      #    SnU R                  U5       H  nX#-  nM	     [        R                  " X R                  -  5      n[	        U5       H  nU R                  X5       Sh  vN   M     g N	7f)zJLoad all the references within a field by iterating over the parquet filesrb   N)rP   r  r  r   ranger  )r   rT   nrecchr   s        r   rR   )LazyReferenceMapper._generate_all_recordso  sb     ''.BJD /yy 0 001DkF,,U;;; ";s   A#A1%A/&
A1c                     [        U 5      $ r   )rE   r"   s    r   r/   LazyReferenceMapper.valuesx  s    d##r   c                     [        U 5      $ r   )r[   r"   s    r   itemsLazyReferenceMapper.items{  s    T""r   c                     [        U 5      $ r   )idr"   s    r   __hash__LazyReferenceMapper.__hash__~  s    $xr   c                 $    U R                  U5      $ r   )r   )r   r   s     r   __getitem__LazyReferenceMapper.__getitem__  s    !!#&&r   c                 x   SU;   a  U R                  U5      (       du  UR                  SS5      u  p4U R                  U5      u  pVnU R                  R	                  X540 5      nX(U'   [        U5      U R                  :X  a  U R                  X55        g g [        US5      (       a  UR                  5       R                  5       n	O([        U[        5      (       a  UR                  5       n	OUn	XR                  U'   [        R                  " U	5      n
0 U R                  R!                  U0 5      EU
EU R                  U'   g )Nr   rb   to_bytes)r   r   r   rN   r>   rQ   r   writehasattrr(  decoder5   bytesrK   r   rJ   r4   )r   r   valuerT   r   r   rg   r   subdictrS   	new_values              r   __setitem__LazyReferenceMapper.__setitem__  s   #:dmmC00::c1-LE..s3LFqkk,,e_bAGAJ7|t///

5) 0 uj))nn&--/E5))lln"KK

3I"NT^^%7%7R%@"NI"NDNN3r   c                 <    U R                  S5      =(       d    SU ;   $ )Nr   z/.zr   r   s    r   r   LazyReferenceMapper._is_meta  s    ~~d#3u|3r   c                    XR                   ;   a  U R                   U	 g XR                  ;   a  U R                  U	 g SU;   a  U R                  U5      (       du  UR                  SS5      u  p#U R	                  U5      u  pEnU R                   R                  X$40 5      nS Xe'   [        U5      U R                  :X  a  U R                  X$5        g g S U R                   U'   g )Nr   rb   )	rN   rJ   r   r   r   r>   rQ   r   r)  )r   r   rT   r   r   rg   r.  s          r   __delitem__LazyReferenceMapper.__delitem__  s    ++C NN"s#cz$--"4"4::c1-#22371++00%"E!
w<4#3#33JJu- 4 $(C r   c           	         SS K nSS KnSS KnU R                  X4   nSn	[	        U5      U R
                  :  a   U R                  X5      n	U	(       a  U	S   n
U	S   nU	S   nU	S   nO~UR                  U R
                  UR                  SS9n
UR                  U R
                  S	S9nUR                  U R
                  S	S9nUR                  U R
                  UR                  SS9nUR                  5        H  u  p[        U[        5      (       ar  [        U
R                  5      S
:X  a1  US   U
R                  R                   ;  a  U
R#                  US   5      n
US   X'   [	        U5      S:  a  US   X'   US   X'   M  M  Uc  S X'   SX'   SX'   S X'   M  UR$                  R'                  U5      X'   M     UR)                  U
UUUS.SS9nUR*                  R-                  5       UR*                  R/                  5       =(       d    S-  U R0                  :  a  US   R3                  S
5      US'   SSS.nSS/nU=(       d    U R4                   SU SU S3nU R6                  R9                  U=(       d    U R4                   SU 3SS9  U R:                  S:X  a  SS0nO/U R:                  S:X  a  SUUS.nO[=        U R:                   S35      eUR>                  " U4U R:                  U=(       d    [A        U R6                  SS 5      SSS.UD6  URC                  5         U R                  RE                  X45        g ! [         a     GNf = f)Nr   Fr9   r   r   r   O)dtypeint64categoryrb      r   )copyr,  utf8)r   r9   r   z/refs.z.parqTr   rw   write_statisticsrv   )statsobject_encoding	has_nullsz not supportedr   zstd)ru   r   compressionindex)#kerchunk.dfrn   rr   rN   rQ   r   r   r   fullnanzerosr  r5   r6   r8   r:  
categoriesadd_categoriesr   	_proc_raw	DataFramer9   countnuniquer|   astyper   r   mkdirsru   NotImplementedError
to_parquetgetattrclearpop)r   rT   r   base_urlr   kerchunkro   rs   	partitionoriginalr@   offsetsre   rawsjr   r   rB  rC  fndf_backend_kwargss                        r   r)  LazyReferenceMapper.write  s5   KK0	y>D,,,>>%8 V$Ex(GV$EE?DGGD,,bffCG@Ehht//wh?GHHT--WH=E774++RVV37?D (GA$%%$
2Qu{{'='==!00a9E7t9q=!%aGJ#AwEH ! 
 #++//5' )* \\!	   
 77==?bggoo/415GF**:6BvJ")6:UO	)DMM*!E7&F(3dmm4AeW=M;;)#!3U ;[[M)#2&! &^&DEE
	
;;+ 9tww 148	
  	
 	(Q  s   L8 8
MMc                    [        U R                  5       H0  n[        U[        5      (       d  M  Uu  pEU R	                  UUUUS9  M2     [        U R                  5       HO  nUS:w  d  M  SU;   d  M  [
        R                  " U R                  R                  U5      5      U R                  U'   MQ     U R                  U R                  S.nU R                  R                  5         [
        R                  " U5      R                  5       U R                  S'   U R                  R                  SR                  U=(       d    U R                   S/5      U R                  S   5        U R"                  R%                  5         g)zdOutput any modified or deleted keys

Parameters
----------
base_url: str
    Location of the output
)rX  r   r   r   r   r   N)r6   rN   r5   r7   r)  rK   r   rW  rJ   r   rV  rL   rM   r   r   r   r   r   cache_clear)r   rX  r   thingrT   r   kr   s           r   flushLazyReferenceMapper.flush  s    $++&E%'' %

%$3	   ' dkk"AL TQY$(JJt{{q/A$Bq! #  >>$:J:JK$(JJsO$:$:$<L!HHh/$-->?KK%	
 	""$r   c                 0   SnU R                  5        HH  nUR                  S5      (       a  US-  nM   U[        R                  " U R	                  U5      5      -  nMJ     U[        U R                  5      -  nU[        S U R                   5       5      -  nU$ )Nr   r   rb   c              3   T   #    U  H  n[        U[        5      (       a  M  S v   M      g7f)rb   N)r5   r7   )r   r   s     r   r   .LazyReferenceMapper.__len__.<locals>.<genexpr>/  s     H1:a3GQQs   (	()	rO   r   r  prodrP   rQ   rJ   sumrN   )r   rO  rT   s      r   __len__LazyReferenceMapper.__len__%  s    \\^E$$
4#8#8#?@@	 $
 	T^^$$HHHHr   c              #   (  #    [        U R                  5      nUR                  U R                  5        U H  n[	        U[
        5      (       d  M  Uv   M      U R                  5        H&  nU R                  U5       H  nX@;   d  M
  Uv   M     M(     g 7fr   )r   rJ   r   rN   r5   r8   rO   r   )r   metasbitrT   re  s        r   rV   LazyReferenceMapper.__iter__2  sr      DNN#T[[!C#s##	  \\^E((/9G 0 $s   A	B2BBc                 H     U R                  U5        g! [         a     gf = f)NTF)r   r   r   s     r   __contains__ LazyReferenceMapper.__contains__?  s*    	t$ 		s    
!!c           
   #     #    U R                  U5      n[        U5      S:X  a  US-   v   g[        R                  " S U 5       6 nU H6  nUS-   SR	                  U Vs/ s H  n[        U5      PM     sn5      -   v   M8     gs  snf 7f)zlList key names in given field

Produces strings like "field/x.y" appropriate from the chunking of the array
r   rH   Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )r  )r   rg   s     r   r   5LazyReferenceMapper._keys_in_field.<locals>.<genexpr>O  s     "A[588[r  r   r   )rP   rQ   	itertoolsproductr   r8   )r   rT   rU   indsindr   s         r   r   "LazyReferenceMapper._keys_in_fieldF  s     
 ++E2{q $,  "A["ABC#+#)>#Q#a&#)> ??? )>s   ABB2B)rN   r}   r|   rU   ru   r   r   r   r   r{   r~   rJ   )NN   
   rv   )NNi'  )r   TNN)$r%   r&   r'   r(   __doc__propertyro   rs   r   r   r   r   staticmethodr   r   rO   r   r   r   rP   r  rR   r/   r  r"  r%  r0  r   r6  r)  rf  rm  rV   rt  r   r)   rX   r   r   rk   rk   W   s   Y  
    4A.K 01.K`##0 7 7< [ 
@"D&P t_
, 
,'C<$#'O( 4 4("S)j!%F@r   rk   c                   2  ^  \ rS rSrSrSrSr            S"U 4S jjrS#S jrS#S jr	S#S jr
S	 rS
 r\4S jrS$S jrS%S jrS&S jrS rS&S jrS rS rS rS'S jrS(S jrS rS rS rS(S jrS)U 4S jjrS rS rS r S*S jr!S*S jr"S  r#S!r$U =r%$ )+ReferenceFileSystemiT  a  View byte ranges of some other file as a file system
Initial version: single file system target, which must support
async, and must allow start and end args in _cat_file. Later versions
may allow multiple arbitrary URLs for the targets.
This FileSystem is read-only. It is designed to be used with async
targets (for now). We do not get original file details from the target FS.
Configuration is by passing a dict of references at init, or a URL to
a JSON file containing the same; this dict
can also contain concrete data for some set of paths.
Reference dict format:
{path0: bytes_data, path1: (target_url, offset, size)}
https://github.com/fsspec/kerchunk/blob/main/README.md
r   Fc                 	  > [         TU ]  " S0 UD6  X l        Xl        Xl        0 U l        0 U l        0 U l        Xl        Xl	        [        U[        5      (       a  [        S0 U=(       d    U=(       d    0 DSU0D6n[        R                  R                  " U40 UD6u  nnUR!                  U5      (       a`  [        R"                  " US40 UD6 n[$        R'                  SU5        [(        R*                  " U5      nSSS5        U R-                  WU	5        O8[$        R'                  SU5        [/        UUUS9U l        OU R-                  X5        [        U[        5      (       a  UR3                  5        VVs0 s HH  u  nnU[        U[        5      (       a*  [        R4                  " UR7                  SS5      S	   40 UD6OU_MJ     snnU l        SU R                  ;  a  [5        S
5      U R                  S'   gUbH  [        UR8                  [:        5      (       a  UR8                  S	   OUR8                  nXR                  U'   Uc  U R
                  R=                  5        Hz  n[?        U5      (       a  U" 5       n[        R                  RA                  U5      u  nnU(       d  ME  UU R                  ;  d  MW  [5        U40 U=(       d    0 D6nXR                  U'   M|     Uc  U R0                  R=                  5        H  n[?        U5      (       a  U" 5       n[        U[B        5      (       d  M1  US	   (       d  M=  [        R                  RA                  US	   5      u  nnUU R                  ;  d  Mt  [5        U40 U=(       d    0 D6nXR                  U'     O   U(       a2  X`R                  ;  a#  [5        U40 U=(       d    0 D6nXR                  U'   U=(       d    [5        S
5      U R                  S'   U R                  R3                  5        Hc  u  nnURD                  (       d#  [G        UU RH                  S9U R                  U'   M:  U RH                  URH                  -  (       d  MZ  [K        S5      e   g! , (       d  f       GN}= fs  snnf )a`
  
Parameters
----------
fo : dict or str
    The set of references to use for this instance, with a structure as above.
    If str referencing a JSON file, will use fsspec.open, in conjunction
    with target_options and target_protocol to open and parse JSON at this
    location. If a directory, then assume references are a set of parquet
    files to be loaded lazily.
target : str
    For any references having target_url as None, this is the default file
    target to use
ref_storage_args : dict
    If references is a str, use these kwargs for loading the JSON file.
    Deprecated: use target_options instead.
target_protocol : str
    Used for loading the reference file, if it is a path. If None, protocol
    will be derived from the given path
target_options : dict
    Extra FS options for loading the reference file ``fo``, if given as a path
remote_protocol : str
    The protocol of the filesystem on which the references will be evaluated
    (unless fs is provided). If not given, will be derived from the first
    URL that has a protocol in the templates or in the references, in that
    order.
remote_options : dict
    kwargs to go with remote_protocol
fs : AbstractFileSystem | dict(str, (AbstractFileSystem | dict))
    Directly provide a file system(s):
        - a single filesystem instance
        - a dict of protocol:filesystem, where each value is either a filesystem
          instance, or a dict of kwargs that can be used to create in
          instance for the given protocol

    If this is given, remote_options and remote_protocol are ignored.
template_overrides : dict
    Swap out any templates in the references file with these - useful for
    testing.
simple_templates: bool
    Whether templates can be processed with simple replace (True) or if
    jinja  is needed (False, much slower). All reference sets produced by
    ``kerchunk`` are simple in this sense, but the spec allows for complex.
max_gap, max_block: int
    For merging multiple concurrent requests to the same remote file.
    Neighboring byte ranges will only be merged when their
    inter-range gap is <= ``max_gap``. Default is 64KB. Set to 0
    to only merge when it requires no extra bytes. Pass a negative
    number to disable merging, appropriate for local target files.
    Neighboring byte ranges will only be merged when the size of
    the aggregated range is <= ``max_block``. Default is 256MB.
cache_size : int
    Maximum size of LRU cache, where cache_size*record_size denotes
    the total number of references that can be loaded in memory at once.
    Only used for lazily loaded references.
kwargs : passed to parent class
rB   rbzRead reference from URL %sNz$Open lazy reference dict from URL %s)r   r}   :rb   r   ry   )asynchronouszDReference-FS's target filesystem must have same valueof asynchronousrX   )&r   r   r   template_overridessimple_templates	templatesfss	_dircachemax_gap	max_blockr5   r8   dictr   r   r   isfiler   loggerinforK   load_process_referencesrk   r:   r  r
   r   rB   r7   r/   callabler   r6   
async_implr   r  r   )r   for   ref_storage_argstarget_protocoltarget_optionsremote_protocolremote_optionsr   r  r  r  r  r}   r   dicref_fsfo2r   textre  optsr;   rB   r   r   s                            r   r   ReferenceFileSystem.__init__f  s   R 	"6""4 0"b# #;~;GVC !++//:c:KFC}}S!![[T1S1QKK <bA99Q<D 2 ((/AB BBG"5)# $$R<b$  "xxz  *GAt !$-- %%aggc1oa&8ADA
  *DH 488#!+F!3> #-R[[%"@"@Abkk  )+HH_%"~~,,.C==%C$kk88=!8 8#HG1E2GB)+HHX& / " --/C==%Cc4((SVV"(++"<"<SV"DKHatxx/'K^5IrK-/* 0 hh>OF0D"FB(*HH_%1z&1HHNN$DAq<<4QTEVEVW""Q^^33 & 	 % 21 s   -Q05AR0
Q?c           
      2   U R                  U5      n[        R                  SU 35         U R                  U   n[        U[        5      (       a  UR                  5       n[        US5      (       a  UR                  5       n[        U[        5      (       aM  [        R                  SU S35        UR                  S5      (       a  [        R                  " USS  5      nUS S 4$ [        U5      S:X  a#  [        R                  SU SU 35        US	   nX#pOTUu  pin
[        R                  SU S
U SU	 SU
 35        X-   nUb  US	:  a  X-   nOX-   nOU	nUb  US	:  a  X-   nOX-   nOUnUc  U R                   nXgU4$ ! [         a  n[        U5      UeS nAff = f)Nzcat: r(  zReference: z, type bytes   base64:   rb   z, whole file => r   z => z	, offset z, size )_strip_protocolr  debugr:   r   r   r5   r8   rM   r*  r(  r,  r   base64	b64decoderQ   r   )r   r9   startendpartr   r~   start1end1start0r   end0s               r   _cat_commonReferenceFileSystem._cat_common  s   ##D)uTF^$	3??4(D dC  ;;=D4$$==?DdE""LL;tfL9:z**''QR1t##t9>LL;tf,<TFCDq'C D $CLL;tfDYvhgdVTU=D A:#^F!\F!8!<D:D;++CD  K  	3#D)s2	3s   E; ;
FFFc                   #    U R                  XUS9u  pVn[        U[        5      (       a  XRU $ [        U5      u  p U R                  U   R                  XVUS9I S h  vN $  N! [         a  n
[        X5      U
eS n
A
ff = f7fN)r  r  )r  r5   r,  r   r  	_cat_file	Exceptionr   r   r9   r  r  r   part_or_urlr  r  rB   r   es              r   r  ReferenceFileSystem._cat_file3  s     $($4$4TC$4$P!Tk5))S))$[1	B(+55t 6      	B':A	Bs:   :B A$ A"A$ !B"A$ $
A?.A::A??Bc                     U R                  XUS9u  pVn[        U[        5      (       a  XRU $ [        U5      u  p U R                  U   R                  XVUS9$ ! [         a  n
[        X5      U
eS n
A
ff = fr  )r  r5   r,  r   r  r   r  r   r  s              r   r   ReferenceFileSystem.cat_file?  s    $($4$4TC$4$P!Tk5))S))$[1	B88H%..{d.SS 	B':A	Bs   A 
A3"A..A3c                      X R                   U'   g)z2Temporarily add binary data or reference as a fileNr:   )r   r9   r-  r   s       r   	pipe_fileReferenceFileSystem.pipe_fileI  s     %r   c                   #    U R                  U5      (       a  [        R                  " USS9$ U R                  U5      I S h  vN n[	        US5       nUR                  U5        S S S 5        g  N+! , (       d  f       g = f7fNTr   wb)isdirosr   r  r   r)  )r   rpathlpathr   r   r   s         r   	_get_fileReferenceFileSystem._get_fileM  s`     ::e;;ut44^^E**%!GGDM  +s*   A BA.BA0%
B0
A>:Bc                    U R                  U5      (       a  [        R                  " USS9$ U R                  " U40 UD6nUR	                  [        U5      5        [        U5      (       a  UR                  U5        O&[        US5       nUR                  U5        S S S 5        UR                  [        U5      5        g ! , (       d  f       N)= fr  )
r  r  r   r   set_sizerQ   r   r)  r   absolute_update)r   r  r  callbackr   r   r   s          r   get_fileReferenceFileSystem.get_fileT  s    ::e;;ut44}}U-f-#d)$eKKeT"a #  T+ #"s   B<<
C
c                    U(       a  U R                  S5        U R                  XS9n[        R                  " SSS9n[	        X5      nU(       a:  U R                  U Vs/ s H  opR                  U5      (       a  M  UPM     sn5      nOU R                  U5      n[        X5       H   u  pX;   d  M  UR                  XU	   5        M"     g s  snf )Nr   r   ry   T)
auto_mkdir)	r   expand_pathr   r
   r   catr  r^   r  )r   r  r  r   r   r   targetsrr   remotelocals              r   r4   ReferenceFileSystem.get`  s    GGBK   <v$7e+88C1ZZ]QCDD88E?D 0MF~UL1 1 Ds   C
;C
c           
      P   [        U[        5      (       a  U(       a  [        e[        U[        5      (       a$  U(       d  [	        S U 5       5      (       a  [        e[        XR                  5      n0 nUR                  5        GH  u  pxU R                  U   n	/ / / / 4u  ppU H{  n U R                  U5      u  nnn[        U[        [        45      (       d  M6   U
R                  U5        UR                  U5        UR                  U5        UR                  U5        M}     / n/ n/ n/ n[        5       n[        XX5       H}  u  nnnn[        U[        5      (       a  XU'   M#  Ub  M(  UR                  U5        UR                  U5        UR                  U5        UR                  U5        UR                  U5        M     [        XX5       HY  u  nnnnUc  M  UU;  d  M  UR                  U5        UR                  U5        UR                  U5        UR                  U5        M[     [!        [        U5      [        U5      [        U5      SU R"                  U R$                  S9u  nnnU	R'                  UUU5      n[        XX5       H  u  nnnnX;   a  M  [        UUUU5       H  u  nnnnUU:X  a*  Ub  Uc$  [        U[(        5      (       a  UXn'   M/  UUU Xn'   M8  UU:X  d  M@  UU:  d  MH  UU::  d  MP  [        U[(        5      (       a  UXn'   Mk  UUU-
  UU-
  =(       d    S  Xn'   M     M     GM     UR+                  5       R                  5        Hi  u  n n![        U![(        5      (       d  M  U U R                  ;   d  M/  UU    n"[-        U U R                  U    5      n#U"U#l        US:X  a  U#eUS:w  d  Md  U#UU '   Mk     [1        U5      S:X  a&  [        U[        5      (       a  SU;  a  [3        U5      $ U$ ! [         a$  nUS:X  a  e US:w  a  UXn'    S nAGMv   S nAGM}  S nAff = f)Nc              3   ,   #    U  H
  nS U;   v   M     g7f)*NrX   r   s     r   r   *ReferenceFileSystem.cat.<locals>.<genexpr>r  s     7O$Qq$   raiseomitT)sortr  r  rb   r  )r5   r8   rS  r6   anyrC   r:   r  r  r  r,  r?   r   r   r^   addr   r  r  
cat_rangesr  r>  r   	__cause__rQ   r1   )$r   r9   r   on_errorr   
proto_dictrA   protor@   r   urlsstartsendsvalid_pathsr   urh   r  errurls2starts2ends2paths2whole_files	new_paths
new_startsnew_ends	bytes_outro   nsnebre  vexnew_exs$                                       r   r  ReferenceFileSystem.cato  s   dC  Y%%dD!!yC7O$7O4O4O%%%dOO<
&,,.LE%B.0"b"n+D$*"..q1GAq!%a%66  7 KKNMM!$KKN&&q)# ( EGEF%K!$B
1aa''FY  OOA&LLONN1%LLOMM!$ C "$B
1a=Qk%9LLONN1%LLOMM!$ C /BUWU../+Iz8 iXFI "$B
1a8%(J)%TMBBQwBJ"*%a33%&CF%&qVCFqQ"Wb%a33%&CF%&q2vR0@D%ACF &U Cy /V HHJ$$&DAq!Y''A,@V.q$//!2DE#% w& L'#CF ' s8q=Zc22s$#;
[ ) %7*6)!$ *%s   '0O77
P%P  P%c                     UR                  SS 5      nUc  U R                  U5        g US:X  a  U R                  XS9  g [        SU 35      e)Nversionrb   )r  z Unknown reference spec version: )r4   _process_references0_process_references1r   )r   r:   r  verss       r   r  'ReferenceFileSystem._process_references  sP    ~~i.<%%j1QY%%j%X?vFGGr   c           	          [        U[        5      (       aP  UR                  5        VVs0 s H3  u  p#U[        U[        5      (       a  [        R                  " U5      OU_M5     nnnXl        gs  snnf )z&Make reference dict for Spec Version 0N)r5   r  r  rK   rL   r:   )r   r:   r   rS   s       r   r  (ReferenceFileSystem._process_references0  sc    j$''
 !+ 0 0 2 2HC 
3(=(=TZZ_3F 2   %	s   :A-c                 *  ^ ^ T R                   (       a  T R                  (       a  SS Km0 T l        T R	                  UR                  S0 5      5        [        S5      UU 4S j5       nUR                  S0 5      R                  5        GHO  u  pE[        U[        5      (       aM  UR                  S5      (       a&  [        R                  " USS  5      T R                  U'   UT R                  U'   Mh  [        U[        5      (       a%  [        R                  " U5      T R                  U'   M  T R                  (       a  US   nSU;   aV  T R                   (       a=  UR!                  SS	5      R!                  S
S5      R"                  " S0 T R                  D6nOU" U5      n[%        U5      S:X  a  U/O	XeS   US   /T R                  U'   GM@  UT R                  U'   GMR     T R                  R'                  T R)                  UR                  S/ 5      5      5        g )Nr   r  i  c                 Z   > TR                  U 5      R                  " S0 TR                  D6$ NrX   )Templaterenderr  )r  jinja2r   s    r   _render_jinja?ReferenceFileSystem._process_references1.<locals>._render_jinja  s$    ??1%,,>t~~>>r   r   zbase64:r  {{{z}}}rb   r=  genrX   )r  r  r  r:   _process_templatesr4   r   r  r5   r8   r   r  r  r  rK   rL   replacer   rQ   r   _process_gen)r   r:   r  r  re  r  r  r  s   `      @r   r  (ReferenceFileSystem._process_references1  s   $$
{B ?@	4	? 
	? NN62.446DA!S!!<<	**)/)9)9!AB%)@DOOA&%&"At$$%)ZZ]"aD19,,IIdC0$WT3/#V$ 6&*nn6  *!,,/FaKaSa1qt_"%&") 7* 	t00r1JKLr   c                    ^ 0 U l         U R                  b  UR                  U R                  5        UR                  5        H5  u  p#SU;   a  SS KmU4U4S jjU R                   U'   M'  X0R                   U'   M7     g )Nr  r   c                 F   > TR                  U 5      R                  " S0 UD6$ r
  )r  r  )tempr   r  s     r   r   8ReferenceFileSystem._process_templates.<locals>.<lambda>  s(    V__>&> >#!>#r   )r  r  r   r  r  )r   tmpre  r  r  s       @r   r  &ReferenceFileSystem._process_templates  se    "".JJt../IIKDAqy01 %#q! %&q!  r   c                   ^ 0 nU GH  nUS   R                  5        VVs0 s HM  u  pEU[        U[        5      (       a  UO/[        UR	                  SS5      US   UR	                  SS5      5      _MO     snnmU4S j[
        R                  " TR                  5       6  5       nU GH  nSS KnUR                  US   5      R                  " S0 UDU R                  D6n	UR                  US	   5      R                  " S0 UDU R                  D6n
S
U;   a  SU;   az  [        UR                  US
   5      R                  " S0 UDU R                  D65      n[        UR                  US   5      R                  " S0 UDU R                  D65      nXU/X)'   M  S
U;   SU;   -  (       a  [        S5      eU
/X)'   GM     GM     U$ s  snnf )N
dimensionsr  r   stopsteprb   c              3   j   >#    U  H(  n[        [        TR                  5       U5      5      v   M*     g 7fr   )r  r^   r_   )r   r/   	dimensions     r   r   3ReferenceFileSystem._process_gen.<locals>.<genexpr>!  s.      DF S)6233Ds   03r   r~   r   lengthz^Both 'offset' and 'length' are required for a reference generator entry if either is provided.rX   )r  r5   r6   r  r4   ry  rz  r/   r  r  r  r  r   r   )r   gensrA   r  re  r  productsprr  r   r~   r   r%  r#  s                @r   r   ReferenceFileSystem._process_gen  s   C  -335 6DA !!T** quuWa0!F)QUU61=MNO
 6I'//1A1A1CDH ooc%j188P2PPooc%j188P2PPO(c/ H6==UUdnnUF !H6==UUdnnUF !$V4CH#o(c/:$K 
 !$uCH'  B 
As   AF?c                    S/ 0U l         U R                  R                  5       nU GHc  u  p#[        U[        [
        45      (       d  [        US5      (       a  [        U5      nO[        U5      S:X  a  S nOUu    pTSU;   a  UR                  SS5      S   OSnUnU/nU(       aI  XpR                   ;  a:  U R                  U5      nUR                  U5        U(       a  XpR                   ;  a  M:  UR                  5         [        XSS  5       HX  u  pXR                   ;  d   eXR                   ;   d   eU R                   U	   R                  U
SSS.5        / U R                   U
'   MZ     U R                   U   R                  USUS.5        GMf     g )	Nr   r(  rb   r   r   r   r   ry   )dircacher:   r  r5   r,  r8   r*  rQ   r   _parentr?   reverser^   )r   r  r9   r  r   r   parpar0subdirsparentchilds              r   _dircache_from_items(ReferenceFileSystem._dircache_from_items;  s[   R__""$JD$--z1J1J4yTa!
1,/4K$++c1%a(RCDfG4}}4||D)t$ 4}}4
 OO!$Wabk!:MM111...f%,,"KC (*e$ "; MM#%%tVT&RS3 r   c                    U R                  U5      u  pgn[        U[        5      (       a  [        R                  " XgU 5      $ [        U5      u  pUc'  Uc$  U R                  U	   R                  " UU4UUS.UD6$ [        U UU4UUS.UD6$ )N)
block_sizecache_options)	r  r5   r,  r   r   r   r  _openReferenceFile)r   r9   moder6  r7  r   r  r  r  rB   r   s              r   r8  ReferenceFileSystem._openY  s    $($4$4T$:!T k5))::k677$[1>dl88H%++ &+	
   
 "'
 
 	
r   c                    [         R                  SU5        U R                  U5      n[        U R                  [
        5      (       a   U R                  R                  X5      $ U R                  (       d  U R                  5         U R                  U5      nUc  [        U5      eU(       a  U$ U Vs/ s H  oUS   PM	     sn$ ! [         a     Of = f[        SU S35      es  snf )Nzlist %s'z' is not a known keyr   )r  r  r  r5   r:   rk   r   r   r   r+  r3  _ls_from_cache)r   r9   r   r   rA   os         r   r   ReferenceFileSystem.lss  s    Y%##D)doo':;;))$77 }}%%'!!$';#D))J#&'3a&	3''  #av-A$BCC (s   C 0C 
CCc                 T    U R                  U5      =(       d    U R                  U5      $ r   )r  r  r   r9   r   s      r   r   ReferenceFileSystem.exists  s    zz$44;;t#44r   c                    ^ U R                   (       a  TU R                   ;   $ [        U R                  [        5      (       a  TU R                  R	                  5       ;   $ [        U4S jU R                   5       5      $ )Nc              3   J   >#    U  H  oR                  T S 35      v   M     g7f)r   Nr3  )r   r   r9   s     r   r   ,ReferenceFileSystem.isdir.<locals>.<genexpr>  s!     IA||tfAJ//s    #)r+  r5   r:   rk   rO   r  r   r9   s    `r   r  ReferenceFileSystem.isdir  sZ    ==4==(()<==4??22444 IIIIr   c                     XR                   ;   $ r   r  rG  s     r   r  ReferenceFileSystem.isfile  s    &&r   c                 0   #    U R                   " X40 UD6$ 7fr   )r   )r   r9   r   r   s       r   _lsReferenceFileSystem._ls  s     wwt.v..s   c                 ~  >^ U(       a  [         TU ]  " T4X#US.UD6$ T(       a1  U R                  T5      m[        U4S jU R                   5       5      nO[        U R                  5      nU(       aF  U R
                  (       d  U R                  5         U Vs0 s H  owU R                  U5      S   _M     sn$ U$ s  snf )N)maxdepthwithdirsr   c              3   V   >#    U  H  oR                  T5      (       d  M  Uv   M      g 7fr   r3  )r   re  r9   s     r   r   +ReferenceFileSystem.find.<locals>.<genexpr>  s     H/Q\\$5Gqq/s   )	)r   )r   findr  r   r:   r+  r3  r>  )	r   r9   rO  rP  r   r   r  re  r   s	    `      r   rS  ReferenceFileSystem.find  s    7<'6MS  ''-DH$//HHAt'A==))+:;<!Qt**1-a00!<<H =s   B:c                    U R                   R                  U5      nUbJ  [        U[        [        45      (       a  US[        U5      S.$ [        U5      S:  a	  USUS   S.$ USS S./nO;U R                  US5      nU Vs/ s H  oUS   U:X  d  M  UPM     nnU(       d  USSS.$ US   S	   cQ  [        U R                   U   S   5      u  pgU R                  U   R                  U R                   U   S   5      US   S	'   US   $ s  snf )
Nry   r   rb   r=  Tr   r   r   r   )
r:   r4   r5   r8   r,  rQ   r   r   r  r   )r   r9   r   rA   out0r?  protr   s           r   r  ReferenceFileSystem.info  s	   oo!!$'?#U|,, $fc#hGGSA $fc!fEE!%vtDE''$%C"8s!i4&7AsD8 $k1EE76?"$T__T%:1%=>GD"hhtn11$//$2G2JKDGFOAw 9s   ?DDc                 ,   #    U R                  U5      $ 7fr   )r  rB  s      r   _infoReferenceFileSystem._info  s     yyr  c                 x   #    U R                   R                  US 5        U R                  R                  5         g 7fr   )r:   rW  r+  rV  rB  s      r   _rm_fileReferenceFileSystem._rm_file  s.     $	
 	s   8:c                    #    US:X  a  U R                  U5      (       a  [        eX R                  U'   U R                  R	                  5         g 7f)Nr   )r   FileExistsErrorr:   r+  rV  )r   r9   r   r:  r   s        r   
_pipe_fileReferenceFileSystem._pipe_file  s=     8D 1 1!! $s   AAc                 
  #    US:X  a  U R                  U5      (       a  [        e[        US5       nUR                  5       U R                  U'   S S S 5        U R
                  R                  5         g ! , (       d  f       N)= f7f)Nr   r  )r   r`  r   readr:   r+  rV  )r   r  r  r:  r   r   s         r   	_put_fileReferenceFileSystem._put_file  s^     8E 2 2!!%!%&VVXDOOE"  s   /BA2#B2
B <Bc                    0 nU R                   R                  5        H4  u  pE[        U[        5      (       a   UR	                  S5      X4'   M0  XSU'   M6     [        R                  " US40 UD6 nUR                  [        R                  " SUS.5      R                  5       5        SSS5        g! [
         a-    S[        R                  " U5      -   R	                  5       X4'    M  f = f! , (       d  f       g= f)z+Write modified references into new locationasciir  r  rb   )r  r   N)r:   r  r5   r,  r+  UnicodeDecodeErrorr  	b64encoder   r   r)  rK   rL   rM   )r   r~   r   rA   re  r  r   s          r   	save_jsonReferenceFileSystem.save_json  s    OO))+DA!U##IXXg.CF A , [[d6o6!GGDJJ1c:;BBDE 76	 * I(6+;+;A+>>FFHCFI 76s   B--7C'-3C$#C$'
C5)
r  r+  r  r  r  r:   r  r   r  r  )NNNNNNNNTi   i @Br~  r  )F)Fr  r   )r  NN)T)NFF)	overwrite)&r%   r&   r'   r(   r  rB   cachabler   r  r  r   r  r  r	   r  r4   r  r  r  r  r  r  r3  r8  r   r   r  r  rL  rS  r  rZ  r]  ra  re  rk  r)   r*   r+   s   @r   r  r  T  s     HH
 _B*!X
BB& /? 
,2`DH	%MB&#JT<
4($5J'/"*F Fr   r  c                   Z   ^  \ rS rSr      SU 4S jjr\S 5       rU 4S jrS rSr	U =r
$ )r9  i  c	           
        > [         TU ]  " UU4UUUUUUS.U	D6  U R                  R                  U R                  5      u  ol        U l        [        U
5      u  pU R                  R                  U   U l	        Xl
        S U l        g )N)r:  r6  
autocommitr   
cache_typer7  )r   r   r   r  r9   r  r  r   r  src_fssrc_path_f)r   r   r9   r:  r6  rq  rr  r7  r   r   r  rB   r   r   s                r   r   ReferenceFile.__init__  s     	
	
 !!!'
	
 
	
 -1GG,?,?		,J)Z$[1ggkk(+#r   c                    U R                   b  U R                   R                  (       aY  U R                  R                  " U R                  4U R
                  U R                  U R                  SS.U R                  D6U l         U R                   $ )Nnone)r:  r6  rq  rr  )	ru  closedrs  r8  rt  r:  	blocksizerq  r   r"   s    r   r   ReferenceFile.f  sh    77?dggnnkk''YY>>??! ++DG wwr   c                 n   > U R                   b  U R                   R                  5         [        TU ]  5       $ r   )ru  closer   )r   r   s    r   r}  ReferenceFile.close  s&    77GGMMOw}r   c                     XR                   -   n[        X R                   -   U R                  5      nU R                  R	                  U5        U R                  R                  X!-
  5      $ r   )r  minr  r   seekrd  )r   r  r  s      r   _fetch_rangeReferenceFile._fetch_range  sJ    

"#

"DHH-Evv{{3;''r   )ru  r  rs  rt  r  )r  defaultT	readaheadNN)r%   r&   r'   r(   r   r  r   r}  r  r)   r*   r+   s   @r   r9  r9    s?    
 : 
 

( (r   r9  )2r  collectionsr   ry  loggingr  r  	functoolsr   r   typingr   r   fsspec.corer   fsspec.specr   ujsonrK   r   fsspec.asynr   fsspec.callbacksr	   r
   r   r   #fsspec.implementations.asyn_wrapperr   fsspec.utilsr   r   r   	getLoggerr  RuntimeErrorr   r1   r<   rC   abc
ValuesViewrE   	ItemsViewr[   ri   MutableMappingrk   r  r9  rX   r   r   <module>r     s      	    	   )  ,
 ( - 8 8 F E E			-	.TL T"?
B[__// 
BAKOO-- A
z@+//88 z@zN
F/ N
Fb4(( 4(i&  s   D DD