
    lc                         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dS )zImplements reading and writing to/from HDFS.

The main entry point is the :func:`~smart_open.hdfs.open` function.

Uses the command-line hdfs utility under the covers.

    N)utilshdfs)zhdfs:///path/filezhdfs://path/filec                    t           j                            |           }|j        t          k    sJ |j        |j        z   }d|                    d          z   }|st          d| z            t          t          |          S )N/zinvalid HDFS URI: %r)schemeuri_path)
urllibparseurlsplitr   SCHEMEnetlocpathlstripRuntimeErrordict)uri_as_string	split_urir   s      /lib/python3.11/site-packages/smart_open/hdfs.py	parse_urir   "   s    %%m44Iv%%%%).0HX__S)))H C1MABBBv1111    c                     t          j        t          |           t          |           }t          |d         |          }|d                             d          d         |_        |S )Nr   r   )r   check_kwargsopenr   splitname)urimodetransport_params
parsed_urifobjs        r   open_urir"   .   sY    	t-...3J
:&--D:&,,S11"5DIKr   c                 z    |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   7   sL    t| Us###	 U$$$!"Lt"STTTr   c                   F    e Zd ZdZd Zd Zd Zd Zd ZddZ	dd	Z
d
 ZdS )r&   zReads bytes from HDFS via the "hdfs dfs" command-line interface.

    Implements the io.RawIOBase interface of the standard library.
    c                 ~    || _         t          j        ddd| j         gt          j                  | _        d | _        d S )Nr   dfsz-cat)stdout_uri
subprocessPopenPIPE_subrawselfr   s     r   __init__zCliRawInputBase.__init__F   s<    	$feVTY%GPZP_```	
 r   c                 z    t                               d           | j                                         d| _        dS )zFlush and close this stream.zclose: calledN)loggerdebugr2   	terminater5   s    r   closezCliRawInputBase.closeR   s3    _%%%				r   c                     | j         duS )z+Return True if the stream can be read from.Nr2   r;   s    r   readablezCliRawInputBase.readableX       y$$r   c                     dS z;If False, seek(), tell() and truncate() will raise IOError.F r;   s    r   seekablezCliRawInputBase.seekable\       ur   c                     t           j        )zUnsupported.ioUnsupportedOperationr;   s    r   detachzCliRawInputBase.detachc   s    %%r   r   c                 @    | j         j                            |          S )z6Read up to size bytes from the object and return them.)r2   r,   readr5   sizes     r   rL   zCliRawInputBase.readg   s    y$$T***r   c                 .    |                      |          S )zThis is the same as read().)rN   )rL   rM   s     r   read1zCliRawInputBase.read1k   s    yydy###r   c                     |                      t          |                    }|sdS ||dt          |          <   t          |          S )zLRead up to len(b) bytes into b, and return the number of bytes
        read.r   N)rL   len)r5   bdatas      r   readintozCliRawInputBase.readintoo   sG     yyQ   	1*3t99*4yyr   N)r   )__name__
__module____qualname____doc__r6   r<   r?   rD   rJ   rL   rP   rU   rC   r   r   r&   r&   @   s         
    % % %  & & &+ + + +$ $ $ $    r   r&   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
r'   zWrites bytes to HDFS via the "hdfs dfs" command-line interface.

    Implements the io.RawIOBase interface of the standard library.
    c                     || _         t          j        ddddd| j         gt          j                  | _        d | _        d S )Nr   r+   z-putz-f-)stdinr-   r4   s     r   r6   zCliRawOutputBase.__init__~   sE    	$feVT3	%R+5?< < <	 r   c                     |                                   | j        j                                         | j                                         d S N)flushr2   r]   r<   waitr;   s    r   r<   zCliRawOutputBase.close   s=    

		r   c                 B    | j         j                                         d S r_   )r2   r]   r`   r;   s    r   r`   zCliRawOutputBase.flush   s    	r   c                     | j         duS )z(Return True if this object is writeable.Nr>   r;   s    r   	writeablezCliRawOutputBase.writeable   r@   r   c                     dS rB   rC   r;   s    r   rD   zCliRawOutputBase.seekable   rE   r   c                 D    | j         j                            |           d S r_   )r2   r]   write)r5   rS   s     r   rg   zCliRawOutputBase.write   s     	a     r   c                 *    t          j        d          )Nzdetach() not supportedrG   r;   s    r   rJ   zCliRawOutputBase.detach   s    %&>???r   N)rV   rW   rX   rY   r6   r<   r`   rd   rD   rg   rJ   rC   r   r   r'   r'   y   s             
     % % %  ! ! !@ @ @ @ @r   r'   )rY   rH   loggingr/   urllib.parser	   
smart_openr   	getLoggerrV   r8   r   URI_EXAMPLESr   r"   r   	RawIOBaser&   r'   rC   r   r   <module>ro      s    
			               		8	$	$		2 	2 	2  U U U6 6 6 6 6bl 6 6 6r&@ &@ &@ &@ &@r| &@ &@ &@ &@ &@r   