From 484432d804e5b832a4cc9bcf214329ef2e883233 Mon Sep 17 00:00:00 2001 From: pictuga Date: Sat, 28 Jun 2014 00:59:57 +0200 Subject: [PATCH] Add :callback for JSONP calls --- README.md | 1 + morss/morss.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c78006..2797ca6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ The arguments are: - `theforce`: force download the rss feed - `silent`: don't output the final RSS (useless on its own, but can be nice when debugging) - http server only + - `callback=NAME`: for JSONP calls - `cors`: allow Cross-origin resource sharing (allows XHR calls from other servers) - `html`: changes the http content-type to html, so that python cgi erros (written in html) are readable in a web browser - `txt`: changes the http content-type to txt (for faster "`view-source:`") diff --git a/morss/morss.py b/morss/morss.py index d6291d4..439bd16 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -693,7 +693,9 @@ def After(rss, options): if item.content: item.content = conv.handle(item.content) - if options.json: + if re.match(r'^[a-zA-Z0-9\.]+$', options.callback) is not None: + return '%s(%s)' % (options.callback, rss.tojson()) + elif options.json: if options.indent: return rss.tojson(indent=4) else: