File: File.py

package info (click to toggle)
spe 0.8.2a%2Brepack-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,812 kB
  • ctags: 6,555
  • sloc: python: 45,491; makefile: 146; sh: 2
file content (39 lines) | stat: -rwxr-xr-x 1,109 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pychecker2.util import parents

from compiler import ast

class File:
    def __init__(self, name):
        self.name = name
        self.parseTree = None
        self.scopes = {}
        self.root_scope = None
        self.warnings = []

    def __cmp__(self, other):
        return cmp(self.name, other.name)

    def warning(self, line, warn, *args):
        lineno = getattr(line, 'lineno', line)
        if not lineno and hasattr(line, 'parent'):
            for p in parents(line):
                if p.lineno:
                    lineno = p.lineno
                    break
        self.warnings.append( (lineno, warn, args) )

    def scope_filter(self, type):
        return [x for x in self.scopes.iteritems() if isinstance(x[0], type)]

    def function_scopes(self):
        return self.scope_filter(ast.Function)

    def class_scopes(self):
        return self.scope_filter(ast.Class)

    def not_class_scopes(self):
        result = []
        for n, s in self.scopes.iteritems():
            if not isinstance(n, ast.Class):
                result.append( (n, s) )
        return result