George Notaras avatar George Notaras committed c6629ce

Renamed package (backwards incompatible change)

Comments (0)

Files changed (20)

src/recaptcha_works/__init__.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+VERSION = (0, 2, 4, 'final', 0)
+
+def get_version():
+    version = '%d.%d.%d' % (VERSION[0], VERSION[1], VERSION[2])
+    return version
+
+
+long_description = """
+*django-recaptcha-works* provides a Django form field that integrates the
+reCaptcha service. It is released under the terms of the BSD License.
+
+This reCaptcha implementation has no extra requirements other than Django.
+
+The app is based on the code `snippet 1644 <http://djangosnippets.org/snippets/1644/>`_
+as published by *Chris Beaven* (aka SmileyChris).
+
+The original code has been further modified by *George Notaras* in order to
+implement the following:
+
+- transform the snippet to a Django application release
+- add SSL support for both the captcha presentation and the communication with the reCaptcha servers 
+- migration to the Google-hosted reCaptcha API
+- extension of the available application settings
+- addition of a decorator that adds the remote IP to the submitted form
+
+More information about the installation, configuration and usage of this
+application can be found in the *HELP* file inside the distribution package
+or in the project's
+`wiki <http://www.codetrax.org/projects/django-recaptcha-works/wiki>`_.
+
+In case you run into any problems while using this application it is highly
+recommended you file a bug report at the project's
+`issue tracker <http://www.codetrax.org/projects/django-recaptcha-works/issues>`_.
+
+"""

src/recaptcha_works/decorators.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+from django.utils.decorators import available_attrs
+try:
+    from functools import wraps
+except ImportError:
+    from django.utils.functional import wraps  # Python 2.4 fallback.
+
+from recaptchaworks.utils import post_payload_add_recaptcha_remote_ip_field
+
+
+def fix_recaptcha_remote_ip(view_func):
+    """
+    Modifies a view function so that its request object's POST payload
+    contains a ``recaptcha_remote_ip_field`` field, which required for
+    proper reCaptcha functionality.
+    
+    """
+    def wrapped_view(*args, **kwargs):
+        args = list(args)
+        args[0] = post_payload_add_recaptcha_remote_ip_field(args[0])
+        resp = view_func(*args, **kwargs)
+        return resp
+    return wraps(view_func, assigned=available_attrs(view_func))(wrapped_view)
+

src/recaptcha_works/exceptions.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+class RecaptchaError(Exception):
+    def __init__(self, code):
+        self.code = code
+
+    def __str__(self):
+        return self.code
+

src/recaptcha_works/fields.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+from django import forms
+
+from recaptchaworks.widgets import RecaptchaWidget
+from recaptchaworks import settings
+from recaptchaworks.exceptions import RecaptchaError
+from recaptchaworks.utils import validate_recaptcha
+
+
+class RecaptchaField(forms.Field):
+    
+    default_error_messages = {
+        'required': u'Please enter the CAPTCHA solution.',
+        'invalid': u'An incorrect CAPTCHA solution was entered.',
+        'no-remote-ip': u'CAPTCHA failed due to no visible IP address.',
+        'challenge-error': u'An error occurred with the CAPTCHA service - try '
+            'refreshing.',
+        'unknown-error': u'The CAPTCHA service returned the following error: '
+            '%(code)s.',
+    }
+
+    def __init__(self, private_key=None, public_key=None, use_ssl=False,
+                recaptcha_options=None, *args, **kwargs):
+        """Field constructor
+        
+        The optional ``public_key`` argument can be used to override the
+        default use of the project-wide ``RECAPTCHA_PUBLIC_KEY`` setting.
+        
+        The optional ``private_key`` argument can be used to override the
+        default use of the project-wide ``RECAPTCHA_PRIVATE_KEY`` setting.
+        
+        The optional ``use_ssl`` argument can be used to override the default
+        use of the project-wide ``RECAPTCHA_USE_SSL`` setting.
+        
+        The optional ``recaptcha_options`` argument can be used to override
+        the default project wide ``RECAPTCHA_OPTIONS`` setting.
+        
+        """
+        self.private_key = private_key or settings.RECAPTCHA_PRIVATE_KEY
+        self.use_ssl = use_ssl or settings.RECAPTCHA_USE_SSL
+        kwargs['widget'] = RecaptchaWidget(public_key, use_ssl, recaptcha_options)
+        super(RecaptchaField, self).__init__(*args, **kwargs)
+
+    def clean(self, value):
+        
+        value = super(RecaptchaField, self).clean(value)
+        challenge, response, remote_ip = value
+        if not challenge:
+            raise forms.ValidationError(self.error_messages['challenge-error'])
+        if not response:
+            raise forms.ValidationError(self.error_messages['required'])
+        if not remote_ip:
+            raise forms.ValidationError(self.error_messages['no-remote-ip'])
+        try:
+            value = validate_recaptcha(remote_ip, challenge, response,
+                                       self.private_key, self.use_ssl)
+        except RecaptchaError, e:
+            if e.code == 'incorrect-captcha-sol':
+                raise forms.ValidationError(self.error_messages['invalid'])
+            raise forms.ValidationError(self.error_messages['unknown-error'] %
+                                        {'code': e.code})
+        return value
+

