Merlijn van Deen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/86615


Change subject: [WIP] Python 3 compat using 2to3
......................................................................

[WIP] Python 3 compat using 2to3

Files are converted and tests are started, but they fail.
Stashing it for now; feel free to continue/take over the patch.

Change-Id: I597d284ef026312644e66f30055b840dc8d39114
---
M pywikibot/comms/http.py
M pywikibot/data/api.py
M pywikibot/family.py
M pywikibot/page.py
M setup.py
5 files changed, 22 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/15/86615/1

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 1dee9ec..49e57ac 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -27,7 +27,10 @@
 import logging
 import atexit
 
-from httplib2 import SSLHandshakeError
+try:
+    from httplib2 import SSLHandshakeError
+except ImportError:
+    from ssl import SSLError as SSLHandshakeError
 from pywikibot import config
 from pywikibot.exceptions import FatalServerError, Server504Error
 import pywikibot
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 5f36019..c1aa077 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -9,7 +9,7 @@
 #
 __version__ = '$Id$'
 
-from UserDict import DictMixin
+from collections import MutableMapping
 from pywikibot.comms import http
 from email.mime.multipart import MIMEMultipart
 from email.mime.nonmultipart import MIMENonMultipart
@@ -64,7 +64,7 @@
     pass
 
 
-class Request(object, DictMixin):
+class Request(MutableMapping):
     """A request to a Site's api.php interface.
 
     Attributes of this object (except for the special parameters listed
@@ -163,6 +163,9 @@
     def __iter__(self):
         return self.params.__iter__()
 
+    def __len__(self):
+        return len(self.params)
+
     def iteritems(self):
         return self.params.iteritems()
 
diff --git a/pywikibot/family.py b/pywikibot/family.py
index bc5d206..d336daf 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -98,13 +98,9 @@
         ]
 
         # Order for fy: alphabetical by code, but y counts as i
-        def fycomp(x, y):
-            x = x.replace("y", "i") + x.count("y") * "!"
-            y = y.replace("y", "i") + y.count("y") * "!"
-            return cmp(x, y)
         self.fyinterwiki = self.alphabetic[:]
         self.fyinterwiki.remove('nb')
-        self.fyinterwiki.sort(fycomp)
+        self.fyinterwiki.sort(key = lambda x: x.replace("y", "i") + 
x.count("y") * "!")
 
         self.langs = {}
 
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 84c88cc..6b82dfd 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -20,7 +20,10 @@
 import re
 import threading
 import unicodedata
-import urllib
+try:
+    from urllib.parse import quote_from_bytes, unquote_to_bytes
+except ImportError:
+    from urllib import quote as quote_from_bytes, unquote as unquote_to_bytes
 import collections
 
 logger = logging.getLogger("pywiki.wiki.page")
@@ -165,7 +168,7 @@
             title = title.replace(u' ', u'_')
         if asUrl:
             encodedTitle = title.encode(self.site.encoding())
-            title = urllib.quote(encodedTitle)
+            title = quote_from_bytes(encodedTitle)
         if as_filename:
             # Replace characters that are not possible in file names on some
             # systems.
@@ -3461,7 +3464,7 @@
     for enc in encList:
         try:
             t = title.encode(enc)
-            t = urllib.unquote(t)
+            t = unquote_to_bytes(t)
             return unicode(t, enc)
         except UnicodeError, ex:
             if not firstException:
diff --git a/setup.py b/setup.py
index a38cfe8..b6d5825 100644
--- a/setup.py
+++ b/setup.py
@@ -17,10 +17,10 @@
 from setuptools import setup, find_packages
 from setuptools.command import install
 
-if sys.version_info[0] != 2:
-    raise RuntimeError("ERROR: Pywikipediabot only runs under Python 2")
-elif sys.version_info[1] < 6:
-    raise RuntimeError("ERROR: Pywikipediabot only runs under Python 2.6 or 
higher")
+#if sys.version_info[0] != 2:
+#    raise RuntimeError("ERROR: Pywikipediabot only runs under Python 2")
+#elif sys.version_info[1] < 6:
+#    raise RuntimeError("ERROR: Pywikipediabot only runs under Python 2.6 or 
higher")
 
 
 class pwb_install(install.install):
@@ -59,5 +59,6 @@
     ],
     cmdclass={
         'install': pwb_install
-    }
+    },
+    use_2to3=True
 )

-- 
To view, visit https://gerrit.wikimedia.org/r/86615
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I597d284ef026312644e66f30055b840dc8d39114
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to