# Path: apitools/base/py/exceptions.py
# class Error(Exception):
# class TypecheckError(Error, TypeError):
# class NotFoundError(Error):
# class UserError(Error):
# class InvalidDataError(Error):
# class CommunicationError(Error):
# class HttpError(CommunicationError):
# class InvalidUserInputError(InvalidDataError):
# class InvalidDataFromServerError(InvalidDataError, CommunicationError):
# class BatchError(Error):
# class ConfigurationError(Error):
# class GeneratedClientError(Error):
# class ConfigurationValueError(UserError):
# class ResourceUnavailableError(Error):
# class CredentialsError(Error):
# class TransferError(CommunicationError):
# class TransferRetryError(TransferError):
# class TransferInvalidError(TransferError):
# class RequestError(CommunicationError):
# class RetryAfterError(HttpError):
# class BadStatusCodeError(HttpError):
# class NotYetImplementedError(GeneratedClientError):
# class StreamExhausted(Error):
#   def __init__(self, response, content, url):
#   def __str__(self):
#   def status_code(self):
#   def FromResponse(cls, http_response):
#   def __init__(self, response, content, url, retry_after):
#   def FromResponse(cls, http_response):
# 
# Path: apitools/base/py/stream_slice.py
# class StreamSlice(object):
#   def __init__(self, stream, max_bytes):
#   def __str__(self):
#   def __len__(self):
#   def __nonzero__(self):
#   def length(self):
#   def read(self, size=None):  # pylint: disable=missing-docstring


import string
import StringIO
import unittest2
from apitools.base.py import exceptions
from apitools.base.py import stream_slice
    self.value = self.stream.getvalue()
    self.stream.seek(0)

  def testSimpleSlice(self):
    ss = stream_slice.StreamSlice(self.stream, 10)
    self.assertEqual('', ss.read(0))
    self.assertEqual(self.value[0:3], ss.read(3))
    self.assertIn('7/10', str(ss))
    self.assertEqual(self.value[3:10], ss.read())
    self.assertEqual('', ss.read())
    self.assertEqual('', ss.read(10))
    self.assertEqual(10, self.stream.tell())

  def testEmptySlice(self):
    ss = stream_slice.StreamSlice(self.stream, 0)
    self.assertEqual('', ss.read(5))
    self.assertEqual('', ss.read())
    self.assertEqual(0, self.stream.tell())

  def testOffsetStream(self):
    self.stream.seek(26)
    ss = stream_slice.StreamSlice(self.stream, 26)
    self.assertEqual(self.value[26:36], ss.read(10))
    self.assertEqual(self.value[36:], ss.read())
    self.assertEqual('', ss.read())

  def testTooShortStream(self):
    ss = stream_slice.StreamSlice(self.stream, 1000)
    self.assertEqual(self.value, ss.read())
    self.assertEqual('', ss.read(0))

# Path: apitools/base/py/exceptions.py
# class Error(Exception):
# class TypecheckError(Error, TypeError):
# class NotFoundError(Error):
# class UserError(Error):
# class InvalidDataError(Error):
# class CommunicationError(Error):
# class HttpError(CommunicationError):
# class InvalidUserInputError(InvalidDataError):
# class InvalidDataFromServerError(InvalidDataError, CommunicationError):
# class BatchError(Error):
# class ConfigurationError(Error):
# class GeneratedClientError(Error):
# class ConfigurationValueError(UserError):
# class ResourceUnavailableError(Error):
# class CredentialsError(Error):
# class TransferError(CommunicationError):
# class TransferRetryError(TransferError):
# class TransferInvalidError(TransferError):
# class RequestError(CommunicationError):
# class RetryAfterError(HttpError):
# class BadStatusCodeError(HttpError):
# class NotYetImplementedError(GeneratedClientError):
# class StreamExhausted(Error):
#   def __init__(self, response, content, url):
#   def __str__(self):
#   def status_code(self):
#   def FromResponse(cls, http_response):
#   def __init__(self, response, content, url, retry_after):
#   def FromResponse(cls, http_response):
# 
# Path: apitools/base/py/stream_slice.py
# class StreamSlice(object):
#   def __init__(self, stream, max_bytes):
#   def __str__(self):
#   def __len__(self):
#   def __nonzero__(self):
#   def length(self):
#   def read(self, size=None):  # pylint: disable=missing-docstring


# Path: apitools/base/py/stream_slice_test.py
import string
import StringIO
import unittest2
from apitools.base.py import exceptions
from apitools.base.py import stream_slice

    self.value = self.stream.getvalue()
    self.stream.seek(0)

  def testSimpleSlice(self):
    ss = stream_slice.StreamSlice(self.stream, 10)
    self.assertEqual('', ss.read(0))
    self.assertEqual(self.value[0:3], ss.read(3))
    self.assertIn('7/10', str(ss))
    self.assertEqual(self.value[3:10], ss.read())
    self.assertEqual('', ss.read())
    self.assertEqual('', ss.read(10))
    self.assertEqual(10, self.stream.tell())

  def testEmptySlice(self):
    ss = stream_slice.StreamSlice(self.stream, 0)
    self.assertEqual('', ss.read(5))
    self.assertEqual('', ss.read())
    self.assertEqual(0, self.stream.tell())

  def testOffsetStream(self):
    self.stream.seek(26)
    ss = stream_slice.StreamSlice(self.stream, 26)
    self.assertEqual(self.value[26:36], ss.read(10))
    self.assertEqual(self.value[36:], ss.read())
    self.assertEqual('', ss.read())

  def testTooShortStream(self):
    ss = stream_slice.StreamSlice(self.stream, 1000)
    self.assertEqual(self.value, ss.read())
    self.assertEqual('', ss.read(0))

    with self.assertRaises(exceptions.StreamExhausted) as e: