human
I wrote the below code

    def add_metadata_item(src, name, val):
        index = src.rindex('}')
        return (((((src[:index] + '{\\    '[:(-1)]) + name) + '    ') + val) + '}}')
    (src, pos) = get_document_info(stream)
    if (src is None):
        create_metadata(stream, options)
    else:
        olen = len(src)
        base_pat = '\\{\\\\name(.*?)(?<!\\\\)\\}'
        title = options.title
        if (title is not None):
            title = encode(title)
            pat = re.compile(base_pat.replace('name', 'title'), re.DOTALL)
            if pat.search(src):
                src = pat.sub((('{\\\\title    ' + title) + '}'), src)
            else:
                src = add_metadata_item(src, 'title', title)
        comment = options.comments
        if (comment is not None):
            comment = encode(comment)
            pat = re.compile(base_pat.replace('name', 'subject'), re.DOTALL)
            if pat.search(src):
                src = pat.sub((('{\\\\subject    ' + comment) + '}'), src)
            else:
                src = add_metadata_item(src, 'subject', comment)
        author = options.authors
        if (author is not None):
            author = ',    '.join(author)
            author = encode(author)
            pat = re.compile(base_pat.replace('name', 'author'), re.DOTALL)
            if pat.search(src):
                src = pat.sub((('{\\\\author    ' + author) + '}'), src)
            else:
                src = add_metadata_item(src, 'author', author)
        tags = options.tags
        if (tags is not None):
            tags = ',    '.join(tags)
            tags = encode(tags)
            pat = re.compile(base_pat.replace('name', 'category'), re.DOTALL)
            if pat.search(src):
                src = pat.sub((('{\\\\category    ' + tags) + '}'), src)
            else:
                src = add_metadata_item(src, 'category', tags)
        publisher = options.publisher
        if (publisher is not None):
            publisher = encode(publisher)
            pat =...

What's a good function header?
 ... Here's a good function header?
assistant
#Here's a good function header.

def set_metadata(stream, options):