def write(<EOL>stream_fragments, stream, normalize=True,<EOL>book=None, sources=None, names=None, mappings=None):
def push_line():<EOL><INDENT>mappings.append([])<EOL>book.keeper._sink_column = <NUM_LIT:0><EOL><DEDENT>if names is None:<EOL><INDENT>names = Names()<EOL><DEDENT>if sources is None:<EOL><INDENT>sources = Names()<EOL><DEDENT>if book is None:<EOL><INDENT>book = default_book()<EOL><DEDENT>if not isinstance(mappings, list):<EOL><INDENT>mappings = []<EOL>push_line()<EOL><DEDENT>for chunk, lineno, colno, original_name, source in stream_fragments:<EOL><INDENT>lines = chunk.splitlines(True)<EOL>for line in lines:<EOL><INDENT>stream.write(line)<EOL>if lineno is None or colno is None:<EOL><INDENT>mappings[-<NUM_LIT:1>].append((book.keeper.sink_column,))<EOL><DEDENT>else:<EOL><INDENT>name_id = names.update(original_name)<EOL>source_id = sources.update(source) or <NUM_LIT:0><EOL>if lineno:<EOL><INDENT>book.keeper.source_line = lineno<EOL>source_line = book.keeper.source_line<EOL><DEDENT>else:<EOL><INDENT>source_line = <NUM_LIT:0><EOL><DEDENT>if colno:<EOL><INDENT>book.keeper.source_column = colno<EOL><DEDENT>else:<EOL><INDENT>book.keeper.source_column = (<EOL>book.keeper._source_column + book.original_len)<EOL><DEDENT>if original_name is not None:<EOL><INDENT>mappings[-<NUM_LIT:1>].append((<EOL>book.keeper.sink_column, source_id,<EOL>source_line, book.keeper.source_column,<EOL>name_id<EOL>))<EOL><DEDENT>else:<EOL><INDENT>mappings[-<NUM_LIT:1>].append((<EOL>book.keeper.sink_column, source_id,<EOL>source_line, book.keeper.source_column<EOL>))<EOL><DEDENT><DEDENT>if line[-<NUM_LIT:1>:] in '<STR_LIT:\r\n>':<EOL><INDENT>colno = (<EOL>colno if colno in (<NUM_LIT:0>, None) else<EOL>colno + len(line.rstrip()))<EOL>book.original_len = book.written_len = <NUM_LIT:0><EOL>push_line()<EOL>if line is not lines[-<NUM_LIT:1>]:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', len(mappings)<EOL>)<EOL>logger.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>book.written_len = len(line)<EOL>book.original_len = (<EOL>len(original_name) if original_name else book.written_len)<EOL>book.keeper.sink_column = (<EOL>book.keeper._sink_column + book.written_len)<EOL><DEDENT><DEDENT><DEDENT>if normalize:<EOL><INDENT>mappings = normalize_mappings(mappings)<EOL><DEDENT>list_sources = [<EOL>INVALID_SOURCE if s == NotImplemented else s for s in sources<EOL>] or [INVALID_SOURCE]<EOL>return mappings, list_sources, list(names)<EOL>
Given an iterable of stream fragments, write it to the stream object
by using its write method.  Returns a 3-tuple, where the first
element is the mapping, second element is the list of sources and
the third being the original names referenced by the given fragment.

Arguments:

stream_fragments
    an iterable that only contains StreamFragments
stream
    an io.IOBase compatible stream object
normalize
    the default True setting will result in the mappings that were
    returned be normalized to the minimum form.  This will reduce
    the size of the generated source map at the expense of slightly
    lower quality.

    Also, if any of the subsequent arguments are provided (for
    instance, for the multiple calls to this function), the usage of
    the normalize flag is currently NOT supported.

    If multiple sets of outputs are to be produced, the recommended
    method is to chain all the stream fragments together before
    passing in.

Advanced usage arguments

book
    A Book instance; if none is provided an instance will be created
    from the default_book constructor.  The Bookkeeper instance is
    used for tracking the positions of rows and columns of the input
    stream.
sources
    a Names instance for tracking sources; if None is provided, an
    instance will be created for internal use.
names
    a Names instance for tracking names; if None is provided, an
    instance will be created for internal use.
mappings
    a previously produced mappings.

A stream fragment tuple must contain the following

- The string to write to the stream
- Original starting line of the string; None if not present
- Original starting column fo the line; None if not present
- Original string that this fragment represents (i.e. for the case
  where this string fragment was an identifier but got mangled into
  an alternative form); use None if this was not the case.
- The source of the fragment.  If the first fragment is unspecified,
  the INVALID_SOURCE url will be used (i.e. about:invalid).  After
  that, a None value will be treated as the implicit value, and if
  NotImplemented is encountered, the INVALID_SOURCE url will be used
  also.

If a number of stream_fragments are to be provided, common instances
of Book (constructed via default_book) and Names (for sources and
names) should be provided if they are not chained together.