a
    ù!f[  ã                   @   s$   d Z ddlmZ G dd„ deƒZdS )z8Small helper class to provide a small slice of a stream.é    )Úhttp_clientc                   @   sF   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zed
d„ ƒZ	ddd„Z
dS )ÚStreamSlicezíProvides a slice-like object for streams.

    :type stream:  readable file-like object
    :param stream:  the stream to be buffered

    :type max_bytes: integer
    :param max_bytes: maximum number of bytes to return in the slice
    c                 C   s   || _ || _|| _d S ©N©Ú_streamÚ_remaining_bytesÚ
_max_bytes)ÚselfÚstreamZ	max_bytes© r   ú^/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/streaming/stream_slice.pyÚ__init__   s    zStreamSlice.__init__c                 C   s   d| j | j| jf S )Nz0Slice of stream %s with %s/%s bytes not yet readr   ©r	   r   r   r   Ú__repr__"   s    ÿzStreamSlice.__repr__c                 C   s   | j S r   ©r   r   r   r   r   Ú__len__&   s    zStreamSlice.__len__c                 C   s
   t | jƒS r   )Úboolr   r   r   r   r   Ú__nonzero__)   s    zStreamSlice.__nonzero__c                 C   s   | j S )zÝMaximum number of bytes to return in the slice.

        .. note::

           For 32-bit python2.x, len() cannot exceed a 32-bit number.

        :rtype: integer
        :returns: The max "length" of the stream.
        r   r   r   r   r   Úlength.   s    zStreamSlice.lengthNc                 C   s`   |durt || jƒ}n| j}| j |¡}|dkrJ|sJt | j| j | j¡‚|  jt|ƒ8  _|S )aI  Read bytes from the 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 :exc:`IncompleteRead`.

        :type size: integer or None
        :param size: If provided, read no more than size bytes from the stream.

        :rtype: bytes
        :returns: bytes read from this slice.

        :raises: :exc:`IncompleteRead`
        Nr   )Úminr   r   Úreadr   ÚIncompleteReadr   Úlen)r	   ÚsizeÚ	read_sizeÚdatar   r   r   r   ;   s    ÿzStreamSlice.read)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úpropertyr   r   r   r   r   r   r      s   
r   N)r   Z	six.movesr   Úobjectr   r   r   r   r   Ú<module>   s   