
    \jx                         d Z ddlZddlZddlZddlZddlmZ  ej                  e	      Z
dZdZd Zd Zd Z G d	 d
ej                         Z G d dej                         Zy)z,Implements reading and writing to/from HDFS.    N)utils)hdfsviewfs)zhdfs:///path/filezhdfs://path/filezviewfs:///path/filezviewfs://path/filec                    t         j                  j                  |       }|j                  t        v sJ |j
                  |j                  z   }d|j                  d      z   }|st        d| z        t        |j                  |      S )N/zinvalid HDFS URI: %r)schemeuri_path)
urllibparseurlsplitr   SCHEMESnetlocpathlstripRuntimeErrordict)uri_as_string	split_urir	   s      9/root/env/lib/python3.12/site-packages/smart_open/hdfs.py	parse_urir      sx    %%m4Iw&&&)..0HX__S))H1MABBy''(;;    c                     t        j                  t        |       t        |       }t        |d   |      }|d   j	                  d      d   |_        |S )Nr	   r   )r   check_kwargsopenr   splitname)urimodetransport_params
parsed_urifobjs        r   open_urir#   *   sN    	t-.3J
:&-D:&,,S1"5DIKr   c                 ^    |dk(  rt        |       S |dk(  rt        |       S t        d|z        )Nrbwbz(hdfs support for mode %r not implemented)CliRawInputBaseCliRawOutputBaseNotImplementedError)r   r   s     r   r   r   3   s7    t|s##	$$!"Lt"STTr   c                   X    e Zd ZdZdZd Zd Zed        Zd Z	d Z
d Zdd	Zdd
Zd Zy)r'   zReads bytes from HDFS via the "hdfs dfs" command-line interface.

    Implements the io.RawIOBase interface of the standard library.
    Nc                     || _         t        j                  ddd| j                   gt        j                        | _        y )Nr   dfsz-cat)stdout_uri
subprocessPopenPIPE_subselfr   s     r   __init__zCliRawInputBase.__init__C   s1    	$$feVTYY%GPZP_P_`	r   c                     t         j                  d       | j                  s"| j                  j	                          d| _        yy)zFlush and close this stream.close: calledN)loggerdebugclosedr3   	terminater5   s    r   closezCliRawInputBase.closeJ   s1    _%{{II!DI r   c                     | j                   d u S Nr3   r=   s    r   r;   zCliRawInputBase.closedQ       yyD  r   c                     | j                   duS )z+Return True if the stream can be read from.NrA   r=   s    r   readablezCliRawInputBase.readableU       yy$$r   c                      yz;If False, seek(), tell() and truncate() will raise IOError.F r=   s    r   seekablezCliRawInputBase.seekableY       r   c                 "    t         j                  )zUnsupported.ioUnsupportedOperationr=   s    r   detachzCliRawInputBase.detach`   s    %%%r   c                 L    | j                   j                  j                  |      S )z6Read up to size bytes from the object and return them.)r3   r-   readr5   sizes     r   rQ   zCliRawInputBase.readd   s    yy$$T**r   c                 &    | j                  |      S )zThis is the same as read().)rS   )rQ   rR   s     r   read1zCliRawInputBase.read1h   s    yydy##r   c                 n    | j                  t        |            }|sy||dt        |       t        |      S )zLRead up to len(b) bytes into b, and return the number of bytes
        read.r   N)rQ   len)r5   bdatas      r   readintozCliRawInputBase.readintol   s5     yyQ *3t94yr   )r   )__name__
__module____qualname____doc__r3   r6   r>   propertyr;   rD   rI   rO   rQ   rU   rZ   rH   r   r   r'   r'   <   sK     Da ! !%&+$r   r'   c                   N    e Zd ZdZdZd Zd Zed        Zd Z	d Z
d Zd	 Zd
 Zy)r(   zWrites bytes to HDFS via the "hdfs dfs" command-line interface.

    Implements the io.RawIOBase interface of the standard library.
    Nc                     || _         t        j                  ddddd| j                   gt        j                        | _        y )Nr   r,   z-putz-f-)stdinr.   r4   s     r   r6   zCliRawOutputBase.__init__}   s5    	$$feVT3		%R+5??<	r   c                     t         j                  d       | j                  sV| j                          | j                  j
                  j                          | j                  j                          d | _        y y )Nr8   )r9   r:   r;   flushr3   rc   r>   waitr=   s    r   r>   zCliRawOutputBase.close   sL    _%{{JJLIIOO!!#IINNDI	 r   c                     | j                   d u S r@   rA   r=   s    r   r;   zCliRawOutputBase.closed   rB   r   c                 L    | j                   j                  j                          y r@   )r3   rc   re   r=   s    r   re   zCliRawOutputBase.flush   s    		r   c                     | j                   duS )z(Return True if this object is writeable.NrA   r=   s    r   	writeablezCliRawOutputBase.writeable   rE   r   c                      yrG   rH   r=   s    r   rI   zCliRawOutputBase.seekable   rJ   r   c                 L    | j                   j                  j                  |      S )a  Write the given buffer to the underlying raw stream.

        Returns the number of bytes written, as required by
        :class:`io.RawIOBase`. Without this return value, callers that wrap
        this stream and rely on the documented ``write`` contract (for
        example, ``ray._private.external_storage._write_multiple_objects``,
        which asserts ``written_bytes == payload_len``) fail with an
        ``AssertionError`` because ``write`` would otherwise implicitly
        return ``None``.
        )r3   rc   write)r5   rX   s     r   rm   zCliRawOutputBase.write   s     yy$$Q''r   c                 ,    t        j                  d      )Nzdetach() not supportedrL   r=   s    r   rO   zCliRawOutputBase.detach   s    %%&>??r   )r[   r\   r]   r^   r3   r6   r>   r_   r;   re   rj   rI   rm   rO   rH   r   r   r(   r(   v   sF     D<
 ! ! %( @r   r(   )r^   rM   loggingr0   urllib.parser
   
smart_openr   	getLoggerr[   r9   r   URI_EXAMPLESr   r#   r   	RawIOBaser'   r(   rH   r   r   <module>ru      sj    3 	    			8	$
	<U7bll 7t4@r|| 4@r   