add a simplified version of 'parse_qs'

This version only returns a dict of plain string to string key-value
pairs and ignores multiple values for the same query variable.
This commit is contained in:
Mike Fährmann
2017-08-24 20:55:58 +02:00
parent 3b21e0703c
commit f7cdfd4c25
4 changed files with 10 additions and 13 deletions

View File

@@ -10,7 +10,6 @@
from .common import Extractor, Message from .common import Extractor, Message
from .. import text, util, exception from .. import text, util, exception
import urllib.parse
class FlickrExtractor(Extractor): class FlickrExtractor(Extractor):
@@ -225,10 +224,7 @@ class FlickrSearchExtractor(FlickrExtractor):
def __init__(self, match): def __init__(self, match):
FlickrExtractor.__init__(self, match) FlickrExtractor.__init__(self, match)
self.search = { self.search = text.parse_query(match.group(1))
key: vlist[0]
for key, vlist in urllib.parse.parse_qs(match.group(1)).items()
}
if "text" not in self.search: if "text" not in self.search:
self.search["text"] = "" self.search["text"] = ""

View File

@@ -11,7 +11,6 @@
from .common import Extractor, Message from .common import Extractor, Message
from .. import text, exception from .. import text, exception
from ..cache import cache from ..cache import cache
import urllib.parse
import re import re
@@ -141,7 +140,7 @@ class PixivUserExtractor(PixivExtractor):
PixivExtractor.__init__(self) PixivExtractor.__init__(self)
self.user_id, tag = match.groups() self.user_id, tag = match.groups()
if tag: if tag:
self.tag = urllib.parse.unquote(tag).lower() self.tag = text.unquote(tag).lower()
self.works = self._tagged_works self.works = self._tagged_works
def works(self): def works(self):
@@ -267,7 +266,7 @@ class PixivRankingExtractor(PixivExtractor):
test = [ test = [
(("https://www.pixiv.net/ranking.php" (("https://www.pixiv.net/ranking.php"
"?mode=daily&content=illust&date=20170818"), { "?mode=daily&content=illust&date=20170818"), {
"url": "7fdffbecfbd420b1d202fa417d79317240be30bc", "url": "b073c74e3a6633dbdc9ba4122448f66e5211c771",
}), }),
("https://www.pixiv.net/ranking.php", None), ("https://www.pixiv.net/ranking.php", None),
] ]
@@ -277,10 +276,7 @@ class PixivRankingExtractor(PixivExtractor):
self._iter = None self._iter = None
self._first = None self._first = None
query = { query = text.parse_query(match.group(1))
key: vlist[0]
for key, vlist in urllib.parse.parse_qs(match.group(1)).items()
}
self.mode = query.get("mode", "daily") self.mode = query.get("mode", "daily")
self.content = query.get("content", "all") self.content = query.get("content", "all")
self.date = query.get("date") self.date = query.get("date")

View File

@@ -130,6 +130,11 @@ def extract_iter(txt, begin, end, pos=0):
yield value yield value
def parse_query(qs):
"""Parse a query string into key-value pairs"""
return {key: vlist[0] for key, vlist in urllib.parse.parse_qs(qs).items()}
if os.name == "nt": if os.name == "nt":
clean_path = clean_path_windows clean_path = clean_path_windows
else: else:

View File

@@ -58,7 +58,7 @@ skip = [
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", "exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie",
"archivedmoe", "archiveofsins", "thebarchive", "archivedmoe", "archiveofsins", "thebarchive",
# temporary issues # temporary issues
"imgtrex", # 504 "mangapark",
] ]
# enable selective testing for direct calls # enable selective testing for direct calls
if __name__ == '__main__' and len(sys.argv) > 1: if __name__ == '__main__' and len(sys.argv) > 1: