

def tag_stream(original, filtered, tags):
    "Alter tags on a stream.\n\n    :param original: The input stream.\n    :param filtered: The output stream.\n    :param tags: The tags to apply. As in a normal stream - a list of 'TAG' or\n        '-TAG' commands.\n\n        A 'TAG' command will add the tag to the output stream,\n        and override any existing '-TAG' command in that stream.\n        Specifically:\n         * A global 'tags: TAG' will be added to the start of the stream.\n         * Any tags commands with -TAG will have the -TAG removed.\n\n        A '-TAG' command will remove the TAG command from the stream.\n        Specifically:\n         * A 'tags: -TAG' command will be added to the start of the stream.\n         * Any 'tags: TAG' command will have 'TAG' removed from it.\n        Additionally, any redundant tagging commands (adding a tag globally\n        present, or removing a tag globally removed) are stripped as a\n        by-product of the filtering.\n    :return: 0\n    "
    (new_tags, gone_tags) = tags_to_new_gone(tags)

    def write_tags(new_tags, gone_tags):
        if (new_tags or gone_tags):
            filtered.write(('tags: ' + ' '.join(new_tags)))
            if gone_tags:
                for tag in gone_tags:
                    filtered.write(('-' + tag))
            filtered.write('\n')
    write_tags(new_tags, gone_tags)
    for line in original:
        if line.startswith('tags:'):
            line_tags = line[5:].split()
            (line_new, line_gone) = tags_to_new_gone(line_tags)
            line_new = (line_new - gone_tags)
            line_gone = (line_gone - new_tags)
            write_tags(line_new, line_gone)
        else:
            filtered.write(line)
    return 0

dataset/ETHPy150Open byt3bl33d3r/pth-toolkit/lib/python2.7/site-packages/samba/external/subunit/__init__.py tag_stream/original