54 lines
1.2 KiB
Python
Raw Normal View History

2012-02-12 11:50:57 +00:00
"""
"""
class Scope(list):
def __init__(self):
super().__init__()
2012-02-12 12:11:15 +00:00
self._mixins = {}
2012-02-12 11:50:57 +00:00
def push(self):
self.append({
'__variables__' : {},
'__blocks__': [],
'__current__': None
})
2012-02-12 12:00:56 +00:00
@property
2012-02-12 11:50:57 +00:00
def current(self):
return self[-1]['__current__']
2012-02-12 12:00:56 +00:00
@current.setter
def current(self, value):
self[-1]['__current__'] = value
2012-02-12 12:11:15 +00:00
def add_block(self, block):
"""
"""
self[-1]['__blocks__'].append(block)
def add_mixin(self, mixin):
"""
"""
self._mixins[mixin.name()] = mixin
2012-02-12 12:00:56 +00:00
2012-02-12 12:11:15 +00:00
def mixins(self, name):
2012-02-12 11:50:57 +00:00
"""
"""
2012-02-12 12:11:15 +00:00
return (self._mixins[name]
if name in self._mixins
else False)
2012-02-12 12:00:56 +00:00
def in_mixin(self):
"""
"""
return any([s for s in self
2012-02-12 12:11:15 +00:00
if s['__current__'] == '__mixin__'])
def update(self, scope):
"""
"""
blocks = [b for b in self[0]['__blocks__']]
blocks.extend([b for b in scope[0]['__blocks__']])
self._mixins.update(scope._mixins)
self[0].update(scope[0])
self[0]['__blocks__'] = blocks