coding standards
This commit is contained in:
parent
5142ebd626
commit
3b5cabac5b
2 changed files with 19 additions and 17 deletions
|
@ -1066,7 +1066,7 @@ class Hashes(Node):
|
||||||
instead of doing it all over the place in Gajim.
|
instead of doing it all over the place in Gajim.
|
||||||
"""
|
"""
|
||||||
hl = None
|
hl = None
|
||||||
hash = None
|
hash_ = None
|
||||||
# file_string can be a string or a file
|
# file_string can be a string or a file
|
||||||
if type(file_string) == str: # if it is a string
|
if type(file_string) == str: # if it is a string
|
||||||
if algo == 'md5':
|
if algo == 'md5':
|
||||||
|
@ -1083,7 +1083,7 @@ class Hashes(Node):
|
||||||
raise Exception('Hash algorithm not supported')
|
raise Exception('Hash algorithm not supported')
|
||||||
else:
|
else:
|
||||||
hl.update(file_string)
|
hl.update(file_string)
|
||||||
hash = hl.hexdigest()
|
hash_ = hl.hexdigest()
|
||||||
else: # if it is a file
|
else: # if it is a file
|
||||||
|
|
||||||
if algo == 'md5':
|
if algo == 'md5':
|
||||||
|
@ -1101,25 +1101,25 @@ class Hashes(Node):
|
||||||
else:
|
else:
|
||||||
for line in file_string:
|
for line in file_string:
|
||||||
hl.update(line)
|
hl.update(line)
|
||||||
hash = hl.hexdigest()
|
hash_ = hl.hexdigest()
|
||||||
|
|
||||||
return hash
|
return hash_
|
||||||
|
|
||||||
def addHash(self, hash, algo):
|
def addHash(self, hash_, algo):
|
||||||
"""
|
"""
|
||||||
More than one hash can be added. Although it is permitted, it should
|
More than one hash can be added. Although it is permitted, it should
|
||||||
not be done for big files because it could slow down Gajim.
|
not be done for big files because it could slow down Gajim.
|
||||||
"""
|
"""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
attrs['algo'] = algo
|
attrs['algo'] = algo
|
||||||
self.addChild('hash', attrs, [hash])
|
self.addChild('hash', attrs, [hash_])
|
||||||
|
|
||||||
class Acks(Node):
|
class Acks(Node):
|
||||||
"""
|
"""
|
||||||
Acknowledgement elements for Stream Management
|
Acknowledgement elements for Stream Management
|
||||||
"""
|
"""
|
||||||
def __init__(self, nsp=NS_STREAM_MGMT):
|
def __init__(self, nsp=NS_STREAM_MGMT):
|
||||||
Node.__init__(self, None, {}, [], None, None,False, None)
|
Node.__init__(self, None, {}, [], None, None, False, None)
|
||||||
self.setNamespace(nsp)
|
self.setNamespace(nsp)
|
||||||
|
|
||||||
def buildAnswer(self, handled):
|
def buildAnswer(self, handled):
|
||||||
|
|
|
@ -909,18 +909,20 @@ class Interface:
|
||||||
self.last_ftwindow_update = time.time()
|
self.last_ftwindow_update = time.time()
|
||||||
self.instances['file_transfers'].set_progress(file_props['type'],
|
self.instances['file_transfers'].set_progress(file_props['type'],
|
||||||
file_props['sid'], file_props['received-len'])
|
file_props['sid'], file_props['received-len'])
|
||||||
|
|
||||||
def __compare_hashes(self, account, file_props):
|
def __compare_hashes(self, account, file_props):
|
||||||
session = gajim.connections[account].get_jingle_session(jid=None,
|
session = gajim.connections[account].get_jingle_session(jid=None,
|
||||||
sid=file_props['session-sid'])
|
sid=file_props['session-sid'])
|
||||||
h = Hashes()
|
h = Hashes()
|
||||||
try:
|
try:
|
||||||
file = open(file_props['file-name'], 'r')
|
file_ = open(file_props['file-name'], 'r')
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
hash = h.calculateHash(session.hash_algo, file)
|
hash_ = h.calculateHash(session.hash_algo, file_)
|
||||||
|
file_.close()
|
||||||
# If the hash we received and the hash of the file are the same,
|
# If the hash we received and the hash of the file are the same,
|
||||||
# then the file is not corrupt
|
# then the file is not corrupt
|
||||||
if session.file_hash == hash:
|
if session.file_hash == hash_:
|
||||||
print "they are te same"
|
print "they are te same"
|
||||||
# End jingle session
|
# End jingle session
|
||||||
if session:
|
if session:
|
||||||
|
|
Loading…
Add table
Reference in a new issue