'renders the template according to the given namespace.
__namespace - a dictionary serving as a namespace for evaluation
**kw - keyword arguments which are added to the namespace'

def render(self, __namespace=None, **kw):

    namespace = {}
    if __namespace:
        namespace.update(__namespace)
    if kw:
        namespace.update(kw)
    namespace['emit'] = self.write
    __stdout = sys.stdout
    sys.stdout = self
    self.__output = []
    eval(self.__code, namespace)
    sys.stdout = __stdout
    return ''.join(self.__output)
