# Path: pysaliency/utils.py
# def full_split(filename):
#     """ split filename into all parts """
#     path, basename = os.path.split(filename)
#     components = [path, basename]
#     while components[0] and components[0] != '/':
#         first_part = components.pop(0)
#         path, basename = os.path.split(first_part)
#         components = [path, basename] + components
# 
#     if components[0] == '':
#         components = components[1:]
# 
#     return components


import os.path
from .utils import full_split
    def apply(self, source, target):
        src_pos = self.source_start - 1
        assert len(target) == self.target_start - 1
        for line in self.lines:
            type, data = line[0], line[1:]
            if type == ' ':
                assert source[src_pos] == data
                target.append(data)
                src_pos += 1
            elif type == '-':
                assert source[src_pos] == data
                src_pos += 1
            elif type == '+':
                target.append(data)
            elif type == '\\':
                # Newline stuff, ignore
                pass
            else:
                raise ValueError(line)
        assert src_pos == self.source_start + self.source_length - 1
        assert len(target) == self.target_start + self.target_length - 1
        return src_pos


class Diff(object):
    def __init__(self, lines):
        source = lines.pop(0)
        assert source.startswith('--- ')
        _, source = source.split('--- ', 1)
        source, _ = source.split('\t', 1)

# Path: pysaliency/utils.py
# def full_split(filename):
#     """ split filename into all parts """
#     path, basename = os.path.split(filename)
#     components = [path, basename]
#     while components[0] and components[0] != '/':
#         first_part = components.pop(0)
#         path, basename = os.path.split(first_part)
#         components = [path, basename] + components
# 
#     if components[0] == '':
#         components = components[1:]
# 
#     return components


# Path: pysaliency/quilt.py
import os.path
from .utils import full_split

    def apply(self, source, target):
        src_pos = self.source_start - 1
        assert len(target) == self.target_start - 1
        for line in self.lines:
            type, data = line[0], line[1:]
            if type == ' ':
                assert source[src_pos] == data
                target.append(data)
                src_pos += 1
            elif type == '-':
                assert source[src_pos] == data
                src_pos += 1
            elif type == '+':
                target.append(data)
            elif type == '\\':
                # Newline stuff, ignore
                pass
            else:
                raise ValueError(line)
        assert src_pos == self.source_start + self.source_length - 1
        assert len(target) == self.target_start + self.target_length - 1
        return src_pos


class Diff(object):
    def __init__(self, lines):
        source = lines.pop(0)
        assert source.startswith('--- ')
        _, source = source.split('--- ', 1)
        source, _ = source.split('\t', 1)

        source = os.path.join(*full_split(source)[1:])