def render(self, *args, **kwargs):
        """Render the template, replacing macros along the way"""
        bufferstring = str(self.buffer)
        for matchedstring in r_macro.findall(self.buffer):
            # this list should contain the name of the object first, then the attrs needed
            obj_and_attrs = matchedstring.split('.')
            # remove the filters from the attr string
            obj_and_attrs[-1] = obj_and_attrs[-1].split('|', 1)[0]
            obj, attrs = obj_and_attrs[0], obj_and_attrs[1:]

            if obj.startswith('['):
                index = int(obj[1:-1])
                if not index < len(args):
                    #raise ValueError("No object at index %s!"%index)
                    bufferstring = bufferstring.replace('$'+matchedstring, '')
                    continue
                else:
                    obj = args[index]
            
            else:
                if obj not in kwargs:
                    #raise ValueError("No object with name %r"%obj)
                    bufferstring = bufferstring.replace('$'+matchedstring, '')
                    continue
                obj = kwargs[obj]

            value = obj
            if len(attrs) > 0:
                for attr in attrs:
                    if not attr:
                        raise ValueError("Cannot have empty attr!")
                    try:
                        value = getattr(value, attr)
                    except AttributeError:
                        value = value[attr]

            filters = matchedstring.split('|')[1:]

            for filtername in filters:
                if not filtername:
                    raise ValueError("Cannot have empty filter!")
                try:
                    value = getattr(self, "do_"+filtername)(value)
                except AttributeError:
                    try:
                        value = self.filterregister[filtername](value)
                    except KeyError:
                        value = self.do_ALL(value, filtername)

            bufferstring = bufferstring.replace('$'+matchedstring, str(value))
                    
        return bufferstring.replace('$$', '$').replace('\.', '.')
Render the template, replacing macros along the way
recipes/Python/578090_Python_Template_Engine/recipe-578090.py