Пример #1
0
 def __init__(self, tox, friend_number, size, file_number):
     path = settings.ProfileHelper.get_path() + 'avatars/{}.png'.format(tox.friend_get_public_key(friend_number))
     super(ReceiveAvatar, self).__init__(path + '.tmp', tox, friend_number, size, file_number)
     if size > self.MAX_AVATAR_SIZE:
         self.send_control(TOX_FILE_CONTROL['CANCEL'])
         self._file.close()
         remove(path + '.tmp')
     elif not size:
         self.send_control(TOX_FILE_CONTROL['CANCEL'])
         self._file.close()
         if exists(path):
             remove(path)
         self._file.close()
         remove(path + '.tmp')
     elif exists(path):
         hash = self.get_file_id()
         with open(path, 'rb') as fl:
             data = fl.read()
         existing_hash = Tox.hash(data)
         if hash == existing_hash:
             self.send_control(TOX_FILE_CONTROL['CANCEL'])
             self._file.close()
             remove(path + '.tmp')
         else:
             self.send_control(TOX_FILE_CONTROL['RESUME'])
     else:
         self.send_control(TOX_FILE_CONTROL['RESUME'])
Пример #2
0
 def __init__(self, path, tox, friend_number):
     if path is None:
         hash = None
     else:
         with open(path, 'rb') as fl:
             hash = Tox.hash(fl.read())
     super(SendAvatar, self).__init__(path, tox, friend_number, TOX_FILE_KIND['AVATAR'], hash)
Пример #3
0
 def __init__(self, tox, friend_number, size, file_number):
     path = settings.ProfileHelper.get_path() + 'avatars/{}.png'.format(tox.friend_get_public_key(friend_number))
     super(ReceiveAvatar, self).__init__(path + '.tmp', tox, friend_number, size, file_number)
     if size > self.MAX_AVATAR_SIZE:
         self.send_control(TOX_FILE_CONTROL['CANCEL'])
         self._file.close()
         remove(path + '.tmp')
     elif not size:
         self.send_control(TOX_FILE_CONTROL['CANCEL'])
         self._file.close()
         if exists(path):
             remove(path)
         self._file.close()
         remove(path + '.tmp')
     elif exists(path):
         hash = self.get_file_id()
         with open(path, 'rb') as fl:
             data = fl.read()
         existing_hash = Tox.hash(data)
         if hash == existing_hash:
             self.send_control(TOX_FILE_CONTROL['CANCEL'])
             self._file.close()
             remove(path + '.tmp')
         else:
             self.send_control(TOX_FILE_CONTROL['RESUME'])
     else:
         self.send_control(TOX_FILE_CONTROL['RESUME'])