PkgInfo: workaround unescaped "<<" in versioned depends not being parsed correctly

This commit is contained in:
James Lu 2016-09-05 19:44:20 -07:00
parent f9ec36cfd8
commit 5ac44e54d4

View File

@ -147,20 +147,28 @@ class PkgInfo(callbacks.Plugin):
url = addrs[distro] url = addrs[distro]
except KeyError: except KeyError:
irc.error(unknowndist, Raise=True) irc.error(unknowndist, Raise=True)
if source: if source: # Source package was requested
url += 'source/' url += 'source/'
url += "{}/{}".format(release, pkg) url += "{}/{}".format(release, pkg)
try: try:
fd = utils.web.getUrl(url).decode("utf-8") text = utils.web.getUrl(url).decode("utf-8")
except utils.web.Error as e: except utils.web.Error as e:
irc.error(str(e), Raise=True) irc.error(str(e), Raise=True)
soup = BeautifulSoup(fd)
# Workaround unescaped << in package versions (e.g. "python (<< 2.8)") not being parsed
# correctly.
text = text.replace('<<', '&lt;&lt;')
soup = BeautifulSoup(text)
if "Error" in soup.title.string: if "Error" in soup.title.string:
err = soup.find('div', attrs={"id": "content"}).find('p').string err = soup.find('div', attrs={"id": "content"}).find('p').string
if "two or more packages specified" in err: if "two or more packages specified" in err:
irc.error("Unknown distribution/release.", Raise=True) irc.error("Unknown distribution/release.", Raise=True)
irc.reply(err) irc.reply(err)
return return
# If we're using the --depends option, handle that separately. # If we're using the --depends option, handle that separately.
if 'depends' in opts: if 'depends' in opts:
items = soup.find('div', {'id': 'pdeps'}).find_all('dt') items = soup.find('div', {'id': 'pdeps'}).find_all('dt')
@ -185,6 +193,7 @@ class PkgInfo(callbacks.Plugin):
res[deptype][-1] += " or %s" % name res[deptype][-1] += " or %s" % name
except AttributeError: except AttributeError:
continue continue
if res: if res:
s = format("Package \x02%s\x02 dependencies: ", pkg) s = format("Package \x02%s\x02 dependencies: ", pkg)
for deptype, packages in res.items(): for deptype, packages in res.items():
@ -194,10 +203,13 @@ class PkgInfo(callbacks.Plugin):
s += format("%u", url) s += format("%u", url)
irc.reply(s) irc.reply(s)
else: else:
irc.error("%s doesn't seem to have any dependencies." % pkg) irc.error("%s doesn't seem to have any dependencies." % pkg)
return return
desc = soup.find('meta', attrs={"name": "Description"})["content"] desc = soup.find('meta', attrs={"name": "Description"})["content"]
# Override description if we selected source lookup, since the meta # Override description if we selected source lookup, since the meta
# tag Description should be empty for those. Replace this with a list # tag Description should be empty for those. Replace this with a list
# of binary packages that the source package builds. # of binary packages that the source package builds.
@ -205,11 +217,13 @@ class PkgInfo(callbacks.Plugin):
binaries = soup.find('div', {'id': "pbinaries"}) binaries = soup.find('div', {'id': "pbinaries"})
binaries = [ircutils.bold(obj.a.text) for obj in binaries.find_all('dt')] binaries = [ircutils.bold(obj.a.text) for obj in binaries.find_all('dt')]
desc = format('Built packages: %L', binaries) desc = format('Built packages: %L', binaries)
# Get package information from the meta tags # Get package information from the meta tags
keywords = soup.find('meta', attrs={"name": "Keywords"})["content"] keywords = soup.find('meta', attrs={"name": "Keywords"})["content"]
keywords = keywords.replace(",", "").split() keywords = keywords.replace(",", "").split()
version = keywords[-1] version = keywords[-1]
# Handle virtual packages, showing a list of packages that provide it
# Handle virtual packages by showing a list of packages that provide it
if version == "virtual": if version == "virtual":
providing = [ircutils.bold(obj.a.text) for obj in soup.find_all('dt')] providing = [ircutils.bold(obj.a.text) for obj in soup.find_all('dt')]
desc = "Virtual package provided by: %s" % ', '.join(providing[:10]) desc = "Virtual package provided by: %s" % ', '.join(providing[:10])