Return a diff between two strings.
976410
def _diff(text_0, text_1):
    """"""
    diff = difflib.ndiff(text_0.splitlines(), text_1.splitlines())
    return _diff_removed_lines(diff)
675598
def compare(file1, file2):
    """"""
    if isinstance(file1, six.string_types):  # pragma: no branch
        file1 = open(file1, 'r', True)
    if isinstance(file2, six.string_types):  # pragma: no branch
        file2 = open(file2, 'r', True)
    file1_contents = file1.read()
    file2_contents = file2.read()
    return file1_contents == file2_contents
587021
def diff(a, b):
    
    a, b = list(a), list(b)
    opcodes = SM(None, a, b).get_opcodes()
    return parse_opcodes(opcodes)
631070
def parse_diff(base_str):
        
        temp_dict = {'years': 0,
                     'months': 0,
                     'weeks': 0,
                     'days': 0,
                     'hours': 0,
                     'minutes': 0,
                     'seconds': 0}

        _pure_str = re.findall("[a-zA-Z]+", base_str)
        pure_num = [int(_) for _ in re.findall(r'\d+', base_str)]
        pure_str = [filter_unit(_) for _ in _pure_str]
        result_dict = dict(chain(temp_dict.items(), dict(zip(pure_str, pure_num)).items()))
        if result_dict['months'] >= 12:
            advance = result_dict['months'] // 12
            remain = result_dict['months'] % 12
            result_dict['years'] += advance
            result_dict['months'] = remain
        if result_dict['weeks']:
            result_dict['days'] += result_dict['weeks'] * 7
        return result_dict
149766
function diff( $old, $new )
    {
        $datatype = $this->dataType();
        $result = $datatype->diff( $old, $new );
        return $result;
    }
187369
def _get_diffs(cls, dict1, dict2, ignore_missing_keys):
        '''
        
        '''
        ret_dict = {}
        for p in dict1.keys():
            if p not in dict2:
                ret_dict.update({p: {'new': dict1[p], 'old': cls.NONE_VALUE}})
            elif dict1[p] != dict2[p]:
                if isinstance(dict1[p], dict) and isinstance(dict2[p], dict):
                    sub_diff_dict = cls._get_diffs(dict1[p], dict2[p],
                                                   ignore_missing_keys)
                    if sub_diff_dict:
                        ret_dict.update({p: sub_diff_dict})
                else:
                    ret_dict.update({p: {'new': dict1[p], 'old': dict2[p]}})
        if not ignore_missing_keys:
            for p in dict2.keys():
                if p not in dict1.keys():
                    ret_dict.update({p: {'new': cls.NONE_VALUE,
                                         'old': dict2[p]}})
        return ret_dict
396602
def diff(self):
        
        latest = self.latest
        current = NetJsonParser(self.json())
        return diff(current, latest)
1104633
def get_diff_text(old, new, filename):
    """"""
    newline = '\n'
    diff = difflib.unified_diff(
        old, new,
        'original/' + filename,
        'fixed/' + filename,
        lineterm=newline)

    text = ''
    for line in diff:
        text += line

        # Work around missing newline (http://bugs.python.org/issue2142).
        if text and not line.endswith(newline):
            text += newline + r'\ No newline at end of file' + newline

    return text
1345713
def diff_texts(left, right, diff_options=None, formatter=None):
    """"""
    return _diff(etree.fromstring, left, right,
                 diff_options=diff_options, formatter=formatter)
380594
def difference(self, other):
        """"""
        return self.operation(other, lambda x, y: x - y)
874867
def diff_dict(dict1, dict2, ignore_missing=False):
    """"""
    unidict1 = dict_unicodeize(dict1)
    unidict2 = dict_unicodeize(dict2)
    if ((not ignore_missing) and (len(unidict1) != len(unidict2))) or \
       (ignore_missing and (len(unidict1) >= len(unidict2))):
        return True

    for comp_k, comp_v in iteritems(unidict1):
        if comp_k not in unidict2:
            return True
        else:
            if comp_v != unidict2[comp_k]:
                return True

    return False
1305902
def diff(local_path, remote_path):
    """"""
    with hide('commands'):
        if isinstance(local_path, basestring):
            with open(local_path) as stream:
                local_content = stream.read()
        else:
            pos = local_path.tell()
            local_content = local_path.read()
            local_path.seek(pos)
        remote_content = StringIO()
        with settings(hide('warnings'), warn_only=True):
            if get(remote_path, remote_content).failed:
                return True
        return local_content.strip() != remote_content.getvalue().strip()
134365
def diff_files(left, right, diff_options=None, formatter=None):
    """"""
    return _diff(etree.parse, left, right,
                 diff_options=diff_options, formatter=formatter)
601268
def diff(self, other, **kwargs):
        
        return JsonDiff(
            base_type_name=type(self).__name__,
            other_type_name=type(other).__name__,
            values=self.diff_iter(other, **kwargs),
        )
307620
def diff(self, diff):
        
        if diff is None:
            return None
        return dict(
            toVol=diff.toUUID,
            fromVol=diff.fromUUID,
            size=diff.size,
            sizeIsEstimated=diff.sizeIsEstimated,
        )
996033
def print_diff(diff, color=True):
    """"""
    import colorama

    if not diff:
        return

    if not color:
        colorama.init = lambda autoreset: None
        colorama.Fore.RED = ''
        colorama.Back.RED = ''
        colorama.Fore.GREEN = ''
        colorama.deinit = lambda: None

    colorama.init(autoreset=True)  # TODO use context_manager
    for line in diff.splitlines():
        if line.startswith('+') and not line.startswith('+++ '):
            # Note there shouldn't be trailing whitespace
            # but may be nice to generalise this
            print(colorama.Fore.GREEN + line)
        elif line.startswith('-') and not line.startswith('--- '):
            split_whitespace = re.split('(\s+)$', line)
            if len(split_whitespace) > 1:  # claim it must be 3
                line, trailing, _ = split_whitespace
            else:
                line, trailing = split_whitespace[0], ''
            print(colorama.Fore.RED + line, end='')
            # give trailing whitespace a RED background
            print(colorama.Back.RED + trailing)
        elif line == '\ No newline at end of file':
            # The assumption here is that there is now a new line...
            print(colorama.Fore.RED + line)
        else:
            print(line)
    colorama.deinit()
956005
def subtract(dict_a, dict_b, strict=False):
    """"""
    if not strict:
        return subtract_by_key(dict_a, dict_b)

    difference_dict = {}
    for key in dict_a:
        if key not in dict_b or dict_b[key] != dict_a[key]:
            difference_dict[key] = dict_a[key]

    return difference_dict