[tor-commits] [bridgedb/master] Fix txrecaptcha.submit() to always return Deferreds.

isis at torproject.org isis at torproject.org
Wed Mar 26 05:49:32 UTC 2014


commit b4f88aded4fd6cc60be0129e1b6d0bd708d392c7
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed Mar 19 18:30:12 2014 +0000

    Fix txrecaptcha.submit() to always return Deferreds.
    
    All returned Deferreds callback with RecaptchaResponse objects. This
    way, we do not need additional code to check if the result was a
    Deferred (because, in that case, we would need to add a callback
    function to extract the RecaptchaResponse object from it and check it),
    or if it directly returned a RecaptchaResponse.
    
    This function now *always* returns Deferred.
---
 lib/bridgedb/txrecaptcha.py |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/bridgedb/txrecaptcha.py b/lib/bridgedb/txrecaptcha.py
index e1e3234..2185112 100644
--- a/lib/bridgedb/txrecaptcha.py
+++ b/lib/bridgedb/txrecaptcha.py
@@ -213,12 +213,12 @@ def submit(recaptcha_challenge_field, recaptcha_response_field,
     :returns: A :api:`~twisted.internet.defer.Deferred` which will callback
         with a ``recaptcha.RecaptchaResponse`` for the request.
     """
-    if not (recaptcha_response_field and
-            recaptcha_challenge_field and
-            len(recaptcha_response_field) and
-            len(recaptcha_challenge_field)):
-        return RecaptchaResponse(is_valid=False,
-                                 error_code='incorrect-captcha-sol')
+    if not (recaptcha_response_field and len(recaptcha_response_field) and
+            recaptcha_challenge_field and len(recaptcha_challenge_field)):
+        d = defer.Deferred()
+        d.addBoth(_ebRequest)  # We want `is_valid=False`
+        d.errback(failure.Failure(ValueError('incorrect-captcha-sol')))
+        return d
 
     params = urllib.urlencode({
         'privatekey': _encodeIfNecessary(private_key),





More information about the tor-commits mailing list