Revision: 6856
Author:   russblau
Date:     2009-05-07 19:03:06 +0000 (Thu, 07 May 2009)

Log Message:
-----------
Implement SSL connections (somewhat different implementation than used in 
trunk); default is to use SSL (if available) for login actions only, but user 
can configure bot to use SSL never or always.

Modified Paths:
--------------
    branches/rewrite/pywikibot/comms/http.py
    branches/rewrite/pywikibot/config2.py
    branches/rewrite/pywikibot/data/api.py
    branches/rewrite/pywikibot/family.py

Property Changed:
----------------
    branches/rewrite/pywikibot/config2.py
    branches/rewrite/pywikibot/family.py

Modified: branches/rewrite/pywikibot/comms/http.py
===================================================================
--- branches/rewrite/pywikibot/comms/http.py    2009-05-07 18:27:55 UTC (rev 
6855)
+++ branches/rewrite/pywikibot/comms/http.py    2009-05-07 19:03:06 UTC (rev 
6856)
@@ -76,25 +76,32 @@
 atexit.register(_flush)
 
 # export cookie_jar to global namespace
-import pywikibot
 pywikibot.cookie_jar = cookie_jar
 
-def request(site, uri, *args, **kwargs):
+def request(site, uri, ssl=False, *args, **kwargs):
     """Queue a request to be submitted to Site.
 
     All parameters not listed below are the same as
     L{httplib2.Http.request}, but the uri is relative
 
     @param site: The Site to connect to
+    @param uri: the URI to retrieve (relative to the site's scriptpath)
+    @param ssl: Use https connection
     @return: The received data (a unicode string).
+    
     """
-    baseuri = "%s://%s/" % (site.protocol(), site.hostname())
-    uri = urlparse.urljoin(baseuri, uri)
+    if ssl:
+        proto = "https"
+        host = site.ssl_hostname()
+    else:
+        proto = "http"
+        host = site.hostname()
+    full_uri = "%(proto)s://%(host)s%(uri)s" % locals()
 
     # set default user-agent string
     kwargs.setdefault("headers", {})
     kwargs["headers"].setdefault("user-agent", useragent)
-    request = threadedhttp.HttpRequest(uri, *args, **kwargs)
+    request = threadedhttp.HttpRequest(full_uri, *args, **kwargs)
     http_queue.put(request)
     request.lock.acquire()
 

Modified: branches/rewrite/pywikibot/config2.py
===================================================================
--- branches/rewrite/pywikibot/config2.py       2009-05-07 18:27:55 UTC (rev 
6855)
+++ branches/rewrite/pywikibot/config2.py       2009-05-07 19:03:06 UTC (rev 
6856)
@@ -50,7 +50,7 @@
 gdab_namespaces = {}
 
 # Solve captchas in the webbrowser. Setting this to False will result in the 
-# exception CaptchaError be thrown if a captcha is encountered. 
+# exception CaptchaError being thrown if a captcha is encountered. 
 solve_captcha = True
 
 # Some sites will require password identication to access the HTML pages at
@@ -67,6 +67,19 @@
 # 2. You must use the hostname of the site, not its family/language pair
 authenticate = {}
 
+#
+#    Security Connection for Wikimedia Projects
+#
+use_SSL_onlogin = True # if available, use SSL when logging in
+use_SSL_always = False # if available, use SSL for all API queries
+
+# Available security projects
+available_ssl_project = [
+    u'wikipedia', u'wikinews', u'wikisource', u'wiktionary', u'wikibooks',
+    u'wikiquote', u'wikiversity', u'meta', u'mediawiki', u'commons',
+    u'species', u'incubator'
+]
+
 # password_file = ".passwd"
 # A password file with default passwords. For more information, please
 # see LoginManager.readPassword in login.py.
@@ -150,7 +163,10 @@
     #we get "StdioOnnaStick instance has no attribute 'encoding'"
     console_encoding = None
 
-# The encoding in which textfiles are stored, which contain lists of page 
titles.
+# The encoding in which textfiles are stored, which contain lists of page
+# titles. The most used is: 'utf-8'. 'utf-8-sig' recognizes BOM but it is
+# available on Python 2.5 or higher. For a complete list please see:
+# http://docs.python.org/library/codecs.html#standard-encodings
 textfile_encoding = 'utf-8'
 
 # tkinter isn't yet ready
@@ -163,7 +179,7 @@
 # Currently only works if interface 'terminal' is set.
 transliterate = True
 
-# Should the system bell be ringed if the bot expects user input?
+# Should the system bell ring if the bot expects user input?
 ring_bell = False
 
 # Colorization can be used to markup important text parts of the output.
@@ -220,6 +236,7 @@
 #     log = []
 # Per default, logging of interwiki.py is enabled because its logfiles can
 # be used to generate so-called warnfiles.
