[yum-commits] Branch 'yum-3_2_X' - 2 commits - yum/metalink.py yum/misc.py yum/pgpmsg.py

James Antill james at osuosl.org
Mon Dec 1 14:41:09 UTC 2008


 yum/metalink.py |    5 ++++-
 yum/misc.py     |   24 +++++++++++++++++++-----
 yum/pgpmsg.py   |   11 ++++++++---
 3 files changed, 31 insertions(+), 9 deletions(-)

New commits:
commit ea70f4851558e02db81a367c50c7b6ca5570941a
Author: James Antill <james at and.org>
Date:   Mon Dec 1 09:28:26 2008 -0500

    Simple fix for python-2.6, remove sha/md5 imports from pgpmsg

diff --git a/yum/misc.py b/yum/misc.py
index 801fc0f..108283b 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -177,15 +177,14 @@ class Checksums:
         Length and the result(s) when complete. """
 
     def __init__(self, checksums=None, ignore_missing=False):
-        self._checksums = checksums
-        if self._checksums is None:
-            self._checksums = ['sha256']
+        if checksums is None:
+            checksums = ['sha256']
         self._sumalgos = []
         self._sumtypes = []
         self._len = 0
 
         done = set()
-        for sumtype in self._checksums:
+        for sumtype in checksums:
             if sumtype in done:
                 continue
 
@@ -198,6 +197,8 @@ class Checksums:
             done.add(sumtype)
             self._sumtypes.append(sumtype)
             self._sumalgos.append(sumalgo)
+        if not done:
+            raise MiscError, 'Error Checksumming, no valid checksum type'
 
     def __len__(self):
         return self._len
@@ -218,9 +219,22 @@ class Checksums:
             ret[sumtype] = sumdata.hexdigest()
         return ret
 
-    def hexdigest(self, checksum):
+    def hexdigest(self, checksum=None):
+        if checksum is None:
+            checksum = self._sumtypes[0]
         return self.hexdigests()[checksum]
 
+    def digests(self):
+        ret = {}
+        for sumtype, sumdata in zip(self._sumtypes, self._sumalgos):
+            ret[sumtype] = sumdata.digest()
+        return ret
+
+    def digest(self, checksum=None):
+        if checksum is None:
+            checksum = self._sumtypes[0]
+        return self.digests()[checksum]
+
 
 class AutoFileChecksums:
     """ Generate checksum(s), on given file/fileobject. Pretending to be a file
diff --git a/yum/pgpmsg.py b/yum/pgpmsg.py
index 35a7801..66aff61 100644
--- a/yum/pgpmsg.py
+++ b/yum/pgpmsg.py
@@ -13,7 +13,12 @@
 ##You should have received a copy of the GNU General Public License
 ##along with this program; if not, write to the Free Software
 ##Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-import struct, time, cStringIO, base64, types, md5, sha
+import struct, time, cStringIO, base64, types
+
+#  We use this so that we can work on python-2.4 and python-2.6, and thus.
+# use import md5/import sha on the older one and import hashlib on the newer.
+#  Stupid deprecation warnings.
+from misc import Checksums
 
 debug = None
 
@@ -378,14 +383,14 @@ class public_key(pgp_packet) :
         # otherwise calculate it now and cache it
         # v3 and v4 are calculated differently
         if self.version == 3 :
-            h = md5.new()
+            h = misc.Checksums(['md5'])
             h.update(pack_long(self.pk_rsa_mod))
             h.update(pack_long(self.pk_rsa_exp))
             self.fingerprint_ = h.digest()
         elif self.version == 4 :
             # we hash what would be the whole PGP message containing
             # the pgp certificate
-            h = sha.new()
+            h = misc.Checksums(['sha1'])
             h.update('\x99')
             # we need to has the length of the packet as well
             buf = self.serialize()
commit 7760b91e392db1e8dfa5ee03e7810c5ae53f8312
Author: James Antill <james at and.org>
Date:   Sun Nov 30 13:11:08 2008 -0500

    Fix the protocol attribute to use the "std" attribute name

diff --git a/yum/metalink.py b/yum/metalink.py
index c478e0e..ff36393 100755
--- a/yum/metalink.py
+++ b/yum/metalink.py
@@ -135,9 +135,12 @@ class MetaLinkURL:
 
         self.url        = elem.text
         self.preference = int(elem.get("preference", -1))
-        self.protocol   = elem.get("protocol")
+        self.protocol   = elem.get("type") # This is the "std" attribute name
         self.location   = elem.get("location")
 
+        if self.protocol is None: # Try for the old MM protocol attribute
+            self.protocol   = elem.get("protocol")
+
     def __str__(self):
         return """\
 URL:             %s


More information about the Yum-commits mailing list