# Path: web/core/compat.py



import time
from web.core.compat import unicode
	__slots__ = ('header', 'log')
	
	first = True  # We need this processing to happen as early as possible.
	provides = ['analytics']  # Expose this symbol for other extensions to depend upon.
	
	def __init__(self, header='X-Generation-Time', level='debug'):
		"""Executed to configure the extension."""
		
		super(AnalyticsExtension, self).__init__()
		
		# Record settings.
		self.header = header
		self.log = getattr(log, level) if level else None
	
	# ### Request-Local Callabacks
	
	def prepare(self, context):
		"""Executed during request set-up."""
		
		context._start_time = None
	
	def before(self, context):
		"""Executed after all extension prepare methods have been called, prior to dispatch."""
		
		context._start_time = time.time()
	
	def after(self, context, exc=None):
		"""Executed after dispatch has returned and the response populated, prior to anything being sent to the client."""
		
		duration = context._duration = round((time.time() - context._start_time) * 1000)  # Convert to ms.

# Path: web/core/compat.py



# Path: web/ext/analytics.py
import time
from web.core.compat import unicode

	__slots__ = ('header', 'log')
	
	first = True  # We need this processing to happen as early as possible.
	provides = ['analytics']  # Expose this symbol for other extensions to depend upon.
	
	def __init__(self, header='X-Generation-Time', level='debug'):
		"""Executed to configure the extension."""
		
		super(AnalyticsExtension, self).__init__()
		
		# Record settings.
		self.header = header
		self.log = getattr(log, level) if level else None
	
	# ### Request-Local Callabacks
	
	def prepare(self, context):
		"""Executed during request set-up."""
		
		context._start_time = None
	
	def before(self, context):
		"""Executed after all extension prepare methods have been called, prior to dispatch."""
		
		context._start_time = time.time()
	
	def after(self, context, exc=None):
		"""Executed after dispatch has returned and the response populated, prior to anything being sent to the client."""
		
		duration = context._duration = round((time.time() - context._start_time) * 1000)  # Convert to ms.

		delta = unicode(duration)