
    
                     *    d Z ddlmZ  G d de      Zy)zSmall helper class to provide a small slice of a stream.

This class reads ahead to detect if we are at the end of the stream.
    )
exceptionsc                   Z    e Zd ZdZd Zd Zd Zed        Zed        Z	ed        Z
d
d	Zy)BufferedStreamzABuffers a stream, reading ahead to determine if we're at the end.c                     || _         || _        d| _        | j                   j                  |      | _        t        | j                        |k  | _        | j                  t        | j                        z   | _        y )Nr   )_BufferedStream__stream_BufferedStream__start_pos_BufferedStream__buffer_posread_BufferedStream__buffered_datalen_BufferedStream__stream_at_end_BufferedStream__end_pos)selfstreamstartsizes       3lib/third_party/apitools/base/py/buffered_stream.py__init__zBufferedStream.__init__   se     #}}11$7"4#7#784?))C0D0D,EE    c           	      p    d| j                   d| j                  d| j                  d| j                  d	S )NzBuffered stream z from position -z with z bytes remaining)r   r   r   _bytes_remainingr   s    r   __str__zBufferedStream.__str__&   s,    %)]]D4D4D%)^^T5J5JL 	Mr   c                 ,    t        | j                        S N)r   r   r   s    r   __len__zBufferedStream.__len__+   s    4''((r   c                     | j                   S r   )r   r   s    r   stream_exhaustedzBufferedStream.stream_exhausted.   s    ###r   c                     | j                   S r   )r   r   s    r   stream_end_positionz"BufferedStream.stream_end_position2   s    ~~r   c                 F    t        | j                        | j                  z
  S r   )r   r   r	   r   s    r   r   zBufferedStream._bytes_remaining6   s    4''(4+<+<<<r   Nc                 l   ||dk  rMt        j                  d|d| j                  d| j                  d| j                  d| j
                  d      d}| j
                  rQt        || j
                        }| j                  | j                  | j                  |z    }| xj                  |z  c_        |S )	zReads from the buffer.r   zIllegal read of size z- requested on BufferedStream. Wrapped stream z is at position r   z, z bytes remaining. )	r   NotYetImplementedErrorr   r   r   r   minr   r	   )r   r   datas      r   r
   zBufferedStream.read:   s    <4!833 t}}d&6&6&&	() )   tT223D''!!$"3"3d":<D%r   r   )__name__
__module____qualname____doc__r   r   r   propertyr   r!   r   r
    r   r   r   r      sW    KFM
) $ $   = =r   r   N)r+   apitools.base.pyr   objectr   r-   r   r   <module>r0      s   "
 (0V 0r   