strip_line_magic() implementation for Python 2
326091
def strip_line_magic_v2(cls,line):
        """"""

        matches = re.findall("magic\(([^]]+)", line)
        if matches and matches[0]: # This line contains the pattern
            match = matches[0]
            if match[-1] == ')':
                match = match[:-1] # Just because the re way is hard
            stripped = eval(match)
            magic_kind = stripped.split(' ')[0]
            if len(stripped.split(' '))>1:
                stripped = stripped.split(' ')[1:]
            else:
                stripped = ""
        else:
            stripped = line
            magic_kind = ""
        return stripped,magic_kind
133820
def iter_code_by_lines(self):
        

        lnt = self.get_linenumbertable()
        if not lnt:
            yield (None, None, self.disassemble())
            return

        lnt_offset = lnt[0][1]

        cur_line = None
        current = None

        for codelet in self.disassemble():
            abs_line = self.get_line_for_offset(codelet[0])

            if cur_line == abs_line:
                current.append(codelet)

            else:
                if cur_line is not None:
                    yield (cur_line, cur_line - lnt_offset, current)
                cur_line = abs_line
                current = [codelet]

        if current:
            yield (cur_line, cur_line - lnt_offset, current)
159220
def strip_empty_lines_forward(self, content, i):
        
        while i < len(content):
            line = content[i].strip(' \r\n\t\f')
            if line != '':
                break
            self.debug_print_strip_msg(i, content[i])
            i += 1  # Strip an empty line
        return i
1081569
def process_pure_python2(self, content):
        
        output = []
        savefig = False # keep up with this to clear figure
        multiline = False # to handle line continuation
        multiline_start = None
        fmtin = self.promptin

        ct = 0

        # nuke empty lines
        content = [line for line in content if len(line.strip()) > 0]

        for lineno, line in enumerate(content):

            line_stripped = line.strip()
            if not len(line):
                output.append(line)
                continue

            # handle decorators
            if line_stripped.startswith('@'):
                output.extend([line])
                if 'savefig' in line:
                    savefig = True # and need to clear figure
                continue

            # handle comments
            if line_stripped.startswith('#'):
                output.extend([line])
                continue

            continuation  = u'   %s:'% ''.join(['.']*(len(str(ct))+2))
            if not multiline:
                modified = u"%s %s" % (fmtin % ct, line_stripped)
                output.append(modified)
                ct += 1
                try:
                    ast.parse(line_stripped)
                    output.append(u'')
                except Exception:
                    multiline = True
                    multiline_start = lineno
            else:
                modified = u'%s %s' % (continuation, line)
                output.append(modified)

                try:
                    ast.parse('\n'.join(content[multiline_start:lineno+1]))

                    if (lineno < len(content) - 1 and
                        _count_indent(content[multiline_start]) <
                        _count_indent(content[lineno + 1])):

                        continue

                    output.extend([continuation, u''])
                    multiline = False
                except Exception:
                    pass

            continue

        return output
790136
def strip( text ):
        '''
        
        '''
        members = [attr for attr in Colors.__dict__.keys() if not attr.startswith( "__" ) and not attr == 'strip']

        for c in members:
            text = text.replace( vars( Colors )[c], '' )
        return text
583690
def replace_line_magic(source, magic, template='{line}'):
    
    filtered = []
    for line in source.splitlines():
        if line.strip().startswith(magic):
            substitution = template.format(line=line.replace(magic, ''))
            filtered.append(substitution)
        else:
            filtered.append(line)
    return '\n'.join(filtered)
1192379
def strip_instructions(text):
        
        # Pattern can span multiple lines, allows dot to match newline chars
        flags = re.MULTILINE | re.DOTALL
        pattern = '<!--{token}(.*?){token}-->'.format(token=TOKEN)
        text = re.sub(pattern, '', text, flags=flags)
        return re.sub(r'\A[\s\n]*\n', '', text, flags=flags).rstrip()
1202821
def __remove_leading_empty_lines(lines):
        
        tmp = list()
        empty = True
        for i in range(0, len(lines)):
            empty = empty and lines[i] == ''
            if not empty:
                tmp.append(lines[i])

        return tmp
309611
def line_is_continuation(line: str) -> bool:
    

    llstr = line.lstrip()
    return len(llstr) > 0 and llstr[0] == "&"
1307976
def _get_line_type(line):
    '''  '''
    stripped = line.strip()
    if not stripped:
        return 'empty'
    remainder = re.sub(r"\s+", " ", re.sub(CHORD_RE, "", stripped))
    if len(remainder) * 2 < len(re.sub(r"\s+", " ", stripped)):
        return 'chord'
    return 'lyric'
134834
def trim_lines(lines)
      new_lines = lines.dup
      while new_lines[-1] && new_lines[-1].strip.empty?
        new_lines.pop
      end
      new_lines
    end
950314
def dedent(lines):
    """"""
    if len(lines) != 0:
        first_lstrip = lines[0].lstrip()
        strip_len = len(lines[0]) - len(first_lstrip)
        for line in lines:
            if len(line[:strip_len].strip()) != 0:
                raise ValueError('less indentation than first line: ' +
                                 line)
            else:
                yield line[strip_len:]
871536
private static String stripMarginFromLine(String line, char marginChar) {
        int length = line.length();
        int index = 0;
        while (index < length && line.charAt(index) <= ' ') index++;
        return (index < length && line.charAt(index) == marginChar) ? line.substring(index + 1) : line;
    }
845136
def __substitute_replace_pairs(self):
        
        self._set_magic_constants()

        routine_source = []
        i = 0
        for line in self._routine_source_code_lines:
            self._replace['__LINE__'] = "'%d'" % (i + 1)
            for search, replace in self._replace.items():
                tmp = re.findall(search, line, re.IGNORECASE)
                if tmp:
                    line = line.replace(tmp[0], replace)
            routine_source.append(line)
            i += 1

        self._routine_source_code = "\n".join(routine_source)
1253846
def strip_literal(literal)
      literal = literal[1..-1] if literal[0] == ':'
      literal = literal[1..-2] if literal[0] == "'" || literal[0] == '"'
      literal
    end
451589
private static String stripIndentFromLine(String line, int numChars) {
        int length = line.length();
        return numChars <= length ? line.substring(numChars) : "";
    }
1349592
def handle_magic_line(line, cell, parser, namespace=None):
  
  args = parser.parse(line, namespace)
  if args:
    try:
      return args.func(vars(args), cell)
    except Exception as e:
      sys.stderr.write(str(e))
      sys.stderr.write('\n')
      sys.stderr.flush()
  return None