5 if isinstance(elt
, tuple):
6 elts
= elts
+ flatten(elt
)
16 def __contains__(self
, elt
):
17 return elt
in self
.elts
21 return self
.elts
.keys()
22 def has_elt(self
, elt
):
23 return elt
in self
.elts
24 def remove(self
, elt
):
28 c
.elts
.update(self
.elts
)
34 self
.pop
= self
.stack
.pop
36 return len(self
.stack
)
38 self
.stack
.append(elt
)
41 def __getitem__(self
, index
): # needed by visitContinue()
42 return self
.stack
[index
]
44 MANGLE_LEN
= 256 # magic constant from compile.c
46 def mangle(name
, klass
):
47 if not name
.startswith('__'):
49 if len(name
) + 2 >= MANGLE_LEN
:
51 if name
.endswith('__'):
55 while klass
[i
] == '_':
61 tlen
= len(klass
) + len(name
)
63 klass
= klass
[:MANGLE_LEN
-tlen
]
65 return "_%s%s" % (klass
, name
)
67 def set_filename(filename
, tree
):
68 """Set the filename attribute to filename on every node in tree"""
71 node
= worklist
.pop(0)
72 node
.filename
= filename
73 worklist
.extend(node
.getChildNodes())