Count lines of code (by default ignores empty lines, but child could override to do more).
324130
def count_lines(self, code):
        
        return sum(bool(line.strip()) for line in code.splitlines())
182860
def parse_lines(self, lines):
        
        indent = ''
        level = 0

        if lines[0][0] == ' ' or lines[0][0] == '\t':
            raise CommandError("The first line in the file cannot start with a space or tab.")

        # This keeps track of the current parents at a given level
        current_parents = {0: None}

        for line in lines:
            if len(line) == 0:
                continue
            if line[0] == ' ' or line[0] == '\t':
                if indent == '':
                    indent = self.get_indent(line)
                elif not line[0] in indent:
                    raise CommandError("You can't mix spaces and tabs for indents")
                level = line.count(indent)
                current_parents[level] = self.make_category(line, parent=current_parents[level - 1])
            else:
                # We are back to a zero level, so reset the whole thing
                current_parents = {0: self.make_category(line)}
        current_parents[0]._tree_manager.rebuild()
1020855
def ignore(code):
    
    if code in Main.options['ignore']:
        return True
    if any(c in code for c in Main.options['ignore']):
        return True
    return False
1265044
def count_lines_to_next_cell(cell_end_marker, next_cell_start, total, explicit_eoc):
    """"""
    if cell_end_marker < total:
        lines_to_next_cell = next_cell_start - cell_end_marker
        if explicit_eoc:
            lines_to_next_cell -= 1
        if next_cell_start >= total:
            lines_to_next_cell += 1
        return lines_to_next_cell

    return 1
704443
def _count_pixels_on_line(self, y, p):
        """"""
        h = line(y, self._effective_thickness(p), 0.0)
        return h.sum()
1084750
private void getCounts(String path, Counts counts) {
        DataNode node = getNode(path);
        if (node == null) {
            return;
        }
        String[] children = null;
        int len = 0;
        synchronized (node) {
            Set<String> childs = node.getChildren();
            if (childs != null) {
                children = childs.toArray(new String[childs.size()]);
            }
            len = (node.data == null ? 0 : node.data.length);
        }
        // add itself
        counts.count += 1;
        counts.bytes += len;
        if (children == null || children.length == 0) {
            return;
        }
        for (String child : children) {
            getCounts(path + "/" + child, counts);
        }
    }
1151385
def check_rst(code, ignore):
    """"""
    filename = '<string>'

    for result in check(code,
                        filename=filename,
                        ignore=ignore):
        yield result
1288672
def lines_once(cls, code, **kwargs):
        
        if kwargs:
            g = cls.with_id_processor()
            g._append_context(kwargs)
        else:
            g = cls()
        g.lines(code)
        return g.code
1245385
def count_lines(path, extensions=None, excluded_dirnames=None):
    """"""
    if extensions is None:
        extensions = ['.py', '.pyw', '.ipy', '.enaml', '.c', '.h', '.cpp',
                      '.hpp', '.inc', '.', '.hh', '.hxx', '.cc', '.cxx',
                      '.cl', '.f', '.for', '.f77', '.f90', '.f95', '.f2k',
                      '.f03', '.f08']
    if excluded_dirnames is None:
        excluded_dirnames = ['build', 'dist', '.hg', '.svn']
    def get_filelines(path):
        dfiles, dlines = 0, 0
        if osp.splitext(path)[1] in extensions:
            dfiles = 1
            with open(path, 'rb') as textfile:
                dlines = len(textfile.read().strip().splitlines())
        return dfiles, dlines
    lines = 0
    files = 0
    if osp.isdir(path):
        for dirpath, dirnames, filenames in os.walk(path):
            for d in dirnames[:]:
                if d in excluded_dirnames:
                    dirnames.remove(d)
            if excluded_dirnames is None or \
               osp.dirname(dirpath) not in excluded_dirnames:
                for fname in filenames:
                    dfiles, dlines = get_filelines(osp.join(dirpath, fname))
                    files += dfiles
                    lines += dlines
    else:
        dfiles, dlines = get_filelines(path)
        files += dfiles
        lines += dlines
    return files, lines
893315
def check_one_liners(self, definition, docstring):
        
        if docstring:
            lines = ast.literal_eval(docstring).split('\n')
            if len(lines) > 1:
                non_empty_lines = sum(1 for l in lines if not is_blank(l))
                if non_empty_lines == 1:
                    return violations.D200(len(lines))
943659
def count(self):
        
        total = len(self.children)
        for child in self.children:
            total += child.count()
        return total
845868
def _code_line(self, line):
        """"""
        assert self._containers
        container = self._containers[-1]
        # Handle extra spaces.
        text = line
        while text:
            if text.startswith('  '):
                r = re.match(r'(^ +)', text)
                n = len(r.group(1))
                container.addElement(S(c=n))
                text = text[n:]
            elif '  ' in text:
                assert not text.startswith(' ')
                i = text.index('  ')
                container.addElement(Span(text=text[:i]))
                text = text[i:]
            else:
                container.addElement(Span(text=text))
                text = ''
121338
def _number_of_line(member_tuple):
    """"""
    member = member_tuple[1]
    try:
        return member.__code__.co_firstlineno
    except AttributeError:
        pass
    try:
        return inspect.findsource(member)[1]
    except BaseException:
        pass
    for value in vars(member).values():
        try:
            return value.__code__.co_firstlineno
        except AttributeError:
            pass
    return 0
83448
def _children(self):
        """"""
        for codeobj in self.body._children():
            yield codeobj
        for catch_block in self.catches:
            for codeobj in catch_block._children():
                yield codeobj
        for codeobj in self.finally_body._children():
            yield codeobj
1143921
def line_content_counts_as_uncovered_manual(content: str) -> bool:
    
    # Omit empty lines.
    if not content:
        return False

    # Omit declarations.
    for keyword in ['def', 'class']:
        if content.startswith(keyword) and content.endswith(':'):
            return False

    # TODO: multiline comments, multiline strings, etc, etc.
    return True
831990
def count(self, Class, set=None, recursive=True,ignore=True):
        """"""
        if self.mode == Mode.MEMORY:
            s = 0
            for t in self.data:
                s +=  sum( 1 for e in t.select(Class,recursive,True ) )
            return s
1006690
def ignore_comments(lines_enum):
    # type: (ReqFileLines) -> ReqFileLines
    
    for line_number, line in lines_enum:
        line = COMMENT_RE.sub('', line)
        line = line.strip()
        if line:
            yield line_number, line