Skip to content

Commit

Permalink
Fix txrecaptcha.submit() to always return Deferreds.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
isislovecruft committed Mar 19, 2014
1 parent 17f9650 commit b4f88ad
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/bridgedb/txrecaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b4f88ad

Please sign in to comment.