Split out Contents file reading.

This commit is contained in:
Jelmer Vernooij 2021-03-05 14:35:09 +00:00
parent 456b47bb97
commit 05bad21f1f
No known key found for this signature in database
GPG key ID: 579C160D4C9E23E8

View file

@ -111,6 +111,14 @@ class ContentsFileNotFound(Exception):
"""The contents file was not found.""" """The contents file was not found."""
def read_contents_file(f):
for line in f:
(path, rest) = line.rsplit(maxsplit=1)
package = rest.split(b"/")[-1]
decoded_path = "/" + path.decode("utf-8", "surrogateescape")
yield decoded_path, package.decode("utf-8")
class AptContentsFileSearcher(FileSearcher): class AptContentsFileSearcher(FileSearcher):
def __init__(self): def __init__(self):
self._db = {} self._db = {}
@ -145,11 +153,8 @@ class AptContentsFileSearcher(FileSearcher):
yield pkg yield pkg
def load_file(self, f): def load_file(self, f):
for line in f: for path, package in read_contents_file(f):
(path, rest) = line.rsplit(maxsplit=1) self[path] = package
package = rest.split(b"/")[-1]
decoded_path = "/" + path.decode("utf-8", "surrogateescape")
self[decoded_path] = package.decode("utf-8")
@classmethod @classmethod
def _load_cache_file(cls, url, cache_dir): def _load_cache_file(cls, url, cache_dir):