src/recaptcha_works/models.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#

src/recaptcha_works/settings.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+from django.conf import settings
+
+
+RECAPTCHA_PRIVATE_KEY = getattr(settings, 'RECAPTCHA_PRIVATE_KEY', '')
+RECAPTCHA_PUBLIC_KEY = getattr(settings, 'RECAPTCHA_PUBLIC_KEY', '')
+RECAPTCHA_USE_SSL = getattr(settings, 'RECAPTCHA_USE_SSL', True)
+
+# See the following page for valid options:
+# http://code.google.com/apis/recaptcha/docs/customization.html
+_RECAPTCHA_OPTIONS = {
+    'theme': 'red',
+    'lang': 'en',
+    'tabindex': 0,
+    #'custom_translations': {},
+    #'custom_theme_widget': None
+    }
+RECAPTCHA_OPTIONS = getattr(settings, 'RECAPTCHA_OPTIONS', _RECAPTCHA_OPTIONS)
+
+_RECAPTCHA_HTML = u'''
+%(options)s
+<script type="text/javascript"
+   src="%(proto)s://www.google.com/recaptcha/api/challenge?k=%(public_key)s">
+</script>
+<noscript>
+   <iframe src="%(proto)s://www.google.com/recaptcha/api/noscript?k=%(public_key)s"
+       height="300" width="500" frameborder="0"></iframe><br>
+   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
+   </textarea>
+   <input type="hidden" name="recaptcha_response_field" value="manual_challenge">
+</noscript>
+'''
+RECAPTCHA_HTML = getattr(settings, 'RECAPTCHA_HTML', _RECAPTCHA_HTML)
+

src/recaptcha_works/tests.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}

src/recaptcha_works/utils.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+import httplib
+from django.utils.http import urlencode
+
+from recaptchaworks.exceptions import RecaptchaError
+
+
+def validate_recaptcha(remote_ip, challenge, response, private_key, use_ssl):
+    assert challenge, 'No challenge was provided for reCaptcha validation'
+    # Request validation from recaptcha.net
+    params = dict(privatekey=private_key, remoteip=remote_ip,
+                  challenge=challenge, response=response)
+    params = urlencode(params)
+    headers = {"Content-type": "application/x-www-form-urlencoded",
+               "Accept": "text/plain"}
+    if use_ssl:
+        conn = httplib.HTTPSConnection("www.google.com")
+    else:
+        conn = httplib.HTTPConnection("www.google.com")
+    conn.request("POST", "/recaptcha/api/verify", params, headers)
+    response = conn.getresponse()
+    if response.status == 200:
+        data = response.read()
+    else:
+        data = ''
+    conn.close()
+    # Validate based on response data
+    result = data.startswith('true')
+    if not result:
+        bits = data.split('\n', 2)
+        error_code = ''
+        if len(bits) > 1:
+            error_code = bits[1]
+        raise RecaptchaError(error_code)
+    # Return dictionary
+    return result
+
+
+def post_payload_add_recaptcha_remote_ip_field(request):
+    if request.method == 'POST':
+        if 'recaptcha_challenge_field' in request.POST and 'recaptcha_response_field' in request.POST:
+            # This is a recaptcha protected form
+            data = request.POST.copy()
+            data['recaptcha_remote_ip_field'] = request.META['REMOTE_ADDR']
+            request.POST = data
+    return request
+

src/recaptcha_works/views.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#

src/recaptcha_works/widgets.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-recaptcha-works.
+#
+#  django-recaptcha-works provides a Django form field that integrates the
+#  reCaptcha service.
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-recaptcha-works
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-recaptcha-works
+#
+#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Based on the code snippet #1644 as published on:
+#    - http://djangosnippets.org/snippets/1644/
+#
+#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
+#
+#  Licensed under the BSD License.
+#
+#  Redistribution and use in source and binary forms, with or without modification,
+#  are permitted provided that the following conditions are met:
+#
+#      1. Redistributions of source code must retain the above copyright notice, 
+#         this list of conditions and the following disclaimer.
+#      
+#      2. Redistributions in binary form must reproduce the above copyright 
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#
+#      3. Neither the name of Django nor the names of its contributors may be used
+#         to endorse or promote products derived from this software without
+#         specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+from django import forms
+from django.utils.safestring import mark_safe
+from django.utils import simplejson
+
+from recaptchaworks import settings
+
+
+class RecaptchaWidget(forms.Widget):
+    
+    RECAPTCHA_OPTIONS_SCRIPT = u'''<script type="text/javascript">
+var RecaptchaOptions = {
+%s
+};
+</script>
+'''
+    
+    def __init__(self, public_key=None, use_ssl=False, recaptcha_options=None):
+        '''RecaptchaWidget constructor
+        
+        For customization information visit:
+        
+        http://code.google.com/apis/recaptcha/docs/customization.html
+        
+        The optional ``recaptcha_options`` argument can be used to override
+        the default project wide ``RECAPTCHA_OPTIONS`` setting.
+        
+        The optional ``public_key`` argument can be used to override the
+        default use of the project-wide ``RECAPTCHA_PUBLIC_KEY`` setting.
+        
+        The optional ``use_ssl`` argument can be used to override the default
+        use of the project-wide ``RECAPTCHA_USE_SSL`` setting.
+        '''
+        self.options = recaptcha_options
+        if recaptcha_options is None:
+            self.options = settings.RECAPTCHA_OPTIONS
+        
+        self.proto = 'http'
+        if use_ssl or settings.RECAPTCHA_USE_SSL:
+            self.proto = 'https'
+        
+        self.public_key = public_key or settings.RECAPTCHA_PUBLIC_KEY
+        
+        super(RecaptchaWidget, self).__init__()
+
+    def render(self, name, value, attrs=None):
+        args = dict(public_key=self.public_key, proto=self.proto, options='')
+        if self.options:
+            args['options'] = self.RECAPTCHA_OPTIONS_SCRIPT % simplejson.dumps(
+                self.options, indent=4).strip('{}')
+        return mark_safe(settings.RECAPTCHA_HTML % args)
+
+    def value_from_datadict(self, data, files, name):
+        challenge = data.get('recaptcha_challenge_field')
+        response = data.get('recaptcha_response_field')
+        # This is added by utils.post_payload_add_recaptcha_remote_ip_field()
+        remote_ip = data.get('recaptcha_remote_ip_field')
+        return (challenge, response, remote_ip)
+
+    def id_for_label(self, id_):
+        return None
+

