# Path: philo/exceptions.py
# class ViewCanNotProvideSubpath(Exception):
# 	"""Raised by :meth:`.View.reverse` when the :class:`.View` can not provide a subpath for the supplied arguments."""
# 	silent_variable_failure = True


from django import template
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse, NoReverseMatch
from django.template.defaulttags import kwarg_re
from django.utils.encoding import smart_str
from philo.exceptions import ViewCanNotProvideSubpath

class NodeURLNode(template.Node):
	def __init__(self, node, as_var, with_obj=None, view_name=None, args=None, kwargs=None):
		self.as_var = as_var
		self.view_name = view_name
		
		# Because the following variables have already been compiled as filters if they exist, they don't need to be re-scanned as template variables.
		self.node = node
		self.with_obj = with_obj
		self.args = args
		self.kwargs = kwargs
	
	def render(self, context):
		if self.node:
			node = self.node.resolve(context)
		else:
			node = context.get('node', None)
		
		if not node:
			return settings.TEMPLATE_STRING_IF_INVALID
		
		if self.with_obj is None and self.view_name is None:
			url = node.get_absolute_url()
		else:
			if not node.accepts_subpath:
				return settings.TEMPLATE_STRING_IF_INVALID
			
			if self.with_obj is not None:
				try:
					view_name, args, kwargs = node.view.get_reverse_params(self.with_obj.resolve(context))

# Path: philo/exceptions.py
# class ViewCanNotProvideSubpath(Exception):
# 	"""Raised by :meth:`.View.reverse` when the :class:`.View` can not provide a subpath for the supplied arguments."""
# 	silent_variable_failure = True


# Path: philo/templatetags/nodes.py
from django import template
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse, NoReverseMatch
from django.template.defaulttags import kwarg_re
from django.utils.encoding import smart_str
from philo.exceptions import ViewCanNotProvideSubpath


class NodeURLNode(template.Node):
	def __init__(self, node, as_var, with_obj=None, view_name=None, args=None, kwargs=None):
		self.as_var = as_var
		self.view_name = view_name
		
		# Because the following variables have already been compiled as filters if they exist, they don't need to be re-scanned as template variables.
		self.node = node
		self.with_obj = with_obj
		self.args = args
		self.kwargs = kwargs
	
	def render(self, context):
		if self.node:
			node = self.node.resolve(context)
		else:
			node = context.get('node', None)
		
		if not node:
			return settings.TEMPLATE_STRING_IF_INVALID
		
		if self.with_obj is None and self.view_name is None:
			url = node.get_absolute_url()
		else:
			if not node.accepts_subpath:
				return settings.TEMPLATE_STRING_IF_INVALID
			
			if self.with_obj is not None:
				try:
					view_name, args, kwargs = node.view.get_reverse_params(self.with_obj.resolve(context))

				except ViewCanNotProvideSubpath: