Revision: 4489
Author: btongminh
Date: 2007-10-31 20:58:43 +0000 (Wed, 31 Oct 2007)
Log Message:
-----------
Add a new config setting for solving captchas (default: backwards-compatible)
Modified Paths:
--------------
trunk/pywikipedia/config.py
trunk/pywikipedia/login.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/config.py
===================================================================
--- trunk/pywikipedia/config.py 2007-10-31 20:37:03 UTC (rev 4488)
+++ trunk/pywikipedia/config.py 2007-10-31 20:58:43 UTC (rev 4489)
@@ -45,6 +45,10 @@
disambiguation_comment = {}
gdab_namespaces = {}
+# Solve captchas in the webbrowser. Setting this to False will result in the
+# exception CaptchaError be thrown if a captcha is encountered.
+solve_captcha = True
+
# Some sites will require password identication to access the HTML pages at
# the site. If you have any such site, add lines to your user-config.py of
# the following form:
Modified: trunk/pywikipedia/login.py
===================================================================
--- trunk/pywikipedia/login.py 2007-10-31 20:37:03 UTC (rev 4488)
+++ trunk/pywikipedia/login.py 2007-10-31 20:58:43 UTC (rev 4489)
@@ -156,6 +156,8 @@
captchaR = re.compile('<input type="hidden"
name="wpCaptchaId" id="wpCaptchaId"
value="(?P<id>\d+)" />')
match = captchaR.search(data)
if match:
+ if not config.solve_captcha:
+ raise wikipedia.CaptchaError(id)
id = match.group('id')
url = self.site.protocol() + '://' + self.site.hostname() +
self.site.captcha_image_address(id)
answer = wikipedia.ui.askForCaptcha(url)
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-10-31 20:37:03 UTC (rev 4488)
+++ trunk/pywikipedia/wikipedia.py 2007-10-31 20:58:43 UTC (rev 4489)
@@ -203,6 +203,9 @@
class PageNotFound(Error):
"""Page not found in list"""
+class CaptchaError(Error):
+ """Captcha is asked and config.solve_captcha ==
False."""
+
SaxError = xml.sax._exceptions.SAXParseException
# Pre-compile re expressions
Show replies by date