# Path: philo/utils/lazycompat.py
# class SimpleLazyObject(LazyObject):
# 	"""
# 	A lazy object initialised from any function.
# 
# 	Designed for compound objects of unknown type. For builtins or objects of
# 	known type, use django.utils.functional.lazy.
# 	"""
# 	def __init__(self, func):
# 		"""
# 		Pass in a callable that returns the object to be wrapped.
# 
# 		If copies are made of the resulting SimpleLazyObject, which can happen
# 		in various circumstances within Django, then you must ensure that the
# 		callable can be safely run more than once and will return the same
# 		value.
# 		"""
# 		self.__dict__['_setupfunc'] = func
# 		super(SimpleLazyObject, self).__init__()
# 
# 	def _setup(self):
# 		self._wrapped = self._setupfunc()
# 
# 	__str__ = new_method_proxy(str)
# 	__unicode__ = new_method_proxy(unicode)
# 
# 	def __deepcopy__(self, memo):
# 		if self._wrapped is empty:
# 			# We have to use SimpleLazyObject, not self.__class__, because the
# 			# latter is proxied.
# 			result = SimpleLazyObject(self._setupfunc)
# 			memo[id(self)] = result
# 			return result
# 		else:
# 			import copy
# 			return copy.deepcopy(self._wrapped, memo)
# 
# 	# Need to pretend to be the wrapped class, for the sake of objects that care
# 	# about this (especially in equality tests)
# 	__class__ = property(new_method_proxy(operator.attrgetter("__class__")))
# 	__eq__ = new_method_proxy(operator.eq)
# 	__hash__ = new_method_proxy(hash)
# 	__nonzero__ = new_method_proxy(bool)


from functools import partial
from UserDict import DictMixin
from django.db import models
from django.contrib.contenttypes.models import ContentType
from philo.utils.lazycompat import SimpleLazyObject
		from philo.models.base import JSONValue, ForeignKeyValue, ManyToManyValue, Attribute
		from philo.models.base import Attribute
		from philo.models import Attribute
		from philo.models import Attribute
		from philo.models import Attribute
		from philo.models import Attribute
		return self._cache.keys()
	
	def items(self):
		"""Returns the items from the cache, first populating the cache if necessary."""
		if not self._cache_filled:
			self._fill_cache()
		return self._cache.items()
	
	def values(self):
		"""Returns the values from the cache, first populating the cache if necessary."""
		if not self._cache_filled:
			self._fill_cache()
		return self._cache.values()
	
	def _fill_cache(self):
		if self._cache_filled:
			return
		
		attributes = self.get_attributes()
		value_lookups = {}
		
		for a in attributes:
			value_lookups.setdefault(a.value_content_type_id, []).append(a.value_object_id)
			self._attributes_cache[a.key] = a
		
		values_bulk = dict(((ct_pk, SimpleLazyObject(partial(ContentType.objects.get_for_id(ct_pk).model_class().objects.in_bulk, pks))) for ct_pk, pks in value_lookups.items()))
		
		cache = {}
		
		for a in attributes:

# Path: philo/utils/lazycompat.py
# class SimpleLazyObject(LazyObject):
# 	"""
# 	A lazy object initialised from any function.
# 
# 	Designed for compound objects of unknown type. For builtins or objects of
# 	known type, use django.utils.functional.lazy.
# 	"""
# 	def __init__(self, func):
# 		"""
# 		Pass in a callable that returns the object to be wrapped.
# 
# 		If copies are made of the resulting SimpleLazyObject, which can happen
# 		in various circumstances within Django, then you must ensure that the
# 		callable can be safely run more than once and will return the same
# 		value.
# 		"""
# 		self.__dict__['_setupfunc'] = func
# 		super(SimpleLazyObject, self).__init__()
# 
# 	def _setup(self):
# 		self._wrapped = self._setupfunc()
# 
# 	__str__ = new_method_proxy(str)
# 	__unicode__ = new_method_proxy(unicode)
# 
# 	def __deepcopy__(self, memo):
# 		if self._wrapped is empty:
# 			# We have to use SimpleLazyObject, not self.__class__, because the
# 			# latter is proxied.
# 			result = SimpleLazyObject(self._setupfunc)
# 			memo[id(self)] = result
# 			return result
# 		else:
# 			import copy
# 			return copy.deepcopy(self._wrapped, memo)
# 
# 	# Need to pretend to be the wrapped class, for the sake of objects that care
# 	# about this (especially in equality tests)
# 	__class__ = property(new_method_proxy(operator.attrgetter("__class__")))
# 	__eq__ = new_method_proxy(operator.eq)
# 	__hash__ = new_method_proxy(hash)
# 	__nonzero__ = new_method_proxy(bool)


# Path: philo/utils/entities.py
from functools import partial
from UserDict import DictMixin
from django.db import models
from django.contrib.contenttypes.models import ContentType
from philo.utils.lazycompat import SimpleLazyObject
		from philo.models.base import JSONValue, ForeignKeyValue, ManyToManyValue, Attribute
		from philo.models.base import Attribute
		from philo.models import Attribute
		from philo.models import Attribute
		from philo.models import Attribute
		from philo.models import Attribute

		return self._cache.keys()
	
	def items(self):
		"""Returns the items from the cache, first populating the cache if necessary."""
		if not self._cache_filled:
			self._fill_cache()
		return self._cache.items()
	
	def values(self):
		"""Returns the values from the cache, first populating the cache if necessary."""
		if not self._cache_filled:
			self._fill_cache()
		return self._cache.values()
	
	def _fill_cache(self):
		if self._cache_filled:
			return
		
		attributes = self.get_attributes()
		value_lookups = {}
		
		for a in attributes:
			value_lookups.setdefault(a.value_content_type_id, []).append(a.value_object_id)
			self._attributes_cache[a.key] = a
		
		values_bulk = dict(((ct_pk, SimpleLazyObject(partial(ContentType.objects.get_for_id(ct_pk).model_class().objects.in_bulk, pks))) for ct_pk, pks in value_lookups.items()))
		
		cache = {}
		
		for a in attributes:

			cache[a.key] = SimpleLazyObject(partial(self._lazy_value_from_bulk, values_bulk, a))