# Path: web/core/compat.py



import pkg_resources
	import json
from collections import Mapping
from marrow.package.host import PluginManager
from web.core.compat import str
	from bson import json_util as json
	
	def __init__(self, default='application/json', types=(list, Mapping)):
		self.default = default
		self.types = types
	
	# ### Application-Level Callbacks
	
	def start(self, context):
		if __debug__:
			log.debug("Registering serialization return value handlers.")
		
		manager = SerializationPlugins('web.serialize')
		manager.__dict__['__isabstractmethod__'] = False
		
		context.serialize = manager
		
		# Register the serialization views supported by this extension.
		for kind in self.types:
			context.view.register(kind, self.render_serialization)
	
	# ### Views
	
	def render_serialization(self, context, result):
		"""Render serialized responses."""
		
		resp = context.response
		serial = context.serialize
		match = context.request.accept.best_match(serial.types, default_match=self.default)
		result = serial[match](result)
		

# Path: web/core/compat.py



# Path: web/ext/serialize.py
import pkg_resources
	import json
from collections import Mapping
from marrow.package.host import PluginManager
from web.core.compat import str
	from bson import json_util as json

	
	def __init__(self, default='application/json', types=(list, Mapping)):
		self.default = default
		self.types = types
	
	# ### Application-Level Callbacks
	
	def start(self, context):
		if __debug__:
			log.debug("Registering serialization return value handlers.")
		
		manager = SerializationPlugins('web.serialize')
		manager.__dict__['__isabstractmethod__'] = False
		
		context.serialize = manager
		
		# Register the serialization views supported by this extension.
		for kind in self.types:
			context.view.register(kind, self.render_serialization)
	
	# ### Views
	
	def render_serialization(self, context, result):
		"""Render serialized responses."""
		
		resp = context.response
		serial = context.serialize
		match = context.request.accept.best_match(serial.types, default_match=self.default)
		result = serial[match](result)
		

		if isinstance(result, str):