def _filter_coverage_for_added_lines(self, diff, coverage):
        if not diff:
            return None

        diff_lines = diff.splitlines()

        current_file = None
        line_number = None
        coverage_by_added_line = []

        for line in diff_lines:
            if line.startswith('diff'):
                # We're about to start a new file.
                current_file = None
                line_number = None
            elif current_file is None and line_number is None and (line.startswith('+++') or line.startswith('---')):
                # We're starting a new file
                if line.startswith('+++ b/'):
                    line = line.split('\t')[0]
                    current_file = unicode(line[6:])
            elif line.startswith('@@'):
                # Jump to new lines within the file
                line_num_info = line.split('+')[1]
                # Strip off the trailing ' @@' so that when only the line is specified
                # and there is no comma, we can just parse as a number.
                line_num_info = line_num_info.rstrip("@ ")
                line_number = int(line_num_info.split(',')[0]) - 1
            elif current_file is not None and line_number is not None:
                # Iterate through the file.
                if line.startswith('+'):
                    # Make sure we have coverage for this line.  Else just tag it as unknown.
                    cov = 'N'
                    if current_file in coverage:
                        try:
                            cov = coverage[current_file][line_number]
                        except IndexError:
                            logger = logging.getLogger('coverage')
                            logger.info('Missing code coverage for line %d of file %s' % (line_number, current_file))

                    coverage_by_added_line.append(cov)

                if not line.startswith('-'):
                    # Up the line count (assuming we aren't at a remove line)
                    line_number += 1

        return coverage_by_added_line
This function takes a diff (text based) and a map of file names to the coverage for those files and
dataset/ETHPy150Open dropbox/changes/changes/api/source_details.py/SourceDetailsAPIView._filter_coverage_for_added_lines