fix traceback handling
fix struc and sha1 usage (use bytes instead of string)
This commit is contained in:
parent
89540b0c2e
commit
e03b3c35b6
|
@ -508,7 +508,7 @@ if dbus_support.supported:
|
||||||
def prefs_store(self):
|
def prefs_store(self):
|
||||||
try:
|
try:
|
||||||
gajim.interface.save_config()
|
gajim.interface.save_config()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return DBUS_BOOLEAN(False)
|
return DBUS_BOOLEAN(False)
|
||||||
return DBUS_BOOLEAN(True)
|
return DBUS_BOOLEAN(True)
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ class TimeResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%SZ')
|
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%SZ')
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
try:
|
try:
|
||||||
t = datetime.datetime.strptime(utc_time,
|
t = datetime.datetime.strptime(utc_time,
|
||||||
'%Y-%m-%dT%H:%M:%S.%fZ')
|
'%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
|
|
@ -36,7 +36,7 @@ try:
|
||||||
import common.gajim
|
import common.gajim
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
if __name__ != "__main__":
|
if __name__ != "__main__":
|
||||||
raise ImportError(e)
|
raise ImportError(str(e))
|
||||||
|
|
||||||
class XMPPEntity(object):
|
class XMPPEntity(object):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -79,7 +79,7 @@ class GlobalEventsDispatcher(object):
|
||||||
if event_name in self.handlers:
|
if event_name in self.handlers:
|
||||||
try:
|
try:
|
||||||
self.handlers[event_name].remove((priority, handler))
|
self.handlers[event_name].remove((priority, handler))
|
||||||
except ValueError as error:
|
except ValueError:
|
||||||
log.warn('''Function (%s) with priority "%s" never registered
|
log.warn('''Function (%s) with priority "%s" never registered
|
||||||
as handler of event "%s". Couldn\'t remove. Error: %s'''
|
as handler of event "%s". Couldn\'t remove. Error: %s'''
|
||||||
%(handler, priority, event_name, error))
|
%(handler, priority, event_name, error))
|
||||||
|
@ -94,7 +94,7 @@ class GlobalEventsDispatcher(object):
|
||||||
return True
|
return True
|
||||||
except NodeProcessed:
|
except NodeProcessed:
|
||||||
node_processed = True
|
node_processed = True
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.error('Error while running an even handler: %s' % \
|
log.error('Error while running an even handler: %s' % \
|
||||||
handler)
|
handler)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -915,7 +915,8 @@ def get_auth_sha(sid, initiator, target):
|
||||||
"""
|
"""
|
||||||
Return sha of sid + initiator + target used for proxy auth
|
Return sha of sid + initiator + target used for proxy auth
|
||||||
"""
|
"""
|
||||||
return hashlib.sha1("%s%s%s" % (sid, initiator, target)).hexdigest()
|
return hashlib.sha1(("%s%s%s" % (sid, initiator, target)).encode('utf-8')).\
|
||||||
|
hexdigest()
|
||||||
|
|
||||||
def remove_invalid_xml_chars(string):
|
def remove_invalid_xml_chars(string):
|
||||||
if string:
|
if string:
|
||||||
|
@ -1545,9 +1546,9 @@ def _get_img_proxy(attrs, proxy):
|
||||||
alt = attrs.get('alt', '')
|
alt = attrs.get('alt', '')
|
||||||
if alt:
|
if alt:
|
||||||
alt += '\n'
|
alt += '\n'
|
||||||
if ex[0] == pycurl.E_FILESIZE_EXCEEDED:
|
if ex.errno == pycurl.E_FILESIZE_EXCEEDED:
|
||||||
alt += _('Image is too big')
|
alt += _('Image is too big')
|
||||||
elif ex[0] == pycurl.E_OPERATION_TIMEOUTED:
|
elif ex.errno == pycurl.E_OPERATION_TIMEOUTED:
|
||||||
alt += _('Timeout loading image')
|
alt += _('Timeout loading image')
|
||||||
else:
|
else:
|
||||||
alt += _('Error loading image')
|
alt += _('Error loading image')
|
||||||
|
|
|
@ -68,7 +68,7 @@ try:
|
||||||
|
|
||||||
rootwindow = libX11.XDefaultRootWindow(dpy_p)
|
rootwindow = libX11.XDefaultRootWindow(dpy_p)
|
||||||
xss_available = True
|
xss_available = True
|
||||||
except OSError as e:
|
except OSError:
|
||||||
# Logging?
|
# Logging?
|
||||||
xss_available = False
|
xss_available = False
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,8 @@ class JingleFileTransfer(JingleContent):
|
||||||
if gajim.contacts.is_gc_contact(session.connection.name,
|
if gajim.contacts.is_gc_contact(session.connection.name,
|
||||||
session.peerjid):
|
session.peerjid):
|
||||||
roomjid = session.peerjid.split('/')[0]
|
roomjid = session.peerjid.split('/')[0]
|
||||||
dstaddr = hashlib.sha1('%s%s%s' % (self.file_props['sid'],
|
dstaddr = hashlib.sha1(('%s%s%s' % (self.file_props['sid'],
|
||||||
session.ourjid, roomjid)).hexdigest()
|
session.ourjid, roomjid)).encode('utf-8')).hexdigest()
|
||||||
self.file_props.dstaddr = dstaddr
|
self.file_props.dstaddr = dstaddr
|
||||||
self.state = STATE_NOT_STARTED
|
self.state = STATE_NOT_STARTED
|
||||||
self.states = {STATE_INITIALIZED : StateInitialized(self),
|
self.states = {STATE_INITIALIZED : StateInitialized(self),
|
||||||
|
|
|
@ -105,13 +105,13 @@ class JingleRTPContent(JingleContent):
|
||||||
try:
|
try:
|
||||||
bin = gst.parse_bin_from_description(pipeline, True)
|
bin = gst.parse_bin_from_description(pipeline, True)
|
||||||
return bin
|
return bin
|
||||||
except GError as error_str:
|
except GError as e:
|
||||||
gajim.nec.push_incoming_event(InformationEvent(None,
|
gajim.nec.push_incoming_event(InformationEvent(None,
|
||||||
conn=self.session.connection, level='error',
|
conn=self.session.connection, level='error',
|
||||||
pri_txt=_('%s configuration error') % text.capitalize(),
|
pri_txt=_('%s configuration error') % text.capitalize(),
|
||||||
sec_txt=_("Couldn't setup %s. Check your configuration.\n\n"
|
sec_txt=_("Couldn't setup %s. Check your configuration.\n\n"
|
||||||
"Pipeline was:\n%s\n\nError was:\n%s") % (text, pipeline,
|
"Pipeline was:\n%s\n\nError was:\n%s") % (text, pipeline,
|
||||||
error_str)))
|
str(e))))
|
||||||
raise JingleContentSetupException
|
raise JingleContentSetupException
|
||||||
|
|
||||||
def add_remote_candidates(self, candidates):
|
def add_remote_candidates(self, candidates):
|
||||||
|
|
|
@ -256,7 +256,7 @@ class Logger:
|
||||||
self.cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid,
|
self.cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid,
|
||||||
typ))
|
typ))
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
except sqlite.IntegrityError as e:
|
except sqlite.IntegrityError:
|
||||||
# Jid already in DB, maybe added by another instance. re-read DB
|
# Jid already in DB, maybe added by another instance. re-read DB
|
||||||
self.get_jids_already_in_db()
|
self.get_jids_already_in_db()
|
||||||
return self.get_jid_id(jid, typestr)
|
return self.get_jid_id(jid, typestr)
|
||||||
|
@ -580,7 +580,7 @@ class Logger:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.get_jid_id(jid)
|
self.get_jid_id(jid)
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
# Error trying to create a new jid_id. This means there is no log
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
return []
|
return []
|
||||||
where_sql, jid_tuple = self._build_contact_where(account, jid)
|
where_sql, jid_tuple = self._build_contact_where(account, jid)
|
||||||
|
@ -624,7 +624,7 @@ class Logger:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.get_jid_id(jid)
|
self.get_jid_id(jid)
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
# Error trying to create a new jid_id. This means there is no log
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
return []
|
return []
|
||||||
where_sql, jid_tuple = self._build_contact_where(account, jid)
|
where_sql, jid_tuple = self._build_contact_where(account, jid)
|
||||||
|
@ -653,7 +653,7 @@ class Logger:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.get_jid_id(jid)
|
self.get_jid_id(jid)
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
# Error trying to create a new jid_id. This means there is no log
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ class Logger:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.get_jid_id(jid)
|
self.get_jid_id(jid)
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
# Error trying to create a new jid_id. This means there is no log
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
return []
|
return []
|
||||||
days_with_logs = []
|
days_with_logs = []
|
||||||
|
@ -736,7 +736,7 @@ class Logger:
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
jid_id = self.get_jid_id(jid, 'ROOM')
|
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
# Error trying to create a new jid_id. This means there is no log
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
return None
|
return None
|
||||||
where_sql = 'jid_id = ?'
|
where_sql = 'jid_id = ?'
|
||||||
|
@ -762,7 +762,7 @@ class Logger:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
jid_id = self.get_jid_id(jid, 'ROOM')
|
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
# Error trying to create a new jid_id. This means there is no log
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
return None
|
return None
|
||||||
where_sql = 'jid_id = %s' % jid_id
|
where_sql = 'jid_id = %s' % jid_id
|
||||||
|
@ -802,7 +802,7 @@ class Logger:
|
||||||
for user in family:
|
for user in family:
|
||||||
try:
|
try:
|
||||||
jid_id = self.get_jid_id(user['jid'])
|
jid_id = self.get_jid_id(user['jid'])
|
||||||
except exceptions.PysqliteOperationalError as e:
|
except exceptions.PysqliteOperationalError:
|
||||||
continue
|
continue
|
||||||
where_sql += 'jid_id = ?'
|
where_sql += 'jid_id = ?'
|
||||||
jid_tuple += (jid_id,)
|
jid_tuple += (jid_id,)
|
||||||
|
|
|
@ -644,7 +644,7 @@ class OptionsParser:
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
con.commit()
|
con.commit()
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError:
|
||||||
pass
|
pass
|
||||||
con.close()
|
con.close()
|
||||||
gajim.config.set('version', '0.11.4.4')
|
gajim.config.set('version', '0.11.4.4')
|
||||||
|
|
|
@ -310,7 +310,7 @@ class HostTester(Socks5, IdleObject):
|
||||||
# read auth response
|
# read auth response
|
||||||
if buff is None or len(buff) != 2:
|
if buff is None or len(buff) != 2:
|
||||||
return None
|
return None
|
||||||
version, method = struct.unpack('!BB', buff[:2])
|
version, method = struct.unpack('!BB', buff[:2].encode('utf-8'))
|
||||||
if version != 0x05 or method == 0xff:
|
if version != 0x05 or method == 0xff:
|
||||||
self.pollend()
|
self.pollend()
|
||||||
return
|
return
|
||||||
|
@ -334,7 +334,7 @@ class HostTester(Socks5, IdleObject):
|
||||||
self._send = self._sock.send
|
self._send = self._sock.send
|
||||||
self._recv = self._sock.recv
|
self._recv = self._sock.recv
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
errnum = ee[0]
|
errnum = ee.errno
|
||||||
# 56 is for freebsd
|
# 56 is for freebsd
|
||||||
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
|
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
|
||||||
# still trying to connect
|
# still trying to connect
|
||||||
|
@ -431,7 +431,7 @@ class ReceiverTester(Socks5, IdleObject):
|
||||||
# read auth response
|
# read auth response
|
||||||
if buff is None or len(buff) != 2:
|
if buff is None or len(buff) != 2:
|
||||||
return None
|
return None
|
||||||
version, method = struct.unpack('!BB', buff[:2])
|
version, method = struct.unpack('!BB', buff[:2].encode('utf-8'))
|
||||||
if version != 0x05 or method == 0xff:
|
if version != 0x05 or method == 0xff:
|
||||||
self.pollend()
|
self.pollend()
|
||||||
return
|
return
|
||||||
|
@ -443,7 +443,7 @@ class ReceiverTester(Socks5, IdleObject):
|
||||||
# read connect response
|
# read connect response
|
||||||
if buff is None or len(buff) < 2:
|
if buff is None or len(buff) < 2:
|
||||||
return None
|
return None
|
||||||
version, reply = struct.unpack('!BB', buff[:2])
|
version, reply = struct.unpack('!BB', buff[:2].encode('utf-8'))
|
||||||
if version != 0x05 or reply != 0x00:
|
if version != 0x05 or reply != 0x00:
|
||||||
self.pollend()
|
self.pollend()
|
||||||
return
|
return
|
||||||
|
|
|
@ -464,7 +464,7 @@ class Socks5:
|
||||||
self._server = ai[4]
|
self._server = ai[4]
|
||||||
break
|
break
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if not isinstance(e, basestring) and e[0] == EINPROGRESS:
|
if e.errno == EINPROGRESS:
|
||||||
break
|
break
|
||||||
# for all other errors, we try other addresses
|
# for all other errors, we try other addresses
|
||||||
continue
|
continue
|
||||||
|
@ -482,7 +482,7 @@ class Socks5:
|
||||||
self._send=self._sock.send
|
self._send=self._sock.send
|
||||||
self._recv=self._sock.recv
|
self._recv=self._sock.recv
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
errnum = ee[0]
|
errnum = ee.errno
|
||||||
self.connect_timeout += 1
|
self.connect_timeout += 1
|
||||||
if errnum == 111 or self.connect_timeout > 1000:
|
if errnum == 111 or self.connect_timeout > 1000:
|
||||||
self.queue._connection_refused(self.streamhost, self.file_props,
|
self.queue._connection_refused(self.streamhost, self.file_props,
|
||||||
|
@ -581,7 +581,7 @@ class Socks5:
|
||||||
"""
|
"""
|
||||||
received = ''
|
received = ''
|
||||||
try:
|
try:
|
||||||
add = self._recv(64)
|
add = self._recv(64).decode('utf-8')
|
||||||
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
|
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
|
||||||
OpenSSL.SSL.WantX509LookupError) as e:
|
OpenSSL.SSL.WantX509LookupError) as e:
|
||||||
log.info('SSL rehandshake request : ' + repr(e))
|
log.info('SSL rehandshake request : ' + repr(e))
|
||||||
|
@ -603,7 +603,7 @@ class Socks5:
|
||||||
OpenSSL.SSL.WantX509LookupError) as e:
|
OpenSSL.SSL.WantX509LookupError) as e:
|
||||||
log.info('SSL rehandshake request :' + repr(e))
|
log.info('SSL rehandshake request :' + repr(e))
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
return len(raw_data)
|
return len(raw_data)
|
||||||
|
|
||||||
|
@ -614,7 +614,7 @@ class Socks5:
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.open_file_for_reading()
|
self.open_file_for_reading()
|
||||||
except IOError as e:
|
except IOError:
|
||||||
self.state = 8 # end connection
|
self.state = 8 # end connection
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
self.file_props.error = -7 # unable to read from file
|
self.file_props.error = -7 # unable to read from file
|
||||||
|
@ -629,7 +629,7 @@ class Socks5:
|
||||||
log.info('SSL rehandshake request :' + repr(e))
|
log.info('SSL rehandshake request :' + repr(e))
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if e.args[0] not in (EINTR, ENOBUFS, EWOULDBLOCK):
|
if e.errno not in (EINTR, ENOBUFS, EWOULDBLOCK):
|
||||||
# peer stopped reading
|
# peer stopped reading
|
||||||
self.state = 8 # end connection
|
self.state = 8 # end connection
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
@ -671,7 +671,7 @@ class Socks5:
|
||||||
if self.remaining_buff != '':
|
if self.remaining_buff != '':
|
||||||
try:
|
try:
|
||||||
fd = self.get_fd()
|
fd = self.get_fd()
|
||||||
except IOError as e:
|
except IOError:
|
||||||
self.disconnect(False)
|
self.disconnect(False)
|
||||||
self.file_props.error = -6 # file system error
|
self.file_props.error = -6 # file system error
|
||||||
return 0
|
return 0
|
||||||
|
@ -692,12 +692,12 @@ class Socks5:
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
fd = self.get_fd()
|
fd = self.get_fd()
|
||||||
except IOError as e:
|
except IOError:
|
||||||
self.disconnect(False)
|
self.disconnect(False)
|
||||||
self.file_props.error = -6 # file system error
|
self.file_props.error = -6 # file system error
|
||||||
return 0
|
return 0
|
||||||
try:
|
try:
|
||||||
buff = self._recv(MAX_BUFF_LEN)
|
buff = self._recv(MAX_BUFF_LEN).decode('utf-8')
|
||||||
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
|
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
|
||||||
OpenSSL.SSL.WantX509LookupError) as e:
|
OpenSSL.SSL.WantX509LookupError) as e:
|
||||||
log.info('SSL rehandshake request :' + repr(e))
|
log.info('SSL rehandshake request :' + repr(e))
|
||||||
|
@ -718,7 +718,7 @@ class Socks5:
|
||||||
return 0
|
return 0
|
||||||
try:
|
try:
|
||||||
fd.write(buff)
|
fd.write(buff)
|
||||||
except IOError as e:
|
except IOError:
|
||||||
self.rem_fd(fd)
|
self.rem_fd(fd)
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
self.file_props.error = -6 # file system error
|
self.file_props.error = -6 # file system error
|
||||||
|
@ -780,9 +780,9 @@ class Socks5:
|
||||||
"""
|
"""
|
||||||
auth_mechanisms = []
|
auth_mechanisms = []
|
||||||
try:
|
try:
|
||||||
num_auth = struct.unpack('!xB', buff[:2])[0]
|
num_auth = struct.unpack('!xB', buff[:2].encode('utf-8'))[0]
|
||||||
for i in list(range(num_auth)):
|
for i in list(range(num_auth)):
|
||||||
mechanism, = struct.unpack('!B', buff[1 + i])
|
mechanism, = struct.unpack('!B', buff[1 + i].encode('utf-8'))
|
||||||
auth_mechanisms.append(mechanism)
|
auth_mechanisms.append(mechanism)
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
@ -799,8 +799,8 @@ class Socks5:
|
||||||
Connect request by domain name
|
Connect request by domain name
|
||||||
"""
|
"""
|
||||||
buff = struct.pack('!BBBBB%dsBB' % len(self.host),
|
buff = struct.pack('!BBBBB%dsBB' % len(self.host),
|
||||||
0x05, 0x01, 0x00, 0x03, len(self.host), self.host, self.port >> 8,
|
0x05, 0x01, 0x00, 0x03, len(self.host), self.host.encode('utf-8'),
|
||||||
self.port & 0xff)
|
self.port >> 8, self.port & 0xff)
|
||||||
return buff
|
return buff
|
||||||
|
|
||||||
def _get_request_buff(self, msg, command = 0x01):
|
def _get_request_buff(self, msg, command = 0x01):
|
||||||
|
@ -809,27 +809,30 @@ class Socks5:
|
||||||
0096)
|
0096)
|
||||||
"""
|
"""
|
||||||
buff = struct.pack('!BBBBB%dsBB' % len(msg),
|
buff = struct.pack('!BBBBB%dsBB' % len(msg),
|
||||||
0x05, command, 0x00, 0x03, len(msg), msg, 0, 0)
|
0x05, command, 0x00, 0x03, len(msg), msg.encode('utf-8'), 0, 0)
|
||||||
return buff
|
return buff
|
||||||
|
|
||||||
def _parse_request_buff(self, buff):
|
def _parse_request_buff(self, buff):
|
||||||
try: # don't trust on what comes from the outside
|
try: # don't trust on what comes from the outside
|
||||||
req_type, host_type, = struct.unpack('!xBxB', buff[:4])
|
req_type, host_type, = struct.unpack('!xBxB', buff[:4].encode(
|
||||||
|
'utf-8'))
|
||||||
if host_type == 0x01:
|
if host_type == 0x01:
|
||||||
host_arr = struct.unpack('!iiii', buff[4:8])
|
host_arr = struct.unpack('!iiii', buff[4:8].encode('utf-8'))
|
||||||
host, = '.'.join(str(s) for s in host_arr)
|
host, = '.'.join(str(s) for s in host_arr)
|
||||||
host_len = len(host)
|
host_len = len(host)
|
||||||
elif host_type == 0x03:
|
elif host_type == 0x03:
|
||||||
host_len, = struct.unpack('!B', buff[4])
|
host_len, = struct.unpack('!B', buff[4].encode('utf-8'))
|
||||||
host, = struct.unpack('!%ds' % host_len, buff[5:5 + host_len])
|
host, = struct.unpack('!%ds' % host_len, buff[5:5 + host_len].\
|
||||||
|
encode('utf-8'))
|
||||||
portlen = len(buff[host_len + 5:])
|
portlen = len(buff[host_len + 5:])
|
||||||
if portlen == 1:
|
if portlen == 1:
|
||||||
port, = struct.unpack('!B', buff[host_len + 5])
|
port, = struct.unpack('!B', buff[host_len + 5].encode('utf-8'))
|
||||||
elif portlen == 2:
|
elif portlen == 2:
|
||||||
port, = struct.unpack('!H', buff[host_len + 5:])
|
port, = struct.unpack('!H', buff[host_len + 5:].encode('utf-8'))
|
||||||
# file data, comes with auth message (Gaim bug)
|
# file data, comes with auth message (Gaim bug)
|
||||||
else:
|
else:
|
||||||
port, = struct.unpack('!H', buff[host_len + 5: host_len + 7])
|
port, = struct.unpack('!H', buff[host_len + 5: host_len + 7].\
|
||||||
|
encode('utf-8'))
|
||||||
self.remaining_buff = buff[host_len + 7:]
|
self.remaining_buff = buff[host_len + 7:]
|
||||||
except Exception:
|
except Exception:
|
||||||
return (None, None, None)
|
return (None, None, None)
|
||||||
|
@ -840,13 +843,13 @@ class Socks5:
|
||||||
Connect response: version, auth method
|
Connect response: version, auth method
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
buff = self._recv()
|
buff = self._recv().decode('utf-8')
|
||||||
except (SSL.WantReadError, SSL.WantWriteError,
|
except (SSL.WantReadError, SSL.WantWriteError,
|
||||||
SSL.WantX509LookupError) as e:
|
SSL.WantX509LookupError) as e:
|
||||||
log.info("SSL rehandshake request : " + repr(e))
|
log.info("SSL rehandshake request : " + repr(e))
|
||||||
raise e
|
raise e
|
||||||
try:
|
try:
|
||||||
version, method = struct.unpack('!BB', buff)
|
version, method = struct.unpack('!BB', buff.encode('utf-8'))
|
||||||
except Exception:
|
except Exception:
|
||||||
version, method = None, None
|
version, method = None, None
|
||||||
if version != 0x05 or method == 0xff:
|
if version != 0x05 or method == 0xff:
|
||||||
|
@ -864,8 +867,8 @@ class Socks5:
|
||||||
"""
|
"""
|
||||||
Get sha of sid + Initiator jid + Target jid
|
Get sha of sid + Initiator jid + Target jid
|
||||||
"""
|
"""
|
||||||
return hashlib.sha1('%s%s%s' % (self.sid, self.initiator,
|
return hashlib.sha1(('%s%s%s' % (self.sid, self.initiator,
|
||||||
self.target)).hexdigest()
|
self.target)).encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
class Socks5Sender(IdleObject):
|
class Socks5Sender(IdleObject):
|
||||||
|
@ -1151,7 +1154,7 @@ class Socks5Client(Socks5):
|
||||||
if self.state == 2: # read auth response
|
if self.state == 2: # read auth response
|
||||||
if buff is None or len(buff) != 2:
|
if buff is None or len(buff) != 2:
|
||||||
return None
|
return None
|
||||||
version, method = struct.unpack('!BB', buff[:2])
|
version, method = struct.unpack('!BB', buff[:2].encode('utf-8'))
|
||||||
if version != 0x05 or method == 0xff:
|
if version != 0x05 or method == 0xff:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
elif self.state == 4: # get approve of our request
|
elif self.state == 4: # get approve of our request
|
||||||
|
@ -1160,18 +1163,23 @@ class Socks5Client(Socks5):
|
||||||
sub_buff = buff[:4]
|
sub_buff = buff[:4]
|
||||||
if len(sub_buff) < 4:
|
if len(sub_buff) < 4:
|
||||||
return None
|
return None
|
||||||
version, address_type = struct.unpack('!BxxB', buff[:4])
|
version, address_type = struct.unpack('!BxxB', buff[:4].encode(
|
||||||
|
'utf-8'))
|
||||||
addrlen = 0
|
addrlen = 0
|
||||||
if address_type == 0x03:
|
if address_type == 0x03:
|
||||||
addrlen = ord(buff[4])
|
addrlen = ord(buff[4])
|
||||||
address = struct.unpack('!%ds' % addrlen, buff[5:addrlen + 5])
|
address = struct.unpack('!%ds' % addrlen, buff[5:addrlen + 5].\
|
||||||
|
encode('utf-8'))
|
||||||
portlen = len(buff[addrlen + 5:])
|
portlen = len(buff[addrlen + 5:])
|
||||||
if portlen == 1:
|
if portlen == 1:
|
||||||
port, = struct.unpack('!B', buff[addrlen + 5])
|
port, = struct.unpack('!B', buff[addrlen + 5].encode(
|
||||||
|
'utf-8'))
|
||||||
elif portlen == 2:
|
elif portlen == 2:
|
||||||
port, = struct.unpack('!H', buff[addrlen + 5:])
|
port, = struct.unpack('!H', buff[addrlen + 5:].encode(
|
||||||
|
'utf-8'))
|
||||||
else: # Gaim bug :)
|
else: # Gaim bug :)
|
||||||
port, = struct.unpack('!H', buff[addrlen + 5:addrlen + 7])
|
port, = struct.unpack('!H', buff[addrlen + 5:addrlen + 7].\
|
||||||
|
encode('utf-8'))
|
||||||
self.remaining_buff = buff[addrlen + 7:]
|
self.remaining_buff = buff[addrlen + 7:]
|
||||||
self.state = 5 # for senders: init file_props and send '\n'
|
self.state = 5 # for senders: init file_props and send '\n'
|
||||||
if self.queue.on_success:
|
if self.queue.on_success:
|
||||||
|
@ -1347,7 +1355,7 @@ class Socks5Listener(IdleObject):
|
||||||
self._serv = OpenSSL.SSL.Connection(
|
self._serv = OpenSSL.SSL.Connection(
|
||||||
jingle_xtls.get_context('server'), self._serv)
|
jingle_xtls.get_context('server'), self._serv)
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.args[0] == EAFNOSUPPORT:
|
if e.errno == EAFNOSUPPORT:
|
||||||
self.ai = None
|
self.ai = None
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -357,8 +357,8 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self.ais = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
|
self.ais = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
|
||||||
socket.SOCK_STREAM)
|
socket.SOCK_STREAM)
|
||||||
except socket.gaierror as e:
|
except socket.gaierror as e:
|
||||||
log.info('Lookup failure for %s: %s[%s]', host, e[1],
|
log.info('Lookup failure for %s: %s', host, str(e),
|
||||||
repr(e[0]), exc_info=True)
|
exc_info=True)
|
||||||
else:
|
else:
|
||||||
self.connect_to_next_ip()
|
self.connect_to_next_ip()
|
||||||
|
|
||||||
|
@ -449,7 +449,8 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self._sock.connect(self._server)
|
self._sock.connect(self._server)
|
||||||
self._sock.setblocking(False)
|
self._sock.setblocking(False)
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
(errnum, errstr) = ee
|
errnum = ee.errno
|
||||||
|
errstr = ee.strerror
|
||||||
errors = (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK)
|
errors = (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK)
|
||||||
if 'WSAEINVAL' in errno.__dict__:
|
if 'WSAEINVAL' in errno.__dict__:
|
||||||
errors += (errno.WSAEINVAL,)
|
errors += (errno.WSAEINVAL,)
|
||||||
|
@ -489,8 +490,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
# get as many bites, as possible, but not more than RECV_BUFSIZE
|
# get as many bites, as possible, but not more than RECV_BUFSIZE
|
||||||
received = self._sock.recv(MAX_BUFF_LEN)
|
received = self._sock.recv(MAX_BUFF_LEN)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if len(e.args) > 0 and isinstance(e.args[0], int):
|
errnum = e.errno
|
||||||
errnum = e[0]
|
|
||||||
# "received" will be empty anyhow
|
# "received" will be empty anyhow
|
||||||
if errnum == socket.SSL_ERROR_WANT_READ:
|
if errnum == socket.SSL_ERROR_WANT_READ:
|
||||||
pass
|
pass
|
||||||
|
@ -560,7 +560,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self._on_send()
|
self._on_send()
|
||||||
|
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e[0] == socket.SSL_ERROR_WANT_WRITE:
|
if e.errno == socket.SSL_ERROR_WANT_WRITE:
|
||||||
return True
|
return True
|
||||||
if self.state < 0:
|
if self.state < 0:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
|
@ -22,7 +22,7 @@ log = logging.getLogger('gajim.c.z.zeroconf_avahi')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dbus.exceptions
|
import dbus.exceptions
|
||||||
except ImportError as e:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from common.zeroconf.zeroconf import C_BARE_NAME, C_INTERFACE, C_PROTOCOL, C_DOMAIN
|
from common.zeroconf.zeroconf import C_BARE_NAME, C_INTERFACE, C_PROTOCOL, C_DOMAIN
|
||||||
|
|
|
@ -24,7 +24,7 @@ from common.zeroconf.zeroconf import C_BARE_NAME, C_DOMAIN
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pybonjour
|
import pybonjour
|
||||||
except ImportError as e:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ class Zeroconf:
|
||||||
try:
|
try:
|
||||||
self.browse_sdRef = pybonjour.DNSServiceBrowse(regtype=self.stype, domain=domain, callBack=self.browse_callback)
|
self.browse_sdRef = pybonjour.DNSServiceBrowse(regtype=self.stype, domain=domain, callBack=self.browse_callback)
|
||||||
except pybonjour.BonjourError as e:
|
except pybonjour.BonjourError as e:
|
||||||
self.error_CB("Error while browsing: %s" % e)
|
self.error_CB("Error while browsing: %s" % str(e))
|
||||||
|
|
||||||
def browse_loop(self):
|
def browse_loop(self):
|
||||||
ready = select.select([self.browse_sdRef], [], [], 0)
|
ready = select.select([self.browse_sdRef], [], [], 0)
|
||||||
|
|
|
@ -3385,7 +3385,7 @@ class ManageBookmarksWindow:
|
||||||
nick = self.nick_entry.get_text()
|
nick = self.nick_entry.get_text()
|
||||||
try:
|
try:
|
||||||
nick = helpers.parse_resource(nick)
|
nick = helpers.parse_resource(nick)
|
||||||
except helpers.InvalidFormat as e:
|
except helpers.InvalidFormat:
|
||||||
dialogs.ErrorDialog(_('Invalid nickname'),
|
dialogs.ErrorDialog(_('Invalid nickname'),
|
||||||
_('Character not allowed'))
|
_('Character not allowed'))
|
||||||
self.nick_entry.set_text(model[iter_][6])
|
self.nick_entry.set_text(model[iter_][6])
|
||||||
|
@ -3424,7 +3424,7 @@ class ManageBookmarksWindow:
|
||||||
self.server_entry.get_text().strip()
|
self.server_entry.get_text().strip()
|
||||||
try:
|
try:
|
||||||
room_jid = helpers.parse_resource(room_jid)
|
room_jid = helpers.parse_resource(room_jid)
|
||||||
except helpers.InvalidFormat as e:
|
except helpers.InvalidFormat:
|
||||||
dialogs.ErrorDialog(_('Invalid room'),
|
dialogs.ErrorDialog(_('Invalid room'),
|
||||||
_('Character not allowed'))
|
_('Character not allowed'))
|
||||||
self.room_entry.set_text(model[iter_][2].split('@')[0])
|
self.room_entry.set_text(model[iter_][2].split('@')[0])
|
||||||
|
|
|
@ -2755,7 +2755,7 @@ class NewChatDialog(InputDialog):
|
||||||
try:
|
try:
|
||||||
jid = helpers.parse_jid(jid)
|
jid = helpers.parse_jid(jid)
|
||||||
except helpers.InvalidFormat as e:
|
except helpers.InvalidFormat as e:
|
||||||
ErrorDialog(_('Invalid JID'), e[0])
|
ErrorDialog(_('Invalid JID'), str(e))
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
ErrorDialog(_('Invalid JID'), _('Unable to parse "%s".') % jid)
|
ErrorDialog(_('Invalid JID'), _('Unable to parse "%s".') % jid)
|
||||||
|
|
|
@ -132,7 +132,7 @@ def parseOpts():
|
||||||
longargs += ' sm-client-id= sm-client-state-file= sm-disable'
|
longargs += ' sm-client-id= sm-client-state-file= sm-disable'
|
||||||
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
|
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
|
||||||
except getopt.error as msg1:
|
except getopt.error as msg1:
|
||||||
print(msg1)
|
print(str(msg1))
|
||||||
print('for help use --help')
|
print('for help use --help')
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
|
|
|
@ -349,10 +349,10 @@ def parse_server_xml(path_to_file):
|
||||||
return handler.servers
|
return handler.servers
|
||||||
# handle exception if unable to open file
|
# handle exception if unable to open file
|
||||||
except IOError as message:
|
except IOError as message:
|
||||||
print(_('Error reading file:') + message, file=sys.stderr)
|
print(_('Error reading file:') + str(message), file=sys.stderr)
|
||||||
# handle exception parsing file
|
# handle exception parsing file
|
||||||
except xml.sax.SAXParseException as message:
|
except xml.sax.SAXParseException as message:
|
||||||
print(_('Error parsing file:') + message, file=sys.stderr)
|
print(_('Error parsing file:') + str(message), file=sys.stderr)
|
||||||
|
|
||||||
def set_unset_urgency_hint(window, unread_messages_no):
|
def set_unset_urgency_hint(window, unread_messages_no):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -766,7 +766,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
#self._insert_text('\u2550'*40)
|
#self._insert_text('\u2550'*40)
|
||||||
self._jump_line()
|
self._jump_line()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(str('Error in hr'+e))
|
log.debug('Error in hr' + str(e))
|
||||||
elif name in LIST_ELEMS:
|
elif name in LIST_ELEMS:
|
||||||
self.list_counters.pop()
|
self.list_counters.pop()
|
||||||
elif name == 'li':
|
elif name == 'li':
|
||||||
|
|
|
@ -427,9 +427,9 @@ class PluginManager(object):
|
||||||
try:
|
try:
|
||||||
module = __import__(module_name)
|
module = __import__(module_name)
|
||||||
except ValueError as value_error:
|
except ValueError as value_error:
|
||||||
log.debug(value_error)
|
log.debug(str(value_error))
|
||||||
except ImportError as import_error:
|
except ImportError as import_error:
|
||||||
log.debug(import_error)
|
log.debug(str(import_error))
|
||||||
|
|
||||||
elif os.path.isdir(file_path) and scan_dirs:
|
elif os.path.isdir(file_path) and scan_dirs:
|
||||||
module_name = elem_name
|
module_name = elem_name
|
||||||
|
@ -440,9 +440,9 @@ class PluginManager(object):
|
||||||
try:
|
try:
|
||||||
module = __import__(module_name)
|
module = __import__(module_name)
|
||||||
except ValueError as value_error:
|
except ValueError as value_error:
|
||||||
log.debug(value_error)
|
log.debug(str(value_error))
|
||||||
except ImportError as import_error:
|
except ImportError as import_error:
|
||||||
log.debug(import_error)
|
log.debug(str(import_error))
|
||||||
|
|
||||||
|
|
||||||
if module is None:
|
if module is None:
|
||||||
|
@ -477,21 +477,21 @@ class PluginManager(object):
|
||||||
|
|
||||||
plugins_found.append(module_attr)
|
plugins_found.append(module_attr)
|
||||||
|
|
||||||
except TypeError as type_error:
|
except TypeError:
|
||||||
# set plugin localization
|
# set plugin localization
|
||||||
try:
|
try:
|
||||||
module_attr._ = _
|
module_attr._ = _
|
||||||
except AttributeError as type_error:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
except configparser.NoOptionError as type_error:
|
except configparser.NoOptionError:
|
||||||
# all fields are required
|
# all fields are required
|
||||||
log.debug('%s : %s' % (module_attr_name,
|
log.debug('%s : %s' % (module_attr_name,
|
||||||
'wrong manifest file. all fields are required!'))
|
'wrong manifest file. all fields are required!'))
|
||||||
except configparser.NoSectionError as type_error:
|
except configparser.NoSectionError:
|
||||||
# info section are required
|
# info section are required
|
||||||
log.debug('%s : %s' % (module_attr_name,
|
log.debug('%s : %s' % (module_attr_name,
|
||||||
'wrong manifest file. info section are required!'))
|
'wrong manifest file. info section are required!'))
|
||||||
except configparser.MissingSectionHeaderError as type_error:
|
except configparser.MissingSectionHeaderError:
|
||||||
# info section are required
|
# info section are required
|
||||||
log.debug('%s : %s' % (module_attr_name,
|
log.debug('%s : %s' % (module_attr_name,
|
||||||
'wrong manifest file. section are required!'))
|
'wrong manifest file. section are required!'))
|
||||||
|
@ -504,10 +504,10 @@ class PluginManager(object):
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
zip_file = zipfile.ZipFile(zip_filename)
|
zip_file = zipfile.ZipFile(zip_filename)
|
||||||
except zipfile.BadZipfile as e:
|
except zipfile.BadZipfile:
|
||||||
# it is not zip file
|
# it is not zip file
|
||||||
raise PluginsystemError(_('Archive corrupted'))
|
raise PluginsystemError(_('Archive corrupted'))
|
||||||
except IOError as e:
|
except IOError:
|
||||||
raise PluginsystemError(_('Archive empty'))
|
raise PluginsystemError(_('Archive empty'))
|
||||||
|
|
||||||
if zip_file.testzip():
|
if zip_file.testzip():
|
||||||
|
|
|
@ -36,6 +36,6 @@ if os.name != 'nt':
|
||||||
try:
|
try:
|
||||||
t = gettext.translation(APP, plugins_locale_dir)
|
t = gettext.translation(APP, plugins_locale_dir)
|
||||||
_ = t.gettext
|
_ = t.gettext
|
||||||
except IOError as msg:
|
except IOError:
|
||||||
from common import i18n
|
from common import i18n
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
|
|
|
@ -743,7 +743,7 @@ class SignalObject(dbus.service.Object):
|
||||||
def prefs_store(self):
|
def prefs_store(self):
|
||||||
try:
|
try:
|
||||||
gajim.interface.save_config()
|
gajim.interface.save_config()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return DBUS_BOOLEAN(False)
|
return DBUS_BOOLEAN(False)
|
||||||
return DBUS_BOOLEAN(True)
|
return DBUS_BOOLEAN(True)
|
||||||
|
|
||||||
|
|
|
@ -15,24 +15,21 @@ from common import jingle_xtls
|
||||||
|
|
||||||
class fake_sock(Mock):
|
class fake_sock(Mock):
|
||||||
def __init__(self, sockobj):
|
def __init__(self, sockobj):
|
||||||
Mock.__init__(self)
|
Mock.__init__(self)
|
||||||
|
|
||||||
self.sockobj = sockobj
|
self.sockobj = sockobj
|
||||||
|
|
||||||
|
|
||||||
def setup_stream(self):
|
def setup_stream(self):
|
||||||
sha1 = self.sockobj._get_sha1_auth()
|
sha1 = self.sockobj._get_sha1_auth()
|
||||||
|
|
||||||
|
self.incoming = []
|
||||||
|
self.incoming.append(self.sockobj._get_auth_response())
|
||||||
|
self.incoming.append(self.sockobj._get_request_buff(sha1, 0x00))
|
||||||
|
self.outgoing = []
|
||||||
|
self.outgoing.append(self.sockobj._get_auth_buff())
|
||||||
|
self.outgoing.append(self.sockobj._get_request_buff(sha1))
|
||||||
|
|
||||||
self.incoming = []
|
|
||||||
self.incoming.append(self.sockobj._get_auth_response())
|
|
||||||
self.incoming.append(
|
|
||||||
self.sockobj._get_request_buff(sha1, 0x00)
|
|
||||||
)
|
|
||||||
self.outgoing = []
|
|
||||||
self.outgoing.append(self.sockobj._get_auth_buff())
|
|
||||||
self.outgoing.append(self.sockobj._get_request_buff(
|
|
||||||
sha1
|
|
||||||
))
|
|
||||||
def switch_stream(self):
|
def switch_stream(self):
|
||||||
# Roles are reversed, client will be expecting server stream
|
# Roles are reversed, client will be expecting server stream
|
||||||
# and server will be expecting client stream
|
# and server will be expecting client stream
|
||||||
|
|
Loading…
Reference in New Issue