def apply_vars(self, cont): if isinstance(cont, basestring) and "$" in cont: try: # Optimization: the full cont is a variable in the context, cont = self.namespace.variable(cont) except KeyError: # Interpolate variables: def _av(m): v = self.namespace.variable(m.group(2)) if v: v = to_str(v) # TODO this used to test for _dequote if m.group(1): v = dequote(v) elif v is not None: v = to_str(v) else: v = m.group(0) return v cont = _interpolate_re.sub(_av, cont) # XXX what?: if options is not None: # ...apply math: cont = self.do_glob_math(cont) return cont
def apply_vars(self, cont): if isinstance(cont, six.string_types) and '$' in cont: try: # Optimization: the full cont is a variable in the context, cont = self.namespace.variable(cont) except KeyError: # Interpolate variables: def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if config.FATAL_UNDEFINED: raise else: if config.VERBOSITY > 1: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, six.string_types): v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v cont = _interpolate_re.sub(_av, cont) # XXX what?: if options is not None: # ...apply math: cont = self.do_glob_math(cont) return cont
def apply_vars(self, cont): # TODO this is very complicated. it should go away once everything # valid is actually parseable. if isinstance(cont, six.string_types) and '$' in cont: try: # Optimization: the full cont is a variable in the context, cont = self.namespace.variable(cont) except KeyError: # Interpolate variables: def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if self.undefined_variables_fatal: raise SyntaxError("Undefined variable: '%s'." % n) else: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, Value): raise TypeError( "Somehow got a variable {0!r} " "with a non-Sass value: {1!r}".format( n, v)) v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v cont = _interpolate_re.sub(_av, cont) else: # Variable succeeded, so we need to render it cont = cont.render() # TODO this is surprising and shouldn't be here cont = self.do_glob_math(cont) return cont
def apply_vars(self, cont): # TODO this is very complicated. it should go away once everything # valid is actually parseable. if isinstance(cont, six.string_types) and '$' in cont: try: # Optimization: the full cont is a variable in the context, cont = self.namespace.variable(cont) except KeyError: # Interpolate variables: def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if self.undefined_variables_fatal: raise SyntaxError("Undefined variable: '%s'." % n) else: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, Value): raise TypeError( "Somehow got a variable {0!r} " "with a non-Sass value: {1!r}" .format(n, v) ) v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v cont = _interpolate_re.sub(_av, cont) else: # Variable succeeded, so we need to render it cont = cont.render() # TODO this is surprising and shouldn't be here cont = self.do_glob_math(cont) return cont
def apply_vars(self, cont): # TODO this is very complicated. it should go away once everything # valid is actually parseable. if isinstance(cont, six.string_types) and '$' in cont: try: # Optimization: the full cont is a variable in the context, cont = self.namespace.variable(cont) except KeyError: # Interpolate variables: def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if config.FATAL_UNDEFINED: raise SyntaxError("Undefined variable: '%s'." % n) else: if config.VERBOSITY > 1: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, six.string_types): v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v cont = _interpolate_re.sub(_av, cont) # TODO this is surprising and shouldn't be here cont = self.do_glob_math(cont) return cont
def apply_vars(self, cont): if isinstance(cont, six.string_types) and '$' in cont: try: # Optimization: the full cont is a variable in the context, cont = self.namespace.variable(cont) except KeyError: # Interpolate variables: def _av(m): v = self.namespace.variable(m.group(2)) if v: if not isinstance(v, six.string_types): v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v cont = _interpolate_re.sub(_av, cont) # XXX what?: if options is not None: # ...apply math: cont = self.do_glob_math(cont) return cont