# Path: web/core/context.py
# class Context(MutableMapping):
# 	"""An attribute access dictionary, of a kind.
# 	
# 	This utility class is used to cooperatively construct the ApplicationContext (and subsequent RequestContext)
# 	from the contributions of multiple extensions. The concept of "promotion to a class" is needed in order to enable
# 	the use of descriptor protocol attributes; without promotion the protocol would not be utilized.
# 	"""
# 	
# 	# M-Morty! We're, *belch*, gonna have to go in deep, Morty!  Elbow deep!
# 	def _promote(self, name, instantiate=True):
# 		"""Create a new subclass of Context which incorporates instance attributes and new descriptors.
# 		
# 		This promotes an instance and its instance attributes up to being a class with class attributes, then
# 		returns an instance of that class.
# 		"""
# 		
# 		metaclass = type(self.__class__)
# 		contents = self.__dict__.copy()
# 		cls = metaclass(str(name), (self.__class__, ), contents)
# 		
# 		if instantiate:
# 			return cls()
# 		
# 		return cls
# 	
# 	def __init__(self, **kw):
# 		"""Construct a new Context instance.
# 		
# 		All keyword arguments are applied to the instance as attributes through direct assignment to `__dict__`.
# 		"""
# 		self.__dict__.update(kw)
# 		super(Context, self).__init__()
# 	
# 	def __len__(self):
# 		"""Get a list of the public data attributes."""
# 		return len([i for i in (set(dir(self)) - self._STANDARD_ATTRS) if i[0] != '_'])
# 	
# 	def __iter__(self):
# 		"""Iterate all valid (public) attributes/keys."""
# 		return (i for i in (set(dir(self)) - self._STANDARD_ATTRS) if i[0] != '_')
# 	
# 	def __getitem__(self, name):
# 		"""Retrieve an attribute through dictionary access."""
# 		try:
# 			return getattr(self, name)
# 		except AttributeError:
# 			pass
# 		
# 		# We do this here to avoid Python 3's nested exception support.
# 		raise KeyError(name)
# 	
# 	def __setitem__(self, name, value):
# 		"""Assign an attribute through dictionary access."""
# 		setattr(self, name, value)
# 	
# 	def __delitem__(self, name):
# 		"""Delete an attribute through dictionary access."""
# 		try:
# 			return delattr(self, name)
# 		except AttributeError:
# 			pass
# 		
# 		# We do this here to avoid Python 3's nested exception support.
# 		raise KeyError(name)
# 
# Path: web/app/static.py
# def static(base, mapping=None, far=('js', 'css', 'gif', 'jpg', 'jpeg', 'png', 'ttf', 'woff')):
# 	"""Serve files from disk.
# 	
# 	This utility endpoint factory is meant primarily for use in development environments; in production environments
# 	it is better (more efficient, secure, etc.) to serve your static content using a front end load balancer such as
# 	Nginx.
# 	
# 	The first argument, `base`, represents the base path to serve files from. Paths below the attachment point for
# 	the generated endpoint will combine this base path with the remaining path elements to determine the file to
# 	serve.
# 	
# 	The second argument is an optional dictionary mapping filename extensions to template engines, for cooperation
# 	with the TemplateExtension.  (See: https://github.com/marrow/template)  The result of attempting to serve a
# 	mapped path is a 2-tuple of `("{mapping}:{path}", dict())`. For example, to render all `.html` files as Mako
# 	templates, you would attach something like the following:
# 	
# 		class Root:
# 			page = static('/path/to/static/pages', dict(html='mako'))
# 	
# 	By default the "usual culprits" are served with far-futures cache expiry headers. If you wish to change the
# 	extensions searched just assign a new `far` iterable.  To disable, assign any falsy value.
# 	"""
# 	
# 	base = abspath(base)
# 	
# 	@staticmethod
# 	def static_handler(context, *parts, **kw):
# 		path = normpath(pathjoin(base, *parts))
# 		
# 		if __debug__:
# 			log.debug("Attempting to serve static file.", extra=dict(
# 					request = id(context),
# 					base = base,
# 					path = path
# 				))
# 		
# 		if not path.startswith(base):  # Ensure we only serve files from the allowed path.
# 			raise HTTPForbidden("Cowardly refusing to violate base path policy." if __debug__ else None)
# 		
# 		if not exists(path):  # Do the right thing if the file doesn't actually exist.
# 			raise HTTPNotFound()
# 		
# 		if not isfile(path):  # Only serve normal files; no UNIX domain sockets, FIFOs, etc., etc.
# 			raise HTTPForbidden("Cowardly refusing to open a non-file." if __debug__ else None)
# 		
# 		if far and path.rpartition('.')[2] in far:
# 			context.response.cache_expires = 60*60*24*365
# 		
# 		if mapping:  # Handle the mapping of filename extensions to 2-tuples. 'Cause why not?
# 			_, _, extension = basename(path).partition('.')
# 			if extension in mapping:
# 				return mapping[extension] + ':' + path, dict()
# 		
# 		return open(path, 'rb')
# 	
# 	return static_handler


import os.path
import pytest
from webob.exc import HTTPForbidden, HTTPNotFound
from web.core.context import Context
from web.app.static import static
# encoding: utf-8

from __future__ import unicode_literals




HERE = os.path.dirname(__file__)

class Sample(object):

# Path: web/core/context.py
# class Context(MutableMapping):
# 	"""An attribute access dictionary, of a kind.
# 	
# 	This utility class is used to cooperatively construct the ApplicationContext (and subsequent RequestContext)
# 	from the contributions of multiple extensions. The concept of "promotion to a class" is needed in order to enable
# 	the use of descriptor protocol attributes; without promotion the protocol would not be utilized.
# 	"""
# 	
# 	# M-Morty! We're, *belch*, gonna have to go in deep, Morty!  Elbow deep!
# 	def _promote(self, name, instantiate=True):
# 		"""Create a new subclass of Context which incorporates instance attributes and new descriptors.
# 		
# 		This promotes an instance and its instance attributes up to being a class with class attributes, then
# 		returns an instance of that class.
# 		"""
# 		
# 		metaclass = type(self.__class__)
# 		contents = self.__dict__.copy()
# 		cls = metaclass(str(name), (self.__class__, ), contents)
# 		
# 		if instantiate:
# 			return cls()
# 		
# 		return cls
# 	
# 	def __init__(self, **kw):
# 		"""Construct a new Context instance.
# 		
# 		All keyword arguments are applied to the instance as attributes through direct assignment to `__dict__`.
# 		"""
# 		self.__dict__.update(kw)
# 		super(Context, self).__init__()
# 	
# 	def __len__(self):
# 		"""Get a list of the public data attributes."""
# 		return len([i for i in (set(dir(self)) - self._STANDARD_ATTRS) if i[0] != '_'])
# 	
# 	def __iter__(self):
# 		"""Iterate all valid (public) attributes/keys."""
# 		return (i for i in (set(dir(self)) - self._STANDARD_ATTRS) if i[0] != '_')
# 	
# 	def __getitem__(self, name):
# 		"""Retrieve an attribute through dictionary access."""
# 		try:
# 			return getattr(self, name)
# 		except AttributeError:
# 			pass
# 		
# 		# We do this here to avoid Python 3's nested exception support.
# 		raise KeyError(name)
# 	
# 	def __setitem__(self, name, value):
# 		"""Assign an attribute through dictionary access."""
# 		setattr(self, name, value)
# 	
# 	def __delitem__(self, name):
# 		"""Delete an attribute through dictionary access."""
# 		try:
# 			return delattr(self, name)
# 		except AttributeError:
# 			pass
# 		
# 		# We do this here to avoid Python 3's nested exception support.
# 		raise KeyError(name)
# 
# Path: web/app/static.py
# def static(base, mapping=None, far=('js', 'css', 'gif', 'jpg', 'jpeg', 'png', 'ttf', 'woff')):
# 	"""Serve files from disk.
# 	
# 	This utility endpoint factory is meant primarily for use in development environments; in production environments
# 	it is better (more efficient, secure, etc.) to serve your static content using a front end load balancer such as
# 	Nginx.
# 	
# 	The first argument, `base`, represents the base path to serve files from. Paths below the attachment point for
# 	the generated endpoint will combine this base path with the remaining path elements to determine the file to
# 	serve.
# 	
# 	The second argument is an optional dictionary mapping filename extensions to template engines, for cooperation
# 	with the TemplateExtension.  (See: https://github.com/marrow/template)  The result of attempting to serve a
# 	mapped path is a 2-tuple of `("{mapping}:{path}", dict())`. For example, to render all `.html` files as Mako
# 	templates, you would attach something like the following:
# 	
# 		class Root:
# 			page = static('/path/to/static/pages', dict(html='mako'))
# 	
# 	By default the "usual culprits" are served with far-futures cache expiry headers. If you wish to change the
# 	extensions searched just assign a new `far` iterable.  To disable, assign any falsy value.
# 	"""
# 	
# 	base = abspath(base)
# 	
# 	@staticmethod
# 	def static_handler(context, *parts, **kw):
# 		path = normpath(pathjoin(base, *parts))
# 		
# 		if __debug__:
# 			log.debug("Attempting to serve static file.", extra=dict(
# 					request = id(context),
# 					base = base,
# 					path = path
# 				))
# 		
# 		if not path.startswith(base):  # Ensure we only serve files from the allowed path.
# 			raise HTTPForbidden("Cowardly refusing to violate base path policy." if __debug__ else None)
# 		
# 		if not exists(path):  # Do the right thing if the file doesn't actually exist.
# 			raise HTTPNotFound()
# 		
# 		if not isfile(path):  # Only serve normal files; no UNIX domain sockets, FIFOs, etc., etc.
# 			raise HTTPForbidden("Cowardly refusing to open a non-file." if __debug__ else None)
# 		
# 		if far and path.rpartition('.')[2] in far:
# 			context.response.cache_expires = 60*60*24*365
# 		
# 		if mapping:  # Handle the mapping of filename extensions to 2-tuples. 'Cause why not?
# 			_, _, extension = basename(path).partition('.')
# 			if extension in mapping:
# 				return mapping[extension] + ':' + path, dict()
# 		
# 		return open(path, 'rb')
# 	
# 	return static_handler


# Path: test/test_app/test_static.py
import os.path
import pytest
from webob.exc import HTTPForbidden, HTTPNotFound
from web.core.context import Context
from web.app.static import static

# encoding: utf-8

from __future__ import unicode_literals




HERE = os.path.dirname(__file__)

class Sample(object):

	ep = static(HERE)