
                         r    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZ G d dej                        Z	y)	z8FilePart implementation for representing part of a file.    )absolute_import)print_function)division)unicode_literalsNc                       e Zd ZdZd Zd Zd Zd ZddZe	j                  fdZd Zdd
ZddZddZddZddZddZddZddZddZddZy	)FileParta  Subclass of the file API for representing part of a file.

  This class behaves as a contiguous subset of a given file (e.g., this object
  will behave as though the desired part of the file was written to another
  file, and the second file was opened).
  c                     t        |d      | _        || _        || _        | j                  | j                  z   | _        | j                  j                  | j                         y)aF  Initializes the FilePart.

    Args:
      filename: The name of the existing file, of which this object represents
                a part.
      offset: The position (in bytes) in the original file that corresponds to
              the first byte of the FilePart.
      length: The total number of bytes in the FilePart.
    rbN)open_fplength_start_endseek)selffilenameoffsetr   s       "platform/gsutil/gslib/file_part.py__init__zFilePart.__init__#   sH     Hd#DHDKDKdkk)DIHHMM$++    c                      y N r   s    r   	__enter__zFilePart.__enter__3   s    r   c                 $    | j                          y r   )close)r   typevalue	tracebacks       r   __exit__zFilePart.__exit__7   s    JJLr   c                 P    | j                   j                         | j                  z
  S r   )r   tellr   r   s    r   r#   zFilePart.tell:   s    88==?T[[((r   c                     |dk  r| j                   }t        || j                  | j                  j	                         z
        }| j                  j                  t        d|            S )Nr   )r   minr   r   r#   readmaxr   sizes     r   r&   zFilePart.read=   sJ    ax[[dtTYY01D88==Q&&r   c                 &   |t         j                  k(  r(| j                  j                  || j                  z         S |t         j
                  k(  r| j                  j                  ||      S | j                  j                  | j                  |z         S r   )osSEEK_ENDr   r   r   SEEK_CURr   )r   r   whences      r   r   zFilePart.seekC   sg    XX]]6DII-..	2;;	XX]]66**XX]]4;;/00r   c                 8    | j                   j                          y r   )r   r   r   s    r   r   zFilePart.closeK   s    HHNNr   Nc                     t        d      )Nz%flush is not implemented in FilePart.NotImplementedErrorr(   s     r   flushzFilePart.flushN       
E
FFr   c                     t        d      )Nz&fileno is not implemented in FilePart.r1   r(   s     r   filenozFilePart.filenoQ       
F
GGr   c                     t        d      )Nz&isatty is not implemented in FilePart.r1   r(   s     r   isattyzFilePart.isattyT   r7   r   c                     t        d      )Nz$next is not implemented in FilePart.r1   r(   s     r   nextzFilePart.nextW   s    
D
EEr   c                     t        d      )Nz(readline is not implemented in FilePart.r1   r(   s     r   readlinezFilePart.readlineZ       
H
IIr   c                     t        d      )Nz)readlines is not implemented in FilePart.r1   r(   s     r   	readlineszFilePart.readlines]   s    
I
JJr   c                     t        d      )Nz*xreadlines is not implemented in FilePart.r1   r(   s     r   
xreadlineszFilePart.xreadlines`       
J
KKr   c                     t        d      )Nz(truncate is not implemented in FilePart.r1   r(   s     r   truncatezFilePart.truncatec   r>   r   c                     t        d      )Nz%write is not implemented in FilePart.r1   r(   s     r   writezFilePart.writef   r4   r   c                     t        d      )Nz*writelines is not implemented in FilePart.r1   r(   s     r   
writelineszFilePart.writelinesi   rC   r   )r   )__name__
__module____qualname____doc__r   r   r!   r#   r&   r+   SEEK_SETr   r   r3   r6   r9   r;   r=   r@   rB   rE   rG   rI   r   r   r   r   r      so     	)' !# 1GHHFJKLJGLr   r   )
rN   
__future__r   r   r   r   r+   ioIOBaser   r   r   r   <module>rS      s0    ? & %  ' 	 	PLryy PLr   