def service_rsd(req): """Serves and RSD definition (really simple discovery) so that blog frontends can query the apis that are available. :URL endpoint: ``blog/service_rsd`` """ return Response(generate_rsd(req.app), mimetype='application/xml')
def rss_feed(req, author=None, year=None, month=None, day=None, category=None, tag=None, post=None): feed = RssFeed( req.app.cfg['blog_title'], req.app.cfg['blog_url'], "", # Description not supported subtitle=req.app.cfg['blog_tagline'], feed_url=req.url) results = populate_feed(req, feed, author, year, month, day, category, tag, post) return Response(results, mimetype="application/rss+xml")
def json_service(req, identifier): """Handle a JSON service req.""" handler = req.app._services.get(identifier) if handler is None: raise NotFound() #! if this event returns a handler it is called instead of the default #! handler. Useful to intercept certain requests. for callback in iter_listeners('before-json-service-called'): rv = callback(identifier, handler) if rv is not None: handler = rv result = handler(req) #! called right after json callback returned some data with the identifier #! of the req method and the result object. Note that events *have* #! to return an object, even if it's just changed in place, otherwise the #! return value will be `null` (None). for callback in iter_listeners('after-json-service-called'): result = callback(identifier, result) return Response(dump_json(result), mimetype='text/javascript')
def get_resource(app, filename): """Get a resource as response object.""" parts = filename.split('/') # no folder or file with a leading dot or the special is allowed for part in parts: if part[:1] == '.': return base = _find_path(app, parts) for filename in os.path.join(base, app.cfg['language'], *parts), \ os.path.join(base, 'en', *parts): if os.path.isfile(filename): f = file(filename, 'rb') try: return Response(f.read(), mimetype=guess_type(filename)[0] or 'application/octet-stram') finally: f.close()
def open(self, data=None): """Return a `URLResponse` object.""" return Response()