jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/617501 )

Change subject: [4.0] remove Python 2 code in site_detect.py
......................................................................

[4.0] remove Python 2 code in site_detect.py

Change-Id: I5c48227889092cdaa0ec2af6ed4af89a11ffedf5
---
M pywikibot/site_detect.py
1 file changed, 8 insertions(+), 20 deletions(-)

Approvals:
  D3r1ck01: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py
index ac5908b..b66a5d2 100644
--- a/pywikibot/site_detect.py
+++ b/pywikibot/site_detect.py
@@ -5,25 +5,20 @@
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import absolute_import, division, unicode_literals
-
 import json
 import re

+from contextlib import suppress
+from html.parser import HTMLParser
+from urllib.parse import urljoin, urlparse
+
 from requests.exceptions import RequestException

 import pywikibot

 from pywikibot.comms.http import fetch
 from pywikibot.exceptions import ServerError
-from pywikibot.tools import MediaWikiVersion, PY2
-
-if not PY2:
-    from html.parser import HTMLParser
-    from urllib.parse import urljoin, urlparse
-else:
-    from HTMLParser import HTMLParser
-    from urlparse import urljoin, urlparse
+from pywikibot.tools import MediaWikiVersion


 SERVER_DB_ERROR_MSG = \
@@ -130,11 +125,9 @@
             pywikibot.log(
                 'wgEnableApi is not enabled in HTML of %s'
                 % self.fromurl)
-        try:
+        with suppress(AttributeError):
             self.version = MediaWikiVersion(
                 self.REwgVersion.search(data).group(1))
-        except AttributeError:
-            pass

         self.server = self.REwgServer.search(data).groups()[0]
         self.scriptpath = self.REwgScriptPath.search(data).groups()[0]
@@ -228,10 +221,7 @@

     def __init__(self, url):
         """Initializer."""
-        if PY2:
-            HTMLParser.__init__(self)
-        else:
-            super().__init__(convert_charrefs=True)
+        super().__init__(convert_charrefs=True)
         self.url = urlparse(url)
         self.generator = None
         self.version = None
@@ -298,11 +288,9 @@
         if tag == 'meta':
             if attrs.get('name') == 'generator':
                 self.generator = attrs['content']
-                try:
+                with suppress(ValueError):
                     self.version = MediaWikiVersion.from_generator(
                         self.generator)
-                except ValueError:
-                    pass
         elif tag == 'link' and 'rel' in attrs and 'href' in attrs:
             if attrs['rel'] in ('EditURI', 'stylesheet', 'search'):
                 self.set_api_url(attrs['href'])

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/617501
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5c48227889092cdaa0ec2af6ed4af89a11ffedf5
Gerrit-Change-Number: 617501
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to