coding standards

This commit is contained in:
Yann Leboulanger 2012-01-24 07:28:40 +01:00
parent 5142ebd626
commit 3b5cabac5b
2 changed files with 19 additions and 17 deletions

View file

@ -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):

View file

@ -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:
@ -930,18 +932,18 @@ class Interface:
ft = self.instances['file_transfers'] ft = self.instances['file_transfers']
if file_props['error'] == 0: if file_props['error'] == 0:
ft.set_progress(file_props['type'], file_props['sid'], ft.set_progress(file_props['type'], file_props['sid'],
file_props['received-len']) file_props['received-len'])
else: else:
ft.set_status(file_props['type'], file_props['sid'], 'stop') ft.set_status(file_props['type'], file_props['sid'], 'stop')
if 'stalled' in file_props and file_props['stalled'] or \ if 'stalled' in file_props and file_props['stalled'] or \
'paused' in file_props and file_props['paused']: 'paused' in file_props and file_props['paused']:
return return
if file_props['type'] == 'r': # we receive a file if file_props['type'] == 'r': # we receive a file
jid = unicode(file_props['sender']) jid = unicode(file_props['sender'])
# Compare hashes in a new thread # Compare hashes in a new thread
self.hashThread = Thread(target=self.__compare_hashes, self.hashThread = Thread(target=self.__compare_hashes,
args=(account, file_props)) args=(account, file_props))
self.hashThread.start() self.hashThread.start()
gajim.socks5queue.remove_receiver(file_props['sid'], True, True) gajim.socks5queue.remove_receiver(file_props['sid'], True, True)
else: # we send a file else: # we send a file
@ -969,7 +971,7 @@ class Interface:
elif file_props['error'] in (-1, -6): elif file_props['error'] in (-1, -6):
msg_type = 'file-stopped' msg_type = 'file-stopped'
event_type = _('File Transfer Stopped') event_type = _('File Transfer Stopped')
if event_type == '': if event_type == '':
# FIXME: ugly workaround (this can happen Gajim sent, Gaim recvs) # FIXME: ugly workaround (this can happen Gajim sent, Gaim recvs)
# this should never happen but it does. see process_result() in # this should never happen but it does. see process_result() in