def chunks(stream, size=None):
  '''
  Returns a generator of chunks from the `stream` with a maximum
  size of `size`. I don't know why this isn't part of core Python.

  :Parameters:

  stream : file-like object

    The stream to fetch the chunks from. Note that the stream will
    not be repositioned in any way.

  size : int | 'lines'; default: null

    If a integer, the size of the chunks to return. If the
    string ``"lines"``, then behaves the same as `file.read()`.
    If unspecified or null, defaults to the package default
    MAXBUF size (usually 8 KiB).
  '''
  if size == 'lines':
    for item in stream:
    # for item in stream.readline():
      yield item
    return
  if size is None:
    size = MAXBUF
  while True:
    buf = stream.read(size)
    if not buf:
      return
    yield buf
def chunks ( stream , size = None ) : if size == 'lines' : for item in stream : yield item return if size is None : size = MAXBUF while True : buf = stream . read ( size ) if not buf : return yield buf
Returns a generator of chunks from the `stream` with a maximum
  size of `size`. I don't know why this isn't part of core Python.

  :Parameters:

  stream : file-like object

    The stream to fetch the chunks from. Note that the stream will
    not be repositioned in any way.

  size : int | 'lines'; default: null

    If a integer, the size of the chunks to return. If the
    string ``"lines"``, then behaves the same as `file.read()`.
    If unspecified or null, defaults to the package default
    MAXBUF size (usually 8 KiB).