MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / apply

Method apply

21-async/mojifinder/bottle.py:1743–1763  ·  view source on GitHub ↗
(self, callback, route)

Source from the content-addressed store, hash-verified

1741 self.json_dumps = json_dumps
1742
1743 def apply(self, callback, route):
1744 dumps = self.json_dumps
1745 if not dumps: return callback
1746 def wrapper(*a, **ka):
1747 try:
1748 rv = callback(*a, **ka)
1749 except HTTPError:
1750 rv = _e()
1751
1752 if isinstance(rv, dict):
1753 #Attempt to serialize, raises exception on failure
1754 json_response = dumps(rv)
1755 #Set content type only if serialization succesful
1756 response.content_type = 'application/json'
1757 return json_response
1758 elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict):
1759 rv.body = dumps(rv.body)
1760 rv.content_type = 'application/json'
1761 return rv
1762
1763 return wrapper
1764
1765
1766class TemplatePlugin(object):

Callers 2

_make_callbackMethod · 0.45
_castMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected