replace sha module with hashlib?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 'sha' module is deprecated and throws this warning.

/usr/local/lib/python2.6/dist-packages/func/overlord/modules/getfile.py:19: DeprecationWarning: the sha module is deprecated; use the hashlib module instead


There's a workaround at the top of
minion/modules/copyfile.py

But these two locations need a similar workaround.
minion/modules/getfile.py:import sha
overlord/modules/getfile.py:import sha


Patches:
#----------------------------------------------------

diff -U1  minion/modules/getfile.py.orig minion/modules/getfile.py
--- minion/modules/getfile.py.orig      2011-02-11 12:38:14.000000000 -0800
+++ minion/modules/getfile.py   2011-02-11 12:41:02.000000000 -0800
@@ -17,3 +17,13 @@
 import sys
-import sha
+try:
+    import hashlib
+except ImportError:
+ # Python-2.4.z ... gah! (or even 2.3!)

+    import sha
+    class hashlib:
+        @staticmethod
+        def new(algo):
+            if algo == 'sha1':
+                return sha.new()
+            raise ValueError, "Bad checksum type"
 import func_module
@@ -58,3 +68,3 @@
         chunk = b64encode(fic.read(bufsize))
-        mysha = sha.new()
+        mysha = hashlib.new('sha1')
         mysha.update(chunk)





#----------------------------------------------------




# diff -U1 overlord/modules/getfile.py.orig overlord/modules/getfile.py--- overlord/modules/getfile.py.orig 2011-02-11 12:44:07.000000000 -0800
+++ overlord/modules/getfile.py 2011-02-11 12:40:11.000000000 -0800
@@ -18,3 +18,14 @@
 import os
-import sha
+
+try:
+    import hashlib
+except ImportError:
+    # Python-2.4.z ... gah! (or even 2.3!)
+    import sha
+    class hashlib:
+        @staticmethod
+        def new(algo):
+            if algo == 'sha1':
+                return sha.new()
+            raise ValueError, "Bad checksum type"
 try:
@@ -55,3 +66,3 @@

-        nullsha = sha.new().hexdigest()
+        nullsha = hashlib.new('sha1').hexdigest()
         sourcebasename = os.path.basename(source)
@@ -72,3 +83,3 @@
                     continue
-                mysha = sha.new()
+                mysha = hashlib.new('sha1')
                 mysha.update(chunk)

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list


[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux