[tor-commits] [bridgedb/develop] Add ReCaptchaProtectedResource._renderDeferred() to render deferred resources.
isis at torproject.org
isis at torproject.org
Wed Mar 26 05:49:31 UTC 2014
commit db8eef49536f0c18891bdf1f5151733e07ffc8d3
Author: Isis Lovecruft <isis at torproject.org>
Date: Tue Mar 25 22:28:45 2014 +0000
Add ReCaptchaProtectedResource._renderDeferred() to render deferred resources.
---
lib/bridgedb/HTTPServer.py | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/lib/bridgedb/HTTPServer.py b/lib/bridgedb/HTTPServer.py
index e2f1059..4c5d414 100644
--- a/lib/bridgedb/HTTPServer.py
+++ b/lib/bridgedb/HTTPServer.py
@@ -367,6 +367,39 @@ class ReCaptchaProtectedResource(CaptchaProtectedResource):
self.recaptchaPubKey = recaptchaPubKey
self.recaptchaRemoteIP = remoteip
+ def _renderDeferred(self, checkedRequest):
+ """Render this resource asynchronously.
+
+ :type checkedRequest: tuple
+ :param checkedRequest: A tuple of ``(bool, request)``, as returned
+ from :meth:`checkSolution`.
+ """
+ try:
+ valid, request = checkedRequest
+ except Exception as err:
+ logging.error("Error in _renderDeferred(): %s" % err)
+ return
+
+ logging.debug("Attemping to render %svalid request %r"
+ % ('' if valid else 'in', request))
+ if valid is True:
+ try:
+ rendered = self.resource.render(request)
+ except Exception as err: # pragma: no cover
+ rendered = replaceErrorPage(err)
+ else:
+ logging.info("Client failed a CAPTCHA; redirecting to %s"
+ % request.uri)
+ rendered = redirectTo(request.uri, request)
+
+ try:
+ request.write(rendered)
+ request.finish()
+ except Exception as err: # pragma: no cover
+ logging.exception(err)
+
+ return request
+
def getCaptchaImage(self, request):
"""Get a CAPTCHA image from the remote reCaptcha server.
More information about the tor-commits
mailing list