# Path: philo/templatetags/containers.py
# class ContainerNode(template.Node):
# 	def __init__(self, name, references=None, as_var=None):
# 		self.name = name
# 		self.as_var = as_var
# 		self.references = references
# 	
# 	def render(self, context):
# 		container_content = self.get_container_content(context)
# 		
# 		if self.as_var:
# 			context[self.as_var] = container_content
# 			return ''
# 		
# 		return container_content
# 	
# 	def get_container_content(self, context):
# 		try:
# 			container_context = context.render_context[CONTAINER_CONTEXT_KEY]
# 		except KeyError:
# 			try:
# 				page = context['page']
# 			except KeyError:
# 				return settings.TEMPLATE_STRING_IF_INVALID
# 			
# 			container_context = ContainerContext(page)
# 			context.render_context[CONTAINER_CONTEXT_KEY] = container_context
# 		
# 		if self.references:
# 			# Then it's a content reference.
# 			try:
# 				contentreference = container_context.get_references()[(self.name, self.references)]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentreference.content
# 		else:
# 			# Otherwise it's a contentlet.
# 			try:
# 				contentlet = container_context.get_contentlets()[self.name]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentlet.content
# 		return content


import itertools
from django.template import TextNode, VariableNode, Context
from django.template.loader_tags import BlockNode, ExtendsNode, BlockContext, ConstantIncludeNode
from django.utils.datastructures import SortedDict
from philo.templatetags.containers import ContainerNode
					blocks[name] = [block]
		
		for block_list in blocks.values():
			for block in block_list:
				block.initialize()
				contentlet_specs.extend(itertools.ifilter(lambda x: x not in contentlet_specs, block.contentlet_specs))
				contentreference_specs.update(block.contentreference_specs)
		
		return contentlet_specs, contentreference_specs


class LazyContainerFinder(object):
	def __init__(self, nodes, extends=False):
		self.nodes = nodes
		self.initialized = False
		self.contentlet_specs = []
		self.contentreference_specs = SortedDict()
		self.blocks = {}
		self.block_super = False
		self.extends = extends
	
	def process(self, nodelist):
		for node in nodelist:
			if self.extends:
				if isinstance(node, BlockNode):
					self.blocks[node.name] = block = LazyContainerFinder(node.nodelist)
					block.initialize()
					self.blocks.update(block.blocks)
				continue
			

# Path: philo/templatetags/containers.py
# class ContainerNode(template.Node):
# 	def __init__(self, name, references=None, as_var=None):
# 		self.name = name
# 		self.as_var = as_var
# 		self.references = references
# 	
# 	def render(self, context):
# 		container_content = self.get_container_content(context)
# 		
# 		if self.as_var:
# 			context[self.as_var] = container_content
# 			return ''
# 		
# 		return container_content
# 	
# 	def get_container_content(self, context):
# 		try:
# 			container_context = context.render_context[CONTAINER_CONTEXT_KEY]
# 		except KeyError:
# 			try:
# 				page = context['page']
# 			except KeyError:
# 				return settings.TEMPLATE_STRING_IF_INVALID
# 			
# 			container_context = ContainerContext(page)
# 			context.render_context[CONTAINER_CONTEXT_KEY] = container_context
# 		
# 		if self.references:
# 			# Then it's a content reference.
# 			try:
# 				contentreference = container_context.get_references()[(self.name, self.references)]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentreference.content
# 		else:
# 			# Otherwise it's a contentlet.
# 			try:
# 				contentlet = container_context.get_contentlets()[self.name]
# 			except KeyError:
# 				content = ''
# 			else:
# 				content = contentlet.content
# 		return content


# Path: philo/utils/templates.py
import itertools
from django.template import TextNode, VariableNode, Context
from django.template.loader_tags import BlockNode, ExtendsNode, BlockContext, ConstantIncludeNode
from django.utils.datastructures import SortedDict
from philo.templatetags.containers import ContainerNode

					blocks[name] = [block]
		
		for block_list in blocks.values():
			for block in block_list:
				block.initialize()
				contentlet_specs.extend(itertools.ifilter(lambda x: x not in contentlet_specs, block.contentlet_specs))
				contentreference_specs.update(block.contentreference_specs)
		
		return contentlet_specs, contentreference_specs


class LazyContainerFinder(object):
	def __init__(self, nodes, extends=False):
		self.nodes = nodes
		self.initialized = False
		self.contentlet_specs = []
		self.contentreference_specs = SortedDict()
		self.blocks = {}
		self.block_super = False
		self.extends = extends
	
	def process(self, nodelist):
		for node in nodelist:
			if self.extends:
				if isinstance(node, BlockNode):
					self.blocks[node.name] = block = LazyContainerFinder(node.nodelist)
					block.initialize()
					self.blocks.update(block.blocks)
				continue
			

			if isinstance(node, ContainerNode):