[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r19321: {bridgedb} Add support for a "plain" html response format. (bridgedb/trunk/lib/bridgedb)



Author: nickm
Date: 2009-04-14 15:19:15 -0400 (Tue, 14 Apr 2009)
New Revision: 19321

Modified:
   bridgedb/trunk/lib/bridgedb/Server.py
Log:
Add support for a "plain" html response format.

Modified: bridgedb/trunk/lib/bridgedb/Server.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Server.py	2009-04-14 15:23:12 UTC (rev 19320)
+++ bridgedb/trunk/lib/bridgedb/Server.py	2009-04-14 19:19:15 UTC (rev 19321)
@@ -46,6 +46,16 @@
 </body></html>
 """.strip()
 
+PLAIN_HTML_MESSAGE_TEMPLATE = """
+<html><body>
+<p>Here are your bridge relays:
+<pre id="bridges">
+%s
+</pre>
+</p>
+</body></html>
+"""
+
 EMAIL_MESSAGE_TEMPLATE = """\
 [This is an automated message; please do not reply.]
 
@@ -102,6 +112,8 @@
         else:
             ip = request.getClientIP()
 
+        format = request.args.get("format", None)
+
         if ip:
             bridges = self.distributor.getBridgesForIP(ip, interval,
                                                        self.nBridgesToGive)
@@ -111,7 +123,10 @@
             answer = "No bridges available."
 
         logging.info("Replying to web request from %s", ip)
-        return HTML_MESSAGE_TEMPLATE % answer
+        if format == 'plain':
+            return PLAIN_HTML_MESSAGE_TEMPLATE % answer
+        else:
+            return HTML_MESSAGE_TEMPLATE % answer
 
 def addWebServer(cfg, dist, sched):
     """Set up a web server.