diff options
author | German M. Bravo <german.mb@deipi.com> | 2013-09-26 17:26:00 -0500 |
---|---|---|
committer | German M. Bravo <german.mb@deipi.com> | 2013-09-26 17:26:09 -0500 |
commit | 65754c240b95ee1fc9462110306149ec441acbc8 (patch) | |
tree | bd227ba29dedf92da1bcb8f76c4ee659c8cadaa4 /scss/rule.py | |
parent | abb1c0a71971a84c07322d1cbdad2b94a42e5486 (diff) | |
download | pyscss-65754c240b95ee1fc9462110306149ec441acbc8.tar.gz |
Immutable Namespaces added
Diffstat (limited to 'scss/rule.py')
-rw-r--r-- | scss/rule.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/scss/rule.py b/scss/rule.py index fe1db34..63422dc 100644 --- a/scss/rule.py +++ b/scss/rule.py @@ -77,8 +77,11 @@ class VariableScope(object): class Namespace(object): """...""" + _mutable = True + + def __init__(self, variables=None, functions=None, mixins=None, mutable=True): + self._mutable = mutable - def __init__(self, variables=None, functions=None, mixins=None): if variables is None: self._variables = VariableScope() else: @@ -93,6 +96,10 @@ class Namespace(object): self._mixins = VariableScope() + def _assert_mutable(self): + if not self._mutable: + raise AttributeError("This Namespace instance is immutable") + @classmethod def derive_from(cls, *others): self = cls() @@ -120,6 +127,7 @@ class Namespace(object): return self._variables[name] def set_variable(self, name, value, local_only=False): + self._assert_mutable() name = normalize_var(name) if not isinstance(value, Value): raise TypeError("Expected a Sass type, while setting %s got %r" % (name, value,)) @@ -145,12 +153,14 @@ class Namespace(object): return self._get_callable(self._mixins, name, arity) def set_mixin(self, name, arity, cb): + self._assert_mutable() self._set_callable(self._mixins, name, arity, cb) def function(self, name, arity): return self._get_callable(self._functions, name, arity) def set_function(self, name, arity, cb): + self._assert_mutable() self._set_callable(self._functions, name, arity, cb) |