Coverage for daklib/dakapt.py: 92%
19 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
1"""
2interfaces around python-apt
4@copyright: 2020 😸 <😸@43-1.org>
5@license: GNU General Public License version 2 or later
6"""
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <https://www.gnu.org/licenses/>.
21import apt_pkg
24class DakHashes:
25 """
26 wrapper around `apt_pkg.Hashes`
27 """
29 def __init__(self, *args, **kwargs):
30 self._apt_hashes = apt_pkg.Hashes(*args, **kwargs)
32 # python-apt in Debian 10 (buster) uses
33 # `apt_pkg.Hashes(...).md5`
34 # but in Debian bullseye it switched to
35 # `apt_pkg.Hashes(...).find('md5sum').hashvalue`
36 def _hashvalue(self, name):
37 h = self._apt_hashes.hashes.find(name)
38 try:
39 return h.hashvalue
40 except AttributeError:
41 return str(h)[len(name) + 1 :]
43 @property
44 def md5(self) -> str:
45 return self._hashvalue("md5sum")
47 @property
48 def sha1(self) -> str:
49 return self._hashvalue("sha1")
51 @property
52 def sha256(self) -> str:
53 return self._hashvalue("sha256")