Returns a 2-tuple where the first element is the list of lines from the
    first open paren in lines to the matching closed paren.  The second element
    is all remaining lines in a list.
763365
def split_call(lines, open_paren_line=0):
    """"""
    num_open = 0
    num_closed = 0
    for i, line in enumerate(lines):
        c = line.count('(')
        num_open += c
        if not c and i==open_paren_line:
            raise Exception('Exception open parenthesis in line %d but there is not one there: %s' % (i, str(lines)))
        num_closed += line.count(')')

        if num_open == num_closed:
            return (lines[:i+1], lines[i+1:])

    print(''.join(lines))
    raise Exception('parenthesis are mismatched (%d open, %d closed found)' % (num_open, num_closed))
1011980
def get_line_in_facet(self, facet):
        

        lines = list(facet.outer_lines)
        pt = []
        prev = None
        while len(lines) > 0:
            if prev is None:
                l = lines.pop(0)
            else:
                for i, l in enumerate(lines):
                    if prev in l:
                        l = lines.pop(i)
                        if l[1] == prev:
                            l.reverse()
                        break
            # make sure the lines are connected one by one.
            # find the way covering all pts and facets
            pt.append(self.wulff_pt_list[l[0]].tolist())
            pt.append(self.wulff_pt_list[l[1]].tolist())
            prev = l[1]

        return pt
1026276
def get_lines_from_file(filename, lineno, context_lines):
    

    def get_lines(start, end):
        return [linecache.getline(filename, l).rstrip() for l in range(start, end)]

    lower_bound = max(1, lineno - context_lines)
    upper_bound = lineno + context_lines
    linecache.checkcache(filename)
    pre_context = get_lines(lower_bound, lineno)
    context_line = linecache.getline(filename, lineno).rstrip()
    post_context = get_lines(lineno + 1, upper_bound)
    return lower_bound, pre_context, context_line, post_context
835445
def get_line_segments(line):
    
    line = line.strip()

    tokens = tk.generate_tokens(io.StringIO(line).readline)

    equality_signs = [-1]
    comment_tuple = None, ""
    for i, t in enumerate(tokens):
        if t.type == tk.COMMENT:
            # store string_index and comment string
            comment_tuple = t.start[1], t.string
        if t.type == tk.OP and t.string == "=":
            equality_signs.append(t.start[1])

    if len(equality_signs) > 1:
        # we have at least one assignment
        lhs = line[equality_signs[-2]+1:equality_signs[-1]].strip()
        equality_signs.pop(0)
    else:
        lhs = None

    rhs_start_idx = equality_signs[-1] + 1

    # from the last `=` until the beginning of the comment
    rhs = line[rhs_start_idx:comment_tuple[0]].strip()
    if rhs == "":
        rhs = None
    comment = comment_tuple[1].strip()

    return lhs, rhs, comment
594002
def matching_text_element_lines(re, exclude_nested=[:a])
      matches = []
      find_type_elements_except(:text, exclude_nested).each do |e|
        first_line = e.options[:location]
        # We'll error out if kramdown doesn't have location information for
        # the current element. It's better to just not match in these cases
        # rather than crash.
        next if first_line.nil?
        lines = e.value.split("\n")
        lines.each_with_index do |l, i|
          matches << first_line + i if re.match(l)
        end
      end
      matches
    end
547705
public final Tuple2<Tuple1<T1>, Tuple5<T2, T3, T4, T5, T6>> split1() {
        return new Tuple2<>(limit1(), skip1());
    }
7820
def split_lines(source, maxline=79):
    
    result = []
    extend = result.extend
    append = result.append
    line = []
    multiline = False
    count = 0
    find = str.find
    for item in source:
        index = find(item, '\n')
        if index:
            line.append(item)
            multiline = index > 0
            count += len(item)
        else:
            if line:
                if count <= maxline or multiline:
                    extend(line)
                else:
                    wrap_line(line, maxline, result)
                count = 0
                multiline = False
                line = []
            append(item)
    return result
100682
def head(self, lines=10):
        
        self.seek(0)

        for i in range(lines):
            if not self.seek_line_forward():
                break
    
        end_pos = self.file.tell()
        
        self.seek(0)
        data = self.file.read(end_pos - 1)

        if data:
            return self.splitlines(data)
        else:
            return []
1248623
def matching_lines(re)
      @lines.each_with_index.select{|text, linenum| re.match(text)}.map{
        |i| i[1]+1}
    end
700132
def to_tuple(self, iterable, surround="()", joiner=", "):
    """"""
    return "{0}{1}{2}".format(surround[0], joiner.join(iterable), surround[1])
57338
def find_block_end(row, line_list, sentinal, direction=1):
    
    import re
    row_ = row
    line_ = line_list[row_]
    flag1 = row_ == 0 or row_ == len(line_list) - 1
    flag2 = re.match(sentinal, line_)
    if not (flag1 or flag2):
        while True:
            if (row_ == 0 or row_ == len(line_list) - 1):
                break
            line_ = line_list[row_]
            if re.match(sentinal, line_):
                break
            row_ += direction
    return row_
1239191
public final Tuple2<Tuple1<T1>, Tuple7<T2, T3, T4, T5, T6, T7, T8>> split1() {
        return new Tuple2<>(limit1(), skip1());
    }
756436
public final Tuple2<Tuple4<T1, T2, T3, T4>, Tuple0> split4() {
        return new Tuple2<>(limit4(), skip4());
    }
151654
def _bounded(p1, p2, line, pos, line_no, lines):
    """"""
    substrings = []
    start_line_no = line_no
    end = pos
    while not line.startswith(p2, end):
        if line[end] == '\\':
            end += 2
        else:
            end += 1
        if end >= len(line):
            substrings.append(line[pos:])
            try:
                line_no, line = next(lines)
            except StopIteration:
                pattern = 'docstring' if p1 == '"""' else 'block comment'
                raise TdlParsingError('Unterminated {}'.format(pattern),
                                      line_number=start_line_no)
            pos = end = 0
    substrings.append(line[pos:end])
    end += len(p2)
    return ''.join(substrings), start_line_no, line_no, line, end
119920
public final Tuple2<Tuple1<T1>, Tuple3<T2, T3, T4>> split1() {
        return new Tuple2<>(limit1(), skip1());
    }
854779
public final Tuple2<Tuple4<T1, T2, T3, T4>, Tuple8<T5, T6, T7, T8, T9, T10, T11, T12>> split4() {
        return new Tuple2<>(limit4(), skip4());
    }
679994
public static <A> Tuple2<A, A> fill(A a) {
        return tuple(a, a);
    }