src/recaptchaworks/__init__.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-VERSION = (0, 2, 4, 'final', 0)
-
-def get_version():
-    version = '%d.%d.%d' % (VERSION[0], VERSION[1], VERSION[2])
-    return version
-
-
-long_description = """
-*django-recaptcha-works* provides a Django form field that integrates the
-reCaptcha service. It is released under the terms of the BSD License.
-
-This reCaptcha implementation has no extra requirements other than Django.
-
-The app is based on the code `snippet 1644 <http://djangosnippets.org/snippets/1644/>`_
-as published by *Chris Beaven* (aka SmileyChris).
-
-The original code has been further modified by *George Notaras* in order to
-implement the following:
-
-- transform the snippet to a Django application release
-- add SSL support for both the captcha presentation and the communication with the reCaptcha servers 
-- migration to the Google-hosted reCaptcha API
-- extension of the available application settings
-- addition of a decorator that adds the remote IP to the submitted form
-
-More information about the installation, configuration and usage of this
-application can be found in the *HELP* file inside the distribution package
-or in the project's
-`wiki <http://www.codetrax.org/projects/django-recaptcha-works/wiki>`_.
-
-In case you run into any problems while using this application it is highly
-recommended you file a bug report at the project's
-`issue tracker <http://www.codetrax.org/projects/django-recaptcha-works/issues>`_.
-
-"""

src/recaptchaworks/decorators.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django.utils.decorators import available_attrs
-try:
-    from functools import wraps
-except ImportError:
-    from django.utils.functional import wraps  # Python 2.4 fallback.
-
-from recaptchaworks.utils import post_payload_add_recaptcha_remote_ip_field
-
-
-def fix_recaptcha_remote_ip(view_func):
-    """
-    Modifies a view function so that its request object's POST payload
-    contains a ``recaptcha_remote_ip_field`` field, which required for
-    proper reCaptcha functionality.
-    
-    """
-    def wrapped_view(*args, **kwargs):
-        args = list(args)
-        args[0] = post_payload_add_recaptcha_remote_ip_field(args[0])
-        resp = view_func(*args, **kwargs)
-        return resp
-    return wraps(view_func, assigned=available_attrs(view_func))(wrapped_view)
-

src/recaptchaworks/exceptions.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-
-class RecaptchaError(Exception):
-    def __init__(self, code):
-        self.code = code
-
-    def __str__(self):
-        return self.code
-

src/recaptchaworks/fields.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django import forms
-
-from recaptchaworks.widgets import RecaptchaWidget
-from recaptchaworks import settings
-from recaptchaworks.exceptions import RecaptchaError
-from recaptchaworks.utils import validate_recaptcha
-
-
-class RecaptchaField(forms.Field):
-    
-    default_error_messages = {
-        'required': u'Please enter the CAPTCHA solution.',
-        'invalid': u'An incorrect CAPTCHA solution was entered.',
-        'no-remote-ip': u'CAPTCHA failed due to no visible IP address.',
-        'challenge-error': u'An error occurred with the CAPTCHA service - try '
-            'refreshing.',
-        'unknown-error': u'The CAPTCHA service returned the following error: '
-            '%(code)s.',
-    }
-
-    def __init__(self, private_key=None, public_key=None, use_ssl=False,
-                recaptcha_options=None, *args, **kwargs):
-        """Field constructor
-        
-        The optional ``public_key`` argument can be used to override the
-        default use of the project-wide ``RECAPTCHA_PUBLIC_KEY`` setting.
-        
-        The optional ``private_key`` argument can be used to override the
-        default use of the project-wide ``RECAPTCHA_PRIVATE_KEY`` setting.
-        
-        The optional ``use_ssl`` argument can be used to override the default
-        use of the project-wide ``RECAPTCHA_USE_SSL`` setting.
-        
-        The optional ``recaptcha_options`` argument can be used to override
-        the default project wide ``RECAPTCHA_OPTIONS`` setting.
-        
-        """
-        self.private_key = private_key or settings.RECAPTCHA_PRIVATE_KEY
-        self.use_ssl = use_ssl or settings.RECAPTCHA_USE_SSL
-        kwargs['widget'] = RecaptchaWidget(public_key, use_ssl, recaptcha_options)
-        super(RecaptchaField, self).__init__(*args, **kwargs)
-
-    def clean(self, value):
-        
-        value = super(RecaptchaField, self).clean(value)
-        challenge, response, remote_ip = value
-        if not challenge:
-            raise forms.ValidationError(self.error_messages['challenge-error'])
-        if not response:
-            raise forms.ValidationError(self.error_messages['required'])
-        if not remote_ip:
-            raise forms.ValidationError(self.error_messages['no-remote-ip'])
-        try:
-            value = validate_recaptcha(remote_ip, challenge, response,
-                                       self.private_key, self.use_ssl)
-        except RecaptchaError, e:
-            if e.code == 'incorrect-captcha-sol':
-                raise forms.ValidationError(self.error_messages['invalid'])
-            raise forms.ValidationError(self.error_messages['unknown-error'] %
-                                        {'code': e.code})
-        return value
-

