changeset 2eed9411ae2d in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=2eed9411ae2d
description: better way to handle non supported hash algorithms

diffstat:

 src/common/jingle_ft.py     |   8 ++++++--
 src/common/xmpp/protocol.py |  10 ++--------
 2 files changed, 8 insertions(+), 10 deletions(-)

diffs (48 lines):

diff -r d57f00841330 -r 2eed9411ae2d src/common/jingle_ft.py
--- a/src/common/jingle_ft.py   Tue Jan 24 10:04:14 2012 -0500
+++ b/src/common/jingle_ft.py   Tue Jan 24 16:51:26 2012 -0500
@@ -118,11 +118,15 @@
         if self.session.hash_algo == None:
             return
         try:
-            file = open(self.file_props['file-name'], 'r')
+            file_ = open(self.file_props['file-name'], 'r')
         except:
+            # can't open file
             return
         h = xmpp.Hashes()
-        hash_ = h.calculateHash(self.session.hash_algo, file)
+        hash_ = h.calculateHash(self.session.hash_algo, file_)
+        if not hash_:
+            # Hash alogrithm not supported
+            return
         self.file_props['hash'] = hash_
         h.addHash(hash_, self.session.hash_algo)
         checksum = xmpp.Node(tag='checksum',  
diff -r d57f00841330 -r 2eed9411ae2d src/common/xmpp/protocol.py
--- a/src/common/xmpp/protocol.py       Tue Jan 24 10:04:14 2012 -0500
+++ b/src/common/xmpp/protocol.py       Tue Jan 24 16:51:26 2012 -0500
@@ -1078,10 +1078,7 @@
             elif algo == 'sha-512':
                 hl = hashlib.sha512()
                 
-            if hl == None:
-                # Raise exception
-                raise Exception('Hash algorithm not supported')
-            else:
+            if hl:
                 hl.update(file_string)
                 hash_ = hl.hexdigest()
         else: # if it is a file
@@ -1095,10 +1092,7 @@
             elif algo == 'sha-512':
                 hl = hashlib.sha512()
                 
-            if hl == None:
-                # Raise exception
-                raise Exception('Hash algorithm not supported')
-            else:
+            if hl:
                 for line in file_string:
                     hl.update(line)
                 hash_ = hl.hexdigest()
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to