+# This setting can be overridden by the -log or -nolog command-line arguments.
 log = ['interwiki']
 # filename defaults to modulename-bot.log
 logfilename = None
@@ -337,7 +354,7 @@
 # That can do very ugly results.
 deIndentTables = True
 # table2wiki.py works quite stable, so you might switch to True
-table2wikiAskOnlyWarnngs = True
+table2wikiAskOnlyWarnings = True
 table2wikiSkipWarnings = False
 
 ############## WEBLINK CHECKER SETTINGS ##############


Property changes on: branches/rewrite/pywikibot/config2.py
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/pywikipedia/config.py:6734-6801
   + /trunk/pywikipedia/config.py:6734-6801,6810-6854

Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py      2009-05-07 18:27:55 UTC (rev 
6855)
+++ branches/rewrite/pywikibot/data/api.py      2009-05-07 19:03:06 UTC (rev 
6856)
@@ -194,7 +194,13 @@
             self.site.throttle(write=write)
             uri = self.site.scriptpath() + "/api.php"
             try:
-                rawdata = http.request(self.site, uri, method="POST",
+                ssl = False
+                if self.site.family.name in config.available_ssl_project:
+                    if action == "login" and config.use_SSL_onlogin:
+                        ssl = True
+                    elif config.use_SSL_always:
+                        ssl = True
+                rawdata = http.request(self.site, uri, ssl, method="POST",
                             headers={'Content-Type':
                                      'application/x-www-form-urlencoded'},
                             body=params)

Modified: branches/rewrite/pywikibot/family.py
===================================================================
--- branches/rewrite/pywikibot/family.py        2009-05-07 18:27:55 UTC (rev 
6855)
+++ branches/rewrite/pywikibot/family.py        2009-05-07 19:03:06 UTC (rev 
6856)
@@ -670,6 +670,7 @@
     redirect = {
         'af': [u'aanstuur'],
         'als': [u'weiterleitung'],
+        'an': [u'redirección'],
         'ar': [u'تحويل'],
         'arz': [u'تحويل'],
         'av': [u'перенаправление'],
@@ -677,6 +678,7 @@
         'be-tarask': [u'перанакіраваньне'],
         'be-x-old': [u'перанакіраваньне'],
         'bg': [u'виж', u'пренасочване'],
+        'bug': [u'alih'],
         'br': [u'adkas'],
         'bs': [u'preusmjeri'],
         'cs': [u'přesměruj'],
@@ -723,17 +725,20 @@
         'oc': [u'redireccion'],
         'pdc': [u'weiterleitung'],
         'pl': [u'redirect', u'patrz', u'tam', u'przekieruj'],
+        'qu': [u'redirección'],
         'ro': [u'redirecteaza'],
         'ru': [u'redirect', u'перенаправление', u'перенапр'],
         'sa': [u'#पुनर्निदेशन'],
+        'sah': [u'перенаправление'],
         'si': [u'යළියොමුව'],
         'sk': [u'presmeruj'],
         'sq': [u'ridrejto'],
         'sr': [u'преусмери', u'преусмери'],
         'srn': [u'stir'],
+        'stq': [u'weiterleitung'],
         'su': [u'redirected', u'alih'],
         'sv': [u'omdirigering'],
-        'szl': [u'redirect', u'tam'],
+        'szl': [u'redirect', u'tam', u'patrz'],
         'ta': [u'வழிமாற்று'],
         'te': [u'దారిమార్పు'],
         'th': [u'เปลี่ยนทาง'],
@@ -767,7 +772,7 @@
     def pagenamecodes(self,code):
         pos = ['PAGENAME']
         pos2 = []
-        if code in self.pagename.keys():
+        if code in self.pagename:
             pos = pos + self.pagename[code]
         elif code == 'als':
             return self.pagenamecodes('de')
@@ -780,7 +785,7 @@
     def pagename2codes(self,code):
         pos = ['PAGENAME']
         pos2 = []
-        if code in self.pagenamee.keys():
+        if code in self.pagenamee:
             pos = pos + self.pagenamee[code]
         elif code == 'als':
             return self.pagename2codes('de')
@@ -799,8 +804,13 @@
         return 'http'
 
     def hostname(self, code):
+        """The hostname to use for standard http connections."""
         return self.langs[code]
 
+    def ssl_hostname(self, code):
+        """The hostname to use for SSL connections."""
+        return "secure.wikimedia.org/%s/%s" % (self.name, code)
+
     def scriptpath(self, code):
         """The prefix used to locate scripts on this wiki.
 


Property changes on: branches/rewrite/pywikibot/family.py
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/pywikipedia/family.py:6057-6649
   + /trunk/pywikipedia/family.py:6057-6854



_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to