src/recaptchaworks/models.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#

src/recaptchaworks/settings.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django.conf import settings
-
-
-RECAPTCHA_PRIVATE_KEY = getattr(settings, 'RECAPTCHA_PRIVATE_KEY', '')
-RECAPTCHA_PUBLIC_KEY = getattr(settings, 'RECAPTCHA_PUBLIC_KEY', '')
-RECAPTCHA_USE_SSL = getattr(settings, 'RECAPTCHA_USE_SSL', True)
-
-# See the following page for valid options:
-# http://code.google.com/apis/recaptcha/docs/customization.html
-_RECAPTCHA_OPTIONS = {
-    'theme': 'red',
-    'lang': 'en',
-    'tabindex': 0,
-    #'custom_translations': {},
-    #'custom_theme_widget': None
-    }
-RECAPTCHA_OPTIONS = getattr(settings, 'RECAPTCHA_OPTIONS', _RECAPTCHA_OPTIONS)
-
-_RECAPTCHA_HTML = u'''
-%(options)s
-<script type="text/javascript"
-   src="%(proto)s://www.google.com/recaptcha/api/challenge?k=%(public_key)s">
-</script>
-<noscript>
-   <iframe src="%(proto)s://www.google.com/recaptcha/api/noscript?k=%(public_key)s"
-       height="300" width="500" frameborder="0"></iframe><br>
-   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
-   </textarea>
-   <input type="hidden" name="recaptcha_response_field" value="manual_challenge">
-</noscript>
-'''
-RECAPTCHA_HTML = getattr(settings, 'RECAPTCHA_HTML', _RECAPTCHA_HTML)
-

