mirror of
https://github.com/powerline/powerline.git
synced 2025-07-31 01:35:40 +02:00
Forbid most operations for Context instances
This commit is contained in:
parent
891a9cbaa5
commit
b333f9ec11
@ -38,26 +38,36 @@ def list_themes(data, context):
|
|||||||
|
|
||||||
|
|
||||||
class Context(tuple):
|
class Context(tuple):
|
||||||
def __new__(cls, base, other=None):
|
for func in dir(tuple):
|
||||||
if other is not None:
|
if func in ('__getitem__', '__init__', '__getattribute__', '__len__', '__iter__'):
|
||||||
return tuple.__new__(cls, tuple.__add__(base, other))
|
continue
|
||||||
else:
|
exec((
|
||||||
return tuple.__new__(cls, ((MarkedUnicode('', base.mark), base),))
|
'def {0}(self, *args, **kwargs):\n'
|
||||||
|
' raise TypeError("{0} is not allowed for Context")'
|
||||||
|
).format(func))
|
||||||
|
del func
|
||||||
|
|
||||||
def __add__(self, arg):
|
__slots__ = ()
|
||||||
assert(len(arg) == 1)
|
|
||||||
assert(type(arg) is tuple)
|
def __new__(cls, base, context_key=None, context_value=None):
|
||||||
assert(len(arg[0]) == 2)
|
if context_key is not None:
|
||||||
assert(type(arg[0]) is tuple)
|
assert(context_value is not None)
|
||||||
havemarks(arg[0][0], arg[0][1])
|
assert(type(base) is Context)
|
||||||
return Context.__new__(Context, self, arg)
|
havemarks(context_key, context_value)
|
||||||
|
return tuple.__new__(cls, tuple.__add__(base, ((context_key, context_value),)))
|
||||||
|
else:
|
||||||
|
havemarks(base)
|
||||||
|
return tuple.__new__(cls, ((MarkedUnicode('', base.mark), base),))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def key(self):
|
def key(self):
|
||||||
return key_sep.join((c[0] for c in self))
|
return key_sep.join((c[0] for c in self))
|
||||||
|
|
||||||
def enter_key(self, value, key):
|
def enter_key(self, value, key):
|
||||||
return self + ((value.keydict[key], value[key]),)
|
return self.enter(value.keydict[key], value[key])
|
||||||
|
|
||||||
def enter_item(self, name, item):
|
def enter_item(self, name, item):
|
||||||
return self + ((MarkedUnicode(name, item.mark), item),)
|
return self.enter(MarkedUnicode(name, item.mark), item)
|
||||||
|
|
||||||
|
def enter(self, context_key, context_value):
|
||||||
|
return Context.__new__(Context, self, context_key, context_value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user