/usr/share/pyshared/pychecker2/util.py is in pychecker 0.8.19-11.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | class BaseVisitor:
def visit(self, unused_node):
"method is really overridden by compiler.visitor.ASTVisitor"
assert 0, 'Unreachable'
def visitChildren(self, n):
for c in n.getChildNodes():
self.visit(c)
def try_if_exclusive(stmt_node1, stmt_node2):
from compiler import ast as ast
"""return true if the statements are in exclusive parts of if/elif/else
or try/finally/else"""
parent = stmt_node1.parent.parent
if parent == stmt_node2.parent.parent:
if isinstance(parent, ast.If):
parts = [code for test, code in parent.tests]
parts.append(parent.else_)
for part in parts:
if part and stmt_node1 in part.nodes:
return stmt_node2 not in part.nodes
if isinstance(parent, ast.TryExcept):
parts = []
if parent.body:
parts.extend(parent.body.nodes)
if parent.else_:
parts.extend(parent.else_.nodes)
return not (stmt_node1 in parts and stmt_node2 in parts)
return None
def parents(obj):
class Parents:
def __init__(self, start):
self.next = start
def __call__(self):
retval = self.next.parent
self.next = retval
return retval
return iter(Parents(obj), None)
def enclosing_scopes(scopes, node):
result = []
n = node
while n:
try:
result.append(scopes[n])
except KeyError:
pass
n = n.parent
return result
def type_filter(seq, *classes):
return [s for s in seq if isinstance(s, classes)]
def dict_minus(a, b):
r = {}
for k, v in a.iteritems():
if not b.has_key(k):
r[k] = v
return r
def dict_intersect(a, b):
r = {}
for k, v in a.iteritems():
if b.has_key(k):
r[k] = v
return r
|