src/recaptchaworks/tests.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-"""
-This file demonstrates two different styles of tests (one doctest and one
-unittest). These will both pass when you run "manage.py test".
-
-Replace these with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-class SimpleTest(TestCase):
-    def test_basic_addition(self):
-        """
-        Tests that 1 + 1 always equals 2.
-        """
-        self.failUnlessEqual(1 + 1, 2)
-
-__test__ = {"doctest": """
-Another way to test that 1 + 1 is equal to 2.
-
->>> 1 + 1 == 2
-True
-"""}

src/recaptchaworks/utils.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-import httplib
-from django.utils.http import urlencode
-
-from recaptchaworks.exceptions import RecaptchaError
-
-
-def validate_recaptcha(remote_ip, challenge, response, private_key, use_ssl):
-    assert challenge, 'No challenge was provided for reCaptcha validation'
-    # Request validation from recaptcha.net
-    params = dict(privatekey=private_key, remoteip=remote_ip,
-                  challenge=challenge, response=response)
-    params = urlencode(params)
-    headers = {"Content-type": "application/x-www-form-urlencoded",
-               "Accept": "text/plain"}
-    if use_ssl:
-        conn = httplib.HTTPSConnection("www.google.com")
-    else:
-        conn = httplib.HTTPConnection("www.google.com")
-    conn.request("POST", "/recaptcha/api/verify", params, headers)
-    response = conn.getresponse()
-    if response.status == 200:
-        data = response.read()
-    else:
-        data = ''
-    conn.close()
-    # Validate based on response data
-    result = data.startswith('true')
-    if not result:
-        bits = data.split('\n', 2)
-        error_code = ''
-        if len(bits) > 1:
-            error_code = bits[1]
-        raise RecaptchaError(error_code)
-    # Return dictionary
-    return result
-
-
-def post_payload_add_recaptcha_remote_ip_field(request):
-    if request.method == 'POST':
-        if 'recaptcha_challenge_field' in request.POST and 'recaptcha_response_field' in request.POST:
-            # This is a recaptcha protected form
-            data = request.POST.copy()
-            data['recaptcha_remote_ip_field'] = request.META['REMOTE_ADDR']
-            request.POST = data
-    return request
-

src/recaptchaworks/views.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#

src/recaptchaworks/widgets.py

-# -*- coding: utf-8 -*-
-#
-#  This file is part of django-recaptcha-works.
-#
-#  django-recaptcha-works provides a Django form field that integrates the
-#  reCaptcha service.
-#
-#  Development Web Site:
-#    - http://www.codetrax.org/projects/django-recaptcha-works
-#  Public Source Code Repository:
-#    - https://source.codetrax.org/hgroot/django-recaptcha-works
-#
-#  Copyright 2010 George Notaras <gnot [at] g-loaded.eu>
-#
-#  Based on the code snippet #1644 as published on:
-#    - http://djangosnippets.org/snippets/1644/
-#
-#  Copyright (c) 2009-2010 Chris Beaven, http://smileychris.com/
-#
-#  Licensed under the BSD License.
-#
-#  Redistribution and use in source and binary forms, with or without modification,
-#  are permitted provided that the following conditions are met:
-#
-#      1. Redistributions of source code must retain the above copyright notice, 
-#         this list of conditions and the following disclaimer.
-#      
-#      2. Redistributions in binary form must reproduce the above copyright 
-#         notice, this list of conditions and the following disclaimer in the
-#         documentation and/or other materials provided with the distribution.
-#
-#      3. Neither the name of Django nor the names of its contributors may be used
-#         to endorse or promote products derived from this software without
-#         specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django import forms
-from django.utils.safestring import mark_safe
-from django.utils import simplejson
-
-from recaptchaworks import settings
-
-
-class RecaptchaWidget(forms.Widget):
-    
-    RECAPTCHA_OPTIONS_SCRIPT = u'''<script type="text/javascript">
-var RecaptchaOptions = {
-%s
-};
-</script>
-'''
-    
-    def __init__(self, public_key=None, use_ssl=False, recaptcha_options=None):
-        '''RecaptchaWidget constructor
-        
-        For customization information visit:
-        
-        http://code.google.com/apis/recaptcha/docs/customization.html
-        
-        The optional ``recaptcha_options`` argument can be used to override
-        the default project wide ``RECAPTCHA_OPTIONS`` setting.
-        
-        The optional ``public_key`` argument can be used to override the
-        default use of the project-wide ``RECAPTCHA_PUBLIC_KEY`` setting.
-        
-        The optional ``use_ssl`` argument can be used to override the default
-        use of the project-wide ``RECAPTCHA_USE_SSL`` setting.
-        '''
-        self.options = recaptcha_options
-        if recaptcha_options is None:
-            self.options = settings.RECAPTCHA_OPTIONS
-        
-        self.proto = 'http'
-        if use_ssl or settings.RECAPTCHA_USE_SSL:
-            self.proto = 'https'
-        
-        self.public_key = public_key or settings.RECAPTCHA_PUBLIC_KEY
-        
-        super(RecaptchaWidget, self).__init__()
-
-    def render(self, name, value, attrs=None):
-        args = dict(public_key=self.public_key, proto=self.proto, options='')
-        if self.options:
-            args['options'] = self.RECAPTCHA_OPTIONS_SCRIPT % simplejson.dumps(
-                self.options, indent=4).strip('{}')
-        return mark_safe(settings.RECAPTCHA_HTML % args)
-
-    def value_from_datadict(self, data, files, name):
-        challenge = data.get('recaptcha_challenge_field')
-        response = data.get('recaptcha_response_field')
-        # This is added by utils.post_payload_add_recaptcha_remote_ip_field()
-        remote_ip = data.get('recaptcha_remote_ip_field')
-        return (challenge, response, remote_ip)
-
-    def id_for_label(self, id_):
-        return None
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.