
    "h0                          d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZmZ d Zda G d de      Z ed	g d
       G d dej(                               Z G d de      Zy)    N)suppress)cached_propertywraps)AbstractFileSystem)"get_package_version_without_importinfer_storage_optionsmirror_fromtokenizec                 .     t                fd       }|S )Nc                      	  | i |S # t         $ rP}|j                  s |j                  ^}} t        |t              rd|v rt	        t
        j                  |      | d }~ww xY w)Nzdoes not exist)OSErrorargs
isinstancestrFileNotFoundErrorerrnoENOENT)r   kwargs	exceptionmessagefuncs       Y/var/www/html/sandstorm/venv/lib/python3.12/site-packages/fsspec/implementations/arrow.pywrapperz wrap_exceptions.<locals>.wrapper   sg    
	((( 	>>&^^NGd'3',<,G'g>IM	s    	A$AAA$)r   )r   r   s   ` r   wrap_exceptionsr      s     
4[  N    c                   "    e Zd ZdZdZ fdZed        Zed        Z	e
d        ZddZd Zd	 Zd
 Zed        Zed        ZeZed        Zedd       Zedd       Zedd       Zedd       Zed        Zed        Zd fd	Z fdZ xZS )ArrowFSWrapperzwFSSpec-compatible wrapper of pyarrow.fs.FileSystem.

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

    /c                 H    t        d      a|| _        t        |   di | y )Npyarrow )r   PYARROW_VERSIONfssuper__init__)selfr#   r   	__class__s      r   r%   zArrowFSWrapper.__init__2   s$    <YG"6"r   c                 .    | j                   j                  S N)r#   	type_namer&   s    r   protocolzArrowFSWrapper.protocol8   s    ww   r   c                 p    dt        | j                  j                  | j                  j                        z   S )Nhdfs_)r
   r#   hostportr+   s    r   fsidzArrowFSWrapper.fsid<   s$    $'',,===r   c                 R    t        |      }|d   }|j                  d      r|dd  }|S )Npathz//   )r   
startswith)clsr3   opss      r   _strip_protocolzArrowFSWrapper._strip_protocol@   s1    #D)6{??4 8Dr   c                     | j                  |      }ddlm} | j                  j	                   ||            D cg c]  }| j                  |       }}|r|S |D cg c]  }|d   	 c}S c c}w c c}w )Nr   )FileSelectorname)r8   
pyarrow.fsr:   r#   get_file_info_make_entry)r&   r3   detailr   r:   entryentriess          r   lszArrowFSWrapper.lsI   s|    ##D)+ ..|D/AB
 U#
 
 N/67eE&M77
 8s   A,A1c                     | j                  |      }| j                  j                  |g      \  }| j                  |      S r)   )r8   r#   r=   r>   )r&   r3   r   infos       r   rD   zArrowFSWrapper.infoV   s;    ##D)&&v.%%r   c                 h    | j                  |      }	 | j                  |       y# t        $ r Y yw xY w)NTF)r8   rD   r   r&   r3   s     r   existszArrowFSWrapper.exists[   s;    ##D)	IIdO  ! 		s   % 	11c                    ddl m} |j                  |j                  u rd}n{|j                  |j                  u rd}n`|j                  |j
                  u rFt        t        j                  t        j                  t        j                        |j                        d}|j                  |j                  ||j                  dS )Nr   )FileType	directoryfileother)r;   sizetypemtime)r<   rI   rN   	DirectoryFileNotFoundr   r   r   osstrerrorr3   rM   rO   )r&   rD   rI   kinds       r   r>   zArrowFSWrapper._make_entryd   s    '99***DYY(--'DYY(+++#ELL"++ell2KTYYWWD IIIIZZ	
 	
r   c                 V   | j                  |      j                  d      }| j                  |      j                  d      }| j                  |d      5 }| dt        j                  d       }	 | j                  |d      5 }t        j                  ||       d d d        | j                  j                  ||       	 d d d        y # 1 sw Y   /xY w# t        $ rA t        t              5  | j                  j                  |       d d d         # 1 sw Y    xY ww xY w# 1 sw Y   y xY w)Nr   rbz.tmp.   wb)r8   rstrip_opensecrets	token_hexopenshutilcopyfileobjr#   moveBaseExceptionr   r   delete_file)r&   path1path2r   lstream	tmp_fnamerstreams          r   cp_filezArrowFSWrapper.cp_filew   s   $$U+2237$$U+2237ZZt$ 		 'w'8'8';&<=IYYy$/ 97&&w89Y.		 		9 9 ! /0 3GG''	233		 		sN   D/CC$CC	CD*D	DDDDD(c                     | j                  |      j                  d      }| j                  |      j                  d      }| j                  j                  ||       y )Nr   )r8   rZ   r#   ra   )r&   rd   re   r   s       r   mvzArrowFSWrapper.mv   sJ    $$U+2237$$U+2237UE"r   c                 \    | j                  |      }| j                  j                  |       y r)   )r8   r#   rc   rF   s     r   rm_filezArrowFSWrapper.rm_file   s$    ##D)D!r   c                     | j                  |      j                  d      }| j                  |      r)|r| j                  j	                  |       y t        d      | j                  j                  |       y )Nr   z0Can't delete directories without recursive=False)r8   rZ   isdirr#   
delete_dir
ValueErrorrc   )r&   r3   	recursivemaxdepths       r   rmzArrowFSWrapper.rm   s\    ##D)005::d""4( !STTGG%r   c                    |dk(  r0|r| j                   j                  }n]| j                   j                  }nF|dk(  r| j                   j                  }n*|dk(  r| j                   j                  }nt        d|      i }|dk7  s|s)t        t        j                  d      d         dk\  rd |d<    ||fi |}t        | ||||fi |S )	NrW   rY   abz'unsupported mode for Arrow filesystem: .r      compression)
r#   open_input_fileopen_input_streamopen_output_streamopen_append_streamrq   intr"   split	ArrowFile)	r&   r3   mode
block_sizeseekabler   method_kwargsstreams	            r   r[   zArrowFSWrapper._open   s    4<0022T\WW//FT\WW//FFthOPP4<x?((-a01Q6)-&((vtT:HHHr   c                     | j                  |      }|r| j                  |d       y | j                  j                  |d       y )NT)exist_okFrr   )r8   makedirsr#   
create_dir)r&   r3   create_parentsr   s       r   mkdirzArrowFSWrapper.mkdir   s<    ##D)MM$M.GGtu5r   c                 `    | j                  |      }| j                  j                  |d       y )NTr   )r8   r#   r   )r&   r3   r   s      r   r   zArrowFSWrapper.makedirs   s)    ##D)440r   c                 \    | j                  |      }| j                  j                  |       y r)   )r8   r#   rp   rF   s     r   rmdirzArrowFSWrapper.rmdir   s$    ##D)4 r   c                 n    | j                  |      }| j                  j                  |      j                  S r)   )r8   r#   r=   rO   rF   s     r   modifiedzArrowFSWrapper.modified   s-    ##D)ww$$T*000r   c                 8    |dv|d<   t        |   |fd d d|S )N)Nr   r   )startend)r$   cat_file)r&   r3   r   r   r   r'   s        r   r   zArrowFSWrapper.cat_file   s.    ")3zwEDdEfEEr   c                 2    d|d<   t        |   ||fi | y )NFr   )r$   get_file)r&   rpathlpathr   r'   s       r   r   zArrowFSWrapper.get_file   s!    "z00r   )F)FN)rW   NT)T)NN)__name__
__module____qualname____doc__root_markerr%   propertyr,   r   r1   classmethodr8   rB   rD   rG   r>   r   ri   rk   mv_filerm   rt   r[   r   r   r   r   r   r   __classcell__r'   s   @r   r   r   '   s/    K# ! ! > >  8&

&   # #
 G" " & & I I, 6 6 1 1 ! ! 1 1F1 1r   r   r   )	readseektellwritereadablewritablecloserM   r   c                        e Zd ZddZd Zd Zy)r   Nc                 f    || _         || _        || _        || _        |x| _        | _        || _        y r)   )r3   r   r#   r   	blocksizer   r   )r&   r#   r   r3   r   r   r   s          r   r%   zArrowFile.__init__   s3    		+55r   c                     | S r)   r!   r+   s    r   	__enter__zArrowFile.__enter__   s    r   c                 "    | j                         S r)   )r   )r&   r   s     r   __exit__zArrowFile.__exit__   s    zz|r   r)   )r   r   r   r%   r   r   r!   r   r   r   r      s    r   r   c                   B     e Zd ZdZdZ	 	 	 	 	 d fd	Zed        Z xZS )HadoopFileSystemz]A wrapper on top of the pyarrow.fs.HadoopFileSystem
    to connect it's interface with fsspechdfsc                 N    ddl m}  ||||||      }t        	|   dd|i| y)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
        extra_conf: None or dict
            Passed on to HadoopFileSystem
        r   )r   )r/   r0   userkerb_ticket
extra_confr#   Nr!   )r<   r   r$   r%   )
r&   r/   r0   r   r   r   r   r   r#   r'   s
            r   r%   zHadoopFileSystem.__init__   s8    0 	0#!
 	)B)&)r   c                     t        |       }i }|j                  dd       r|d   |d<   |j                  dd       r|d   |d<   |j                  dd       r|d   |d<   |S )Nr/   usernamer   r0   )r   get)r3   r7   outs      r   _get_kwargs_from_urlsz&HadoopFileSystem._get_kwargs_from_urls  sg    #D)7764 f+CK77:t$j/CK7764 f+CK
r   )defaultr   NNN)	r   r   r   r   r,   r%   staticmethodr   r   r   s   @r   r   r      s:    - H !*F 	 	r   r   )r   iorS   r\   r_   
contextlibr   	functoolsr   r   fsspec.specr   fsspec.utilsr   r   r	   r
   r   r"   r   IOBaser   r   r!   r   r   <module>r      s{     	 	    , * $ l1' l1^ 
		 $3~ 3r   