
    7Th!                         S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJrJ	r	  S SK
Jr  S SKJr  S SKJrJrJrJr  S rSq " S S	\5      r\" S
/ SQ5       " S S\R,                  5      5       r " S S\5      rg)    N)suppress)cached_propertywraps)parse_qs)AbstractFileSystem)"get_package_version_without_importinfer_storage_optionsmirror_fromtokenizec                 0   ^  [        T 5      U 4S j5       nU$ )Nc                     >  T" U 0 UD6$ ! [          a[  nUR                  (       d  e UR                  tp0[        U[        5      (       a!  SU;   a  [	        [
        R                  U5      Uee S nAff = f)Nzdoes not exist)OSErrorargs
isinstancestrFileNotFoundErrorerrnoENOENT)r   kwargs	exceptionmessagefuncs       T/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/arrow.pywrapper wrap_exceptions.<locals>.wrapper   sh    
	((( 	>>&^^NG'3'',<,G'g>IM	s    
A0AA++A0)r   )r   r   s   ` r   wrap_exceptionsr      s     
4[  N    c                   8  ^  \ rS rSrSrSrU 4S jr\S 5       r\	S 5       r
\S 5       rSS jrS	 rS
 rS r\S 5       r\S 5       r\S 5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\S 5       r\S 5       rSU 4S jjrU 4S jrSrU =r$ )ArrowFSWrapper(   zgFSSpec-compatible wrapper of pyarrow.fs.FileSystem.

Parameters
----------
fs : pyarrow.fs.FileSystem

/c                 H   > [        S5      qXl        [        TU ]  " S0 UD6  g )Npyarrow )r   PYARROW_VERSIONfssuper__init__)selfr&   r   	__class__s      r   r(   ArrowFSWrapper.__init__3   s"    <YG"6"r   c                 .    U R                   R                  $ N)r&   	type_namer)   s    r   protocolArrowFSWrapper.protocol9   s    ww   r   c                 p    S[        U R                  R                  U R                  R                  5      -   $ )Nhdfs_)r   r&   hostportr/   s    r   fsidArrowFSWrapper.fsid=   s$    $'',,===r   c                 \    [        U5      nUS   nUR                  S5      (       a  USS  nU$ )Npathz//   )r	   
startswith)clsr9   opss      r   _strip_protocolArrowFSWrapper._strip_protocolA   s4    #D)6{??4  8Dr   c                     U R                  U5      nSSKJn  U R                  R	                  U" U5      5       Vs/ s H  nU R                  U5      PM     nnU(       a  U$ U Vs/ s H  oUS   PM	     sn$ s  snf s  snf )Nr   )FileSelectorname)r>   
pyarrow.fsrA   r&   get_file_info_make_entry)r)   r9   detailr   rA   entryentriess          r   lsArrowFSWrapper.lsJ   s    ##D)+ ..|D/AB
B U#B 	 
 N/67we&Mw77
 8s   A6%A;c                     U R                  U5      nU R                  R                  U/5      u  nU R                  U5      $ r-   )r>   r&   rD   rE   )r)   r9   r   infos       r   rL   ArrowFSWrapper.infoW   s;    ##D)&&v.%%r   c                 j    U R                  U5      n U R                  U5        g! [         a     gf = f)NTF)r>   rL   r   r)   r9   s     r   existsArrowFSWrapper.exists\   s;    ##D)	IIdO  ! 		s   % 
22c                    SSK Jn  UR                  UR                  L a  SnO~UR                  UR                  L a  SnObUR                  UR
                  L aG  [        [        R                  [        R                  " [        R                  5      UR                  5      eSnUR                  UR                  UUR                  S.$ )Nr   )FileType	directoryfileother)rB   sizetypemtime)rC   rS   rX   	DirectoryFileNotFoundr   r   r   osstrerrorr9   rW   rY   )r)   rL   rS   kinds       r   rE   ArrowFSWrapper._make_entrye   s    '99***DYY(--'DYY(+++#ELL"++ell2KTYYWWD IIIIZZ	
 	
r   c                 v   U R                  U5      R                  S5      nU R                  U5      R                  S5      nU R                  US5       nU S[        R                  " S5       3n U R                  US5       n[        R                  " XF5        S S S 5        U R                  R                  XR5         S S S 5        g ! , (       d  f       N3= f! [         aF    [        [        5         U R                  R                  U5        S S S 5        e ! , (       d  f       e = ff = f! , (       d  f       g = f)Nr!   rbz.tmp.   wb)r>   rstrip_opensecrets	token_hexopenshutilcopyfileobjr&   moveBaseExceptionr   r   delete_file)r)   path1path2r   lstream	tmp_fnamerstreams          r   cp_fileArrowFSWrapper.cp_filex   s    $$U+2237$$U+2237ZZt$ 'w'8'8';&<=IYYy$/7&&w8 0Y. %$ 0/ ! /0GG''	2 1 10 %$sN   D*0CC#C
C	CD'0D	D'
D#D''D**
D8c                     U R                  U5      R                  S5      nU R                  U5      R                  S5      nU R                  R                  X5        g )Nr!   )r>   re   r&   rl   )r)   ro   rp   r   s       r   mvArrowFSWrapper.mv   sH    $$U+2237$$U+2237U"r   c                 \    U R                  U5      nU R                  R                  U5        g r-   )r>   r&   rn   rO   s     r   rm_fileArrowFSWrapper.rm_file   s$    ##D)D!r   c                    U R                  U5      R                  S5      nU R                  U5      (       a.  U(       a  U R                  R	                  U5        g [        S5      eU R                  R                  U5        g )Nr!   z0Can't delete directories without recursive=False)r>   re   isdirr&   
delete_dir
ValueErrorrn   )r)   r9   	recursivemaxdepths       r   rmArrowFSWrapper.rm   s_    ##D)005::d""4( !STTGG%r   c                    US:X  a5  U(       a  U R                   R                  nO`U R                   R                  nOIUS:X  a  U R                   R                  nO,US:X  a  U R                   R                  nO[        SU< 35      e0 nUS:w  d  U(       d*  [        [        R                  S5      S   5      S:  a  S US'   U" U40 UD6n[        XXU40 UD6$ )	Nrb   rd   abz'unsupported mode for Arrow filesystem: .r      compression)
r&   open_input_fileopen_input_streamopen_output_streamopen_append_streamr   intr%   split	ArrowFile)	r)   r9   mode
block_sizeseekabler   method_kwargsstreams	            r   rf   ArrowFSWrapper._open   s    4<0022T\WW//FT\WW//FFthOPP4<x?((-a01Q6)-&((t:HHHr   c                     U R                  U5      nU(       a  U R                  USS9  g U R                  R                  USS9  g )NT)exist_okFr   )r>   makedirsr&   
create_dir)r)   r9   create_parentsr   s       r   mkdirArrowFSWrapper.mkdir   s<    ##D)MM$M.GGtu5r   c                 Z    U R                  U5      nU R                  R                  USS9  g )NTr   )r>   r&   r   )r)   r9   r   s      r   r   ArrowFSWrapper.makedirs   s)    ##D)440r   c                 \    U R                  U5      nU R                  R                  U5        g r-   )r>   r&   r~   rO   s     r   rmdirArrowFSWrapper.rmdir   s$    ##D)4 r   c                 n    U R                  U5      nU R                  R                  U5      R                  $ r-   )r>   r&   rD   rY   rO   s     r   modifiedArrowFSWrapper.modified   s-    ##D)ww$$T*000r   c                 <   > US;  US'   [         TU ]  " U4S S S.UD6$ )N)Nr   r   )startend)r'   cat_file)r)   r9   r   r   r   r*   s        r   r   ArrowFSWrapper.cat_file   s.    ")3zwEDdEfEEr   c                 2   > SUS'   [         TU ]  " X40 UD6  g )NFr   )r'   get_file)r)   rpathlpathr   r*   s       r   r   ArrowFSWrapper.get_file   s    "z00r   )r&   )F)FN)rb   NT)T)NN)__name__
__module____qualname____firstlineno____doc__root_markerr(   propertyr0   r   r6   classmethodr>   rI   rL   rP   rE   r   rt   rw   rz   r   rf   r   r   r   r   r   r   __static_attributes____classcell__r*   s   @r   r   r   (   s*    K# ! ! > >  8&

&   # #
 " " & & I I, 6 6 1 1 ! ! 1 1F1 1r   r   r   )	readseektellwritereadablewritablecloserW   r   c                   *    \ rS rSrSS jrS rS rSrg)r      Nc                 \    X0l         X@l        Xl        X l        U=U l        U l        X`l        g r-   )r9   r   r&   r   	blocksizer   r   )r)   r&   r   r9   r   r   r   s          r   r(   ArrowFile.__init__   s)    		+55r   c                     U $ r-   r$   r/   s    r   	__enter__ArrowFile.__enter__   s    r   c                 "    U R                  5       $ r-   )r   )r)   r   s     r   __exit__ArrowFile.__exit__   s    zz|r   )r   r   r&   r   r   r9   r   r-   )r   r   r   r   r(   r   r   r   r$   r   r   r   r      s    r   r   c                   P   ^  \ rS rSrSrSr      SU 4S jjr\S 5       rSr	U =r
$ )HadoopFileSystem   zYA wrapper on top of the pyarrow.fs.HadoopFileSystem
to connect it's interface with fsspechdfsc           	      L   > SSK Jn  U" UUUUUUS9n	[        T
U ]  " SSU	0UD6  g)a  

Parameters
----------
host: str
    Hostname, IP or "default" to try to read from Hadoop config
port: int
    Port to connect on, or default from Hadoop config if 0
user: str or None
    If given, connect as this username
kerb_ticket: str or None
    If given, use this ticket for authentication
replication: int
    set replication factor of file for write operations. default value is 3.
extra_conf: None or dict
    Passed on to HadoopFileSystem
r   )r   )r4   r5   userkerb_ticketreplication
extra_confr&   Nr$   )rC   r   r'   r(   )r)   r4   r5   r   r   r   r   r   r   r&   r*   s             r   r(   HadoopFileSystem.__init__   s;    6 	0##!
 	)B)&)r   c                 z   [        U 5      n0 nUR                  SS 5      (       a  US   US'   UR                  SS 5      (       a  US   US'   UR                  SS 5      (       a  US   US'   UR                  SS 5      (       a9  [        US   5      nUR                  SS 5      (       a  [        US   S   5      US'   U$ )Nr4   usernamer   r5   	url_queryr   r   )r	   getr   r   )r9   r=   outqueriess       r   _get_kwargs_from_urls&HadoopFileSystem._get_kwargs_from_urls"  s    #D)7764  f+CK77:t$$j/CK7764  f+CK77;%%s;/0G{{=$//%()?)B%CM"
r   r$   )defaultr   NN   N)r   r   r   r   r   r0   r(   staticmethodr   r   r   r   s   @r   r   r      s=    - H %*N  r   r   )r   ior]   rg   rj   
contextlibr   	functoolsr   r   urllib.parser   fsspec.specr   fsspec.utilsr   r	   r
   r   r   r%   r   IOBaser   r   r$   r   r   <module>r      s~     	 	    , ! * $ j1' j1Z 
		 $;~ ;r   