docs: def write_key_val(stream, key, val, linesep=os.linesep):
      """
      The MANIFEST specification limits the width of individual lines to
      72 bytes (including the terminating newlines). Any key and value
      pair that would be longer must be split up over multiple
      continuing lines
      :type key, val: str in Py3, str or unicode in Py2
      :type stream: binary
      """
  
      key = key.encode('utf-8') or ""
      val = val.encode('utf-8') or ""
      linesep = linesep.encode('utf-8')
  
      if not (0 < len(key) < 69):
          raise ManifestKeyException("bad key length", key)
  
      if len(key) + len(val) > 68:
          kvbuffer = BytesIO(b": ".join((key, val)))
  
          # first grab 70 (which is 72 after the trailing newline)
          stream.write(kvbuffer.read(70))
  
          # now only 69 at a time, because we need a leading space and a
          # trailing \n
          part = kvbuffer.read(69)
          while part:
              stream.write(linesep + b" ")
              stream.write(part)
              part = kvbuffer.read(69)
          kvbuffer.close()
  
      else:
          stream.write(key)
          stream.write(b": ")
          stream.write(val)
  
      stream.write(linesep)