
    
                     *    S r SSKJr   " S S\5      rg)z8Small helper class to provide a small slice of a stream.    )
exceptionsc                   J    \ rS rSrSrS rS rS rS r\	S 5       r
SS	 jrS
rg)StreamSlice   z)Provides a slice-like object for streams.c                 (    Xl         X l        X l        g N_StreamSlice__stream_StreamSlice__remaining_bytes_StreamSlice__max_bytes)selfstream	max_bytess      0lib/third_party/apitools/base/py/stream_slice.py__init__StreamSlice.__init__   s    !*$    c                 \    SU R                   < SU R                  < SU R                  < S3$ )NzSlice of stream z with /z bytes not yet readr	   r   s    r   __str__StreamSlice.__str__   s%    MM41143C3CE 	Er   c                     U R                   $ r   r   r   s    r   __len__StreamSlice.__len__#   s    r   c                 ,    [        U R                  5      $ r   )boolr   r   s    r   __nonzero__StreamSlice.__nonzero__&   s     D$$%%r   c                     U R                   $ r   r   r   s    r   lengthStreamSlice.length+   s     r   Nc                 T   Ub  [        XR                  5      nOU R                  nU R                  R                  U5      nUS:  aC  U(       d<  [        R
                  " SU R                  U R                  U R                  -
  4-  5      eU =R                  [        U5      -  sl        U$ )a  Read at most size bytes from this slice.

Compared to other streams, there is one case where we may
unexpectedly raise an exception on read: if the underlying stream
is exhausted (i.e. returns no bytes on read), and the size of this
slice indicates we should still be able to read more bytes, we
raise exceptions.StreamExhausted.

Args:
  size: If provided, read no more than size bytes from the stream.

Returns:
  The bytes read from this slice.

Raises:
  exceptions.StreamExhausted

r   z;Not enough bytes in stream; expected %d, exhausted after %d)minr   r
   readr   StreamExhaustedr   len)r   size	read_sizedatas       r   r&   StreamSlice.read0   s    & D"8"89I..I}}!!),q=,,$$$$t'='==??@ @
 	#d)+r   )__max_bytes__remaining_bytes__streamr   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   propertyr"   r&   __static_attributes__ r   r   r   r      s3    3%
E &
    r   r   N)r4   apitools.base.pyr   objectr   r7   r   r   <module>r:      s   " ? '9& 9r   