1. Juarez Bochi
  2. wtforms-recaptcha

Commits

Juarez Bochi  committed 3a9fea2

Added support to http proxy

  • Participants
  • Parent commits 7804111
  • Branches default

Comments (0)

Files changed (2)

File wtfrecaptcha/fields.py

View file
  • Ignore whitespace
 
     widget = widgets.Recaptcha()
 
-    def __init__(self, label='', validators=None, public_key=None, private_key=None, secure=False, **kwargs):
+    def __init__(self, label='', validators=None, public_key=None, private_key=None, secure=False, http_proxy=None, **kwargs):
         # Pretty useless without the Recaptcha validator but still
         # user may want to subclass it, so keep it optional
         validators = validators or [local_validators.Recaptcha()]
         self.public_key = public_key
         self.private_key = private_key
         self.secure = secure
+        self.http_proxy = http_proxy
 
         self.ip_address = None
         self.challenge = None

File wtfrecaptcha/validators.py

View file
  • Ignore whitespace
     empty_error_text = u'This field is required'
     internal_error_text = u'Internal error, please try again later'
 
-    def _call_verify(self, params):
+    def _call_verify(self, params, proxy):
         """Performs a call to reCaptcha API with given params"""
         data = []
+        if proxy:
+            proxy_handler = urllib2.ProxyHandler({'http': proxy})
+            opener = urllib2.build_opener(proxy_handler)
+            urllib2.install_opener(opener)
+
         try:
             response = urllib2.urlopen('http://www.google.com/recaptcha/api/verify',
                     data=urlencode(params))
                   ('challenge', field.challenge),
                   ('response', field.data))
 
-        data = self._call_verify(params)
+        data = self._call_verify(params, field.http_proxy)
         if data[0] == 'false':
             # Show only incorrect solution to the user else show default message
             if data[1] == 'incorrect-captcha-sol':