Split diffs and context lines into groups based on None sentinel
779014
def _split_diff(merge_result, context_lines=3):
    """"""
    collect = []
    for item in _visible_in_diff(merge_result, context_lines=context_lines):
        if item is None:
            if collect:
                yield collect
            collect = []
        else:
            collect.append(item)
167977
def split_lines(lines):
    
    container = []
    new_list = []
    for line in lines:
        if '>>>' in line:
            container.append(new_list)
            new_list = []
        else:
            new_list.append(line)
    container.append(new_list)
    return container
709138
def parse_group(cls, group, lines, dist=None):
        """"""
        if not MODULE(group):
            raise ValueError("Invalid group name", group)
        this = {}
        for line in yield_lines(lines):
            ep = cls.parse(line, dist)
            if ep.name in this:
                raise ValueError("Duplicate entry point", group, ep.name)
            this[ep.name] = ep
        return this
1346147
def parse_options(cls, line, ns={}):
        
        parsed = cls.parse(line, ns=ns)
        options_list = []
        for spec in sorted(parsed.keys()):
            options = parsed[spec]
            merged = {}
            for group in options.values():
                merged = dict(group.kwargs, **merged)
            options_list.append(Options(spec, **merged))
        return options_list
1260861
def _split_version_specifier(spec):
    """"""
    m = re.search(r'([<>=]?=?)?\s*([0-9.a-zA-Z]+)', spec)
    return m.group(2), m.group(1)
1014000
def record_diff(lhs, rhs):
    ""
    delta = {}
    for k in set(lhs).union(rhs):
        from_ = lhs[k]
        to_ = rhs[k]
        if from_ != to_:
            delta[k] = {'from': from_, 'to': to_}

    return delta
1314590
def _combine_lines(self, lines):
        
        lines = filter(None, map(lambda x: x.strip(), lines))
        return '[' + ','.join(lines) + ']'
255186
def _highlight_line_difflib(self, line, next):
        

        if line['action'] == 'del':
            old, new = line, next
        else:
            old, new = next, line

        oldwords = re.split(r'(\W)', old['line'])
        newwords = re.split(r'(\W)', new['line'])

        sequence = difflib.SequenceMatcher(None, oldwords, newwords)

        oldfragments, newfragments = [], []
        for tag, i1, i2, j1, j2 in sequence.get_opcodes():
            oldfrag = ''.join(oldwords[i1:i2])
            newfrag = ''.join(newwords[j1:j2])
            if tag != 'equal':
                if oldfrag:
                    oldfrag = '<del>%s</del>' % oldfrag
                if newfrag:
                    newfrag = '<ins>%s</ins>' % newfrag
            oldfragments.append(oldfrag)
            newfragments.append(newfrag)

        old['line'] = "".join(oldfragments)
        new['line'] = "".join(newfragments)
845165
function diff (code, lang) {
  var sections = []

  code.split(/\r?\n/g).forEach(function (line) {
    var type

    if (CHUNK_REGEXP.test(line)) {
      type = 'chunk'
    } else if (HEADER_REGEXP.test(line)) {
      type = 'header'
    } else {
      type = PATCH_TYPES[line[0]] || 'null'
      line = line.replace(/^[+\-! ]/, '')
    }

    // Merge data with the previous section where possible.
    var previous = sections[sections.length - 1]

    if (!previous || previous.type !== type) {
      sections.push({
        type: type,
        lines: [line]
      })

      return
    }

    previous.lines.push(line)
  })

  return highlightSections(sections, lang)
    .map(function (section) {
      var type = section.type
      var value = section.lines.join(SEPARATOR)

      return '<span class="diff-' + type + '">' + value + '</span>'
    })
    .join(SEPARATOR)
}
441814
def _make_diff(self, correct, given):
        """"""
        dmp = DMP()
        dmp.Diff_Timeout = 4
        text1, text2, array = dmp.diff_linesToChars(correct, given)
        diffs = dmp.diff_main(text1, text2)
        dmp.diff_cleanupSemantic(diffs)
        dmp.diff_charsToLines(diffs, array)
        return list(dmp_to_mdiff(diffs))
675337
def __separate_data_vars(line):
        
        combine = []
        if '#' in line:
            line = line.replace("#", "")
            line = line.lstrip()
        if line not in NOAA_EMPTY and line not in EMPTY:
            m = re.match(re_var_split, line)
            if m:
                combine.append(m.group(1))
                attr = m.group(2).split(',')
                combine += attr
                for index, string in enumerate(combine):
                    combine[index] = string.strip()
                # for i, s in enumerate(combine):
                #     if not s or s in NOAA_EMPTY:
                #         del combine[i]
        return combine
559130
def split_results(results):
    """"""
    from dask.delayed import Delayed

    def flatten(results):
        out = []
        if isinstance(results, (list, tuple)):
            for itm in results:
                out.extend(flatten(itm))
            return out
        return [results]

    sources = []
    targets = []
    delayeds = []

    for res in flatten(results):
        if isinstance(res, da.Array):
            sources.append(res)
        elif isinstance(res, Delayed):
            delayeds.append(res)
        else:
            targets.append(res)
    return sources, targets, delayeds
1268743
def split_df(df):
    '''
    
    '''
    envmask = (df['agent_id'] == 'env')
    n_env = envmask.sum()
    if n_env == len(df):
        return df, None
    elif n_env == 0:
        return None, df
    agents, env = [x for _, x in df.groupby(envmask)]
    return env, agents
132653
def do_minus(self, parser, group):
        '''
        '''
        grouper = group.__class__()
        
        next_not = None
        for node in group:
            if isinstance(node, self.Minus):
                if next_not is not None:
                    # Two Minuses in a row; skip the second one
                    continue
                next_not = whoosh.qparser.syntax.NotGroup()
                grouper.append(next_not)
            else:
                # Nodes with children: search for nested Minus nodes
                if isinstance(node, whoosh.qparser.syntax.GroupNode):
                    node = self.do_minus(parser, node)
                if next_not is not None:
                    next_not.append(node)
                    next_not = None
                else:
                    grouper.append(node)
        if next_not is not None:
            # Remove the empty NotGroup
            grouper.pop()
        
        return grouper
1183088
def iddtxt2grouplist(txt):
    
    def makenone(astr):
        if astr == 'None':
            return None
        else:
            return astr

    txt = nocomment(txt, '!')
    txt = txt.replace("\\group", "!-group") # retains group in next line
    txt = nocomment(txt, '\\') # remove all other idd info
    lines = txt.splitlines()
    lines = [line.strip() for line in lines] # cleanup
    lines = [line for line in lines if line != ''] # cleanup
    txt = '\n'.join(lines)
    gsplits = txt.split('!') # split into groups, since we have !-group
    gsplits = [gsplit.splitlines() for gsplit in gsplits] # split group

    gsplits[0].insert(0, u'-group None')
        # Put None for the first group that does nothave a group name
    
    glist = []
    for gsplit in gsplits:
        glist.append((gsplit[0], gsplit[1:]))
        # makes dict {groupname:[k1, k2], groupname2:[k3, k4]}

    glist = [(k, '\n'.join(v)) for k, v in glist]# joins lines back
    glist = [(k, v.split(';')) for k, v in glist] # splits into idfobjects
    glist = [(k, [i.strip() for i in v]) for k, v in glist] # cleanup
    glist = [(k, [i.splitlines() for i in v]) for k, v in glist]
        # splits idfobjects into lines
    glist = [(k, [i for i in v if len(i) > 0]) for k, v in glist]
        # cleanup - removes blank lines
    glist = [(k, [i[0] for i in v]) for k, v in glist] # use first line
    fglist = []
    for gnamelist in glist:
        gname = gnamelist[0]
        thelist = gnamelist[-1]
        for item in thelist:
            fglist.append((gname, item))
    glist = [(gname[len("-group "):], obj) for gname, obj in fglist] # remove "-group "
    glist = [(makenone(gname), obj) for gname, obj in glist] # make str None into None
    glist = [(gname, obj.split(',')[0]) for gname, obj in glist] # remove comma
    return glist
1357815
def _diff_and_summarize(from_csv, to_csv, index_columns, stream=sys.stdout,
                        sep=',', ignored_columns=None, significance=None):
    
    from_records = list(records.load(from_csv, sep=sep))
    to_records = records.load(to_csv, sep=sep)

    diff = patch.create(from_records, to_records, index_columns, ignored_columns)
    if significance is not None:
        diff = patch.filter_significance(diff, significance)

    _summarize_diff(diff, len(from_records), stream=stream)
    exit_code = (EXIT_SAME
                 if patch.is_empty(diff)
                 else EXIT_DIFFERENT)
    sys.exit(exit_code)
901378
def split_at_offsets(line, offsets):
    
    result = []

    previous_offset = 0
    current_offset = 0
    for current_offset in sorted(offsets):
        if current_offset < len(line) and previous_offset != current_offset:
            result.append(line[previous_offset:current_offset].strip())
        previous_offset = current_offset

    result.append(line[current_offset:])

    return result