← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:avoid-splitvalue into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:avoid-splitvalue into launchpad:master.

Commit message:
Avoid urllib.parse.splitvalue

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/420260

It's deprecated as of Python 3.8.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:avoid-splitvalue into launchpad:master.
diff --git a/lib/lp/bugs/externalbugtracker/sourceforge.py b/lib/lp/bugs/externalbugtracker/sourceforge.py
index 4cc8b89..6670828 100644
--- a/lib/lp/bugs/externalbugtracker/sourceforge.py
+++ b/lib/lp/bugs/externalbugtracker/sourceforge.py
@@ -6,8 +6,7 @@
 __all__ = ['SourceForge']
 
 import re
-
-from six.moves.urllib.parse import splitvalue
+from urllib.parse import parse_qsl
 
 from lp.bugs.externalbugtracker import (
     BugNotFound,
@@ -91,7 +90,6 @@ class SourceForge(ExternalBugTracker):
 
             # We save the group_id and atid parameters from the
             # query_url. They'll be returned by getRemoteProduct().
-            query_dict = {}
             bugtracker_link = soup.find('a', text='Bugs')
             if bugtracker_link:
                 href = bugtracker_link['href']
@@ -100,11 +98,7 @@ class SourceForge(ExternalBugTracker):
                 # SourceForge occasionally encodes them.
                 href = href.replace('&', '&')
                 schema, host, path, query, fragment = urlsplit(href)
-
-                query_bits = query.split('&')
-                for bit in query_bits:
-                    key, value = splitvalue(bit)
-                    query_dict[key] = value
+                query_dict = {key: value for key, value in parse_qsl(query)}
 
                 try:
                     atid = int(query_dict.get('atid', None))
diff --git a/lib/lp/bugs/model/bugwatch.py b/lib/lp/bugs/model/bugwatch.py
index 8b564a3..51940e7 100644
--- a/lib/lp/bugs/model/bugwatch.py
+++ b/lib/lp/bugs/model/bugwatch.py
@@ -10,16 +10,13 @@ __all__ = [
 
 from datetime import datetime
 import re
+from urllib.parse import urlunsplit
 
 from lazr.lifecycle.event import ObjectModifiedEvent
 from lazr.lifecycle.snapshot import Snapshot
 from lazr.uri import find_uris_in_text
 from pytz import utc
 import six
-from six.moves.urllib.parse import (
-    splitvalue,
-    urlunsplit,
-    )
 from storm.expr import (
     Desc,
     Not,
@@ -721,9 +718,15 @@ class BugWatchSet:
         for trackertype, parse_func in (
             self.bugtracker_parse_functions.items()):
             scheme, host, path, query_string, frag = urlsplit(url)
+            # urllib.parse.parse_qsl would almost be suitable here, but
+            # Savannah/Savane use bare bug IDs as query strings without any
+            # key=value structure, so we need something more like the
+            # deprecated urllib.parse.splitvalue.
             query = {}
             for query_part in query_string.split('&'):
-                key, value = splitvalue(query_part)
+                key, delim, value = query_part.partition('=')
+                if not delim:
+                    value = None
                 query[key] = value
 
             bugtracker_data = parse_func(scheme, host, path, query)
diff --git a/lib/lp/bugs/scripts/sfremoteproductfinder.py b/lib/lp/bugs/scripts/sfremoteproductfinder.py
index 104a5d9..968c26a 100644
--- a/lib/lp/bugs/scripts/sfremoteproductfinder.py
+++ b/lib/lp/bugs/scripts/sfremoteproductfinder.py
@@ -7,8 +7,9 @@ __all__ = [
     'SourceForgeRemoteProductFinder',
     ]
 
+from urllib.parse import parse_qsl
+
 import requests
-from six.moves.urllib.parse import splitvalue
 from zope.component import getUtility
 
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
@@ -96,12 +97,7 @@ class SourceForgeRemoteProductFinder:
         # SourceForge usually encodes them.
         bugtracker_url = bugtracker_url.replace('&', '&')
         schema, host, path, query, fragment = urlsplit(bugtracker_url)
-
-        query_dict = {}
-        query_bits = query.split('&')
-        for bit in query_bits:
-            key, value = splitvalue(bit)
-            query_dict[key] = value
+        query_dict = {key: value for key, value in parse_qsl(query)}
 
         try:
             atid = int(query_dict.get('atid', None))