Commit d485698c authored by Adrian Georgescu's avatar Adrian Georgescu

Various fixes

parent 097bed52
...@@ -423,8 +423,9 @@ class AddAccountDialog(base_class, ui_class, metaclass=QSingleton): ...@@ -423,8 +423,9 @@ class AddAccountDialog(base_class, ui_class, metaclass=QSingleton):
tzinfo=timezone) tzinfo=timezone)
try: try:
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
response = urllib.request.urlopen(settings.server.enrollment_url, urllib.parse.urlencode(dict(enrollment_data))) data = urllib.parse.urlencode(dict(enrollment_data))
response_data = json.loads(response.read().replace(r'\/', '/')) response = urllib.request.urlopen(settings.server.enrollment_url, data.encode())
response_data = json.loads(response.read().decode('utf-8').replace(r'\/', '/'))
response_data = defaultdict(lambda: None, response_data) response_data = defaultdict(lambda: None, response_data)
if response_data['success']: if response_data['success']:
try: try:
......
...@@ -61,9 +61,9 @@ class ChatStyleError(Exception): pass ...@@ -61,9 +61,9 @@ class ChatStyleError(Exception): pass
class ChatHtmlTemplates(object): class ChatHtmlTemplates(object):
def __init__(self, style_path): def __init__(self, style_path):
try: try:
self.message = open(os.path.join(style_path, 'html/message.html')).read().decode('utf-8') self.message = open(os.path.join(style_path, 'html/message.html')).read()
self.message_continuation = open(os.path.join(style_path, 'html/message_continuation.html')).read().decode('utf-8') self.message_continuation = open(os.path.join(style_path, 'html/message_continuation.html')).read()
self.notification = open(os.path.join(style_path, 'html/notification.html')).read().decode('utf-8') self.notification = open(os.path.join(style_path, 'html/notification.html')).read()
except (OSError, IOError): except (OSError, IOError):
raise ChatStyleError("missing or unreadable chat message html template files in %s" % os.path.join(style_path, 'html')) raise ChatStyleError("missing or unreadable chat message html template files in %s" % os.path.join(style_path, 'html'))
...@@ -107,7 +107,7 @@ class ChatMessageStyle(object): ...@@ -107,7 +107,7 @@ class ChatMessageStyle(object):
# #
class Link(object): class Link(object):
__slots__ = 'prev', 'next', 'key', '__weakref__' __slots__ = 'prev', 'next', '__next__', 'key', '__weakref__'
class OrderedSet(MutableSet): class OrderedSet(MutableSet):
...@@ -241,12 +241,12 @@ class ChatContent(object, metaclass=ABCMeta): ...@@ -241,12 +241,12 @@ class ChatContent(object, metaclass=ABCMeta):
@property @property
def date(self): def date(self):
language, encoding = locale.getlocale(locale.LC_TIME) language, encoding = locale.getlocale(locale.LC_TIME)
return self.timestamp.strftime('%d %b %Y').decode(encoding or 'ascii') return self.timestamp.strftime('%d %b %Y')
@property @property
def time(self): def time(self):
language, encoding = locale.getlocale(locale.LC_TIME) language, encoding = locale.getlocale(locale.LC_TIME)
return self.timestamp.strftime('%H:%M').decode(encoding or 'ascii') return self.timestamp.strftime('%H:%M')
@property @property
def text_direction(self): def text_direction(self):
...@@ -1739,21 +1739,22 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -1739,21 +1739,22 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
video_info = blink_session.info.streams.video video_info = blink_session.info.streams.video
chat_info = blink_session.info.streams.chat chat_info = blink_session.info.streams.chat
screen_info = blink_session.info.streams.screen_sharing screen_info = blink_session.info.streams.screen_sharing
state = "%s" % blink_session.state
if 'status' in elements and blink_session.state in ('initialized', 'connecting/*', 'connected/*', 'ended'): if 'status' in elements and blink_session.state in ('initialized', 'connecting/*', 'connected/*', 'ended'):
state_map = {'initialized': 'Disconnected', state_map = {'initialized': 'Disconnected',
'connecting/dns_lookup': 'Finding destination', 'connecting/dns_lookup': 'Finding destination...',
'connecting': 'Connecting', 'connecting': 'Connecting...',
'connecting/ringing': 'Ringing', 'connecting/ringing': 'Ringing',
'connecting/starting': 'Starting media', 'connecting/starting': 'Starting media...',
'connected': 'Connected'} 'connected': 'Connected'}
if blink_session.state == 'ended': if blink_session.state == 'ended':
self.status_value_label.setForegroundRole(QPalette.AlternateBase if blink_session.state.error else QPalette.WindowText) self.status_value_label.setForegroundRole(QPalette.AlternateBase if blink_session.state.error else QPalette.WindowText)
self.status_value_label.setText(blink_session.state.reason) self.status_value_label.setText(blink_session.state.reason)
elif blink_session.state in state_map: elif state in state_map:
self.status_value_label.setForegroundRole(QPalette.WindowText) self.status_value_label.setForegroundRole(QPalette.WindowText)
self.status_value_label.setText(state_map[blink_session.state]) self.status_value_label.setText(state_map[state])
want_duration = blink_session.state == 'connected/*' or blink_session.state == 'ended' and not blink_session.state.error want_duration = blink_session.state == 'connected/*' or blink_session.state == 'ended' and not blink_session.state.error
self.status_title_label.setVisible(not want_duration) self.status_title_label.setVisible(not want_duration)
...@@ -2206,13 +2207,14 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2206,13 +2207,14 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
message = notification.data.message message = notification.data.message
if message.content_type.startswith('image/'): if message.content_type.startswith('image/'):
content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.encode('base64').rstrip()) content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip())
elif message.content_type.startswith('text/'): elif message.content_type.startswith('text/'):
content = HtmlProcessor.autolink(message.content if message.content_type == 'text/html' else QTextDocument(message.content).toHtml()) content = message.content.decode()
content = HtmlProcessor.autolink(content if message.content_type == 'text/html' else QTextDocument(content).toHtml())
else: else:
return return
uri = '%s@%s' % (message.sender.uri.user, message.sender.uri.host) uri = '%s@%s' % (message.sender.uri.user.decode(), message.sender.uri.host.decode())
account_manager = AccountManager() account_manager = AccountManager()
if account_manager.has_account(uri): if account_manager.has_account(uri):
account = account_manager.get_account(uri) account = account_manager.get_account(uri)
......
...@@ -116,7 +116,7 @@ class HTTPURL(str): ...@@ -116,7 +116,7 @@ class HTTPURL(str):
class FileURL(str): class FileURL(str):
def __new__(cls, value): def __new__(cls, value):
if not value.startswith('file:'): if not value.startswith('file:'):
value = 'file:' + pathname2url(os.path.abspath(value).encode('utf-8')).decode('utf-8') value = 'file:' + pathname2url(os.path.abspath(value))
return str.__new__(cls, value) return str.__new__(cls, value)
......
...@@ -54,6 +54,7 @@ from blink.widgets.util import ContextMenuActions ...@@ -54,6 +54,7 @@ from blink.widgets.util import ContextMenuActions
__all__ = ['Group', 'Contact', 'ContactModel', 'ContactSearchModel', 'ContactListView', 'ContactSearchListView', 'ContactEditorDialog', 'URIUtils'] __all__ = ['Group', 'Contact', 'ContactModel', 'ContactSearchModel', 'ContactListView', 'ContactSearchListView', 'ContactEditorDialog', 'URIUtils']
translation_table = dict.fromkeys(map(ord, ' \t'), None)
@implementer(IObserver) @implementer(IObserver)
class VirtualGroupManager(object, metaclass=Singleton): class VirtualGroupManager(object, metaclass=Singleton):
...@@ -4681,11 +4682,11 @@ class URIUtils(object): ...@@ -4681,11 +4682,11 @@ class URIUtils(object):
@classmethod @classmethod
def is_number(cls, token): def is_number(cls, token):
return cls.number_re.match(token) is not None return cls.number_re.match(token.decode()) is not None
@classmethod @classmethod
def trim_number(cls, token): def trim_number(cls, token):
return cls.number_trim_re.sub('', token) return cls.number_trim_re.sub('', token.decode()).encode()
@classmethod @classmethod
def find_contact(cls, uri, display_name=None, exact=True): def find_contact(cls, uri, display_name=None, exact=True):
...@@ -4697,7 +4698,7 @@ class URIUtils(object): ...@@ -4697,7 +4698,7 @@ class URIUtils(object):
uri += '@' + AccountManager().default_account.id.domain uri += '@' + AccountManager().default_account.id.domain
if not uri.startswith(('sip:', 'sips:')): if not uri.startswith(('sip:', 'sips:')):
uri = 'sip:' + uri uri = 'sip:' + uri
uri = SIPURI.parse(str(uri).translate(None, ' \t')) uri = SIPURI.parse(str(uri).translate(translation_table))
if cls.is_number(uri.user): if cls.is_number(uri.user):
uri.user = cls.trim_number(uri.user) uri.user = cls.trim_number(uri.user)
is_number = True is_number = True
......
...@@ -62,7 +62,7 @@ class BlinkPresenceState(object): ...@@ -62,7 +62,7 @@ class BlinkPresenceState(object):
hostname = socket.gethostname() hostname = socket.gethostname()
except Exception: except Exception:
hostname = 'localhost' hostname = 'localhost'
account_id = hashlib.md5(self.account.id).hexdigest() account_id = hashlib.md5(self.account.id.encode()).hexdigest()
timestamp = ISOTimestamp.now() timestamp = ISOTimestamp.now()
doc = pidf.PIDF(str(self.account.uri)) doc = pidf.PIDF(str(self.account.uri))
......
...@@ -127,7 +127,7 @@ class IconManager(object, metaclass=Singleton): ...@@ -127,7 +127,7 @@ class IconManager(object, metaclass=Singleton):
pixmap.save(buffer, 'png') pixmap.save(buffer, 'png')
data = str(buffer.data()) data = str(buffer.data())
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
f.write(data) f.write(data.encode())
icon = QIcon(pixmap) icon = QIcon(pixmap)
icon.filename = filename icon.filename = filename
icon.content = data icon.content = data
...@@ -154,7 +154,7 @@ class IconManager(object, metaclass=Singleton): ...@@ -154,7 +154,7 @@ class IconManager(object, metaclass=Singleton):
pixmap.save(buffer, 'png') pixmap.save(buffer, 'png')
data = str(buffer.data()) data = str(buffer.data())
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
f.write(data) f.write(data.encode())
icon = QIcon(pixmap) icon = QIcon(pixmap)
icon.filename = filename icon.filename = filename
icon.content = data icon.content = data
......
...@@ -57,6 +57,8 @@ from blink.widgets.zrtp import ZRTPWidget ...@@ -57,6 +57,8 @@ from blink.widgets.zrtp import ZRTPWidget
__all__ = ['ClientConference', 'ConferenceDialog', 'AudioSessionModel', 'AudioSessionListView', 'ChatSessionModel', 'ChatSessionListView', 'SessionManager'] __all__ = ['ClientConference', 'ConferenceDialog', 'AudioSessionModel', 'AudioSessionListView', 'ChatSessionModel', 'ChatSessionListView', 'SessionManager']
translation_table = dict.fromkeys(map(ord, ' \t'), None)
class Container(object): class Container(object):
pass pass
...@@ -159,7 +161,7 @@ class MSRPStreamInfo(object, metaclass=ABCMeta): ...@@ -159,7 +161,7 @@ class MSRPStreamInfo(object, metaclass=ABCMeta):
class AudioStreamInfo(RTPStreamInfo): class AudioStreamInfo(RTPStreamInfo):
@property @property
def codec(self): def codec(self):
return '{} {}kHz'.format(self.codec_name, self.sample_rate//1000) if self.codec_name else None return '{} {}kHz'.format(self.codec_name.decode().capitalize(), self.sample_rate//1000) if self.codec_name else None
class VideoStreamInfo(RTPStreamInfo): class VideoStreamInfo(RTPStreamInfo):
...@@ -169,7 +171,7 @@ class VideoStreamInfo(RTPStreamInfo): ...@@ -169,7 +171,7 @@ class VideoStreamInfo(RTPStreamInfo):
@property @property
def codec(self): def codec(self):
return '{0.codec_name} {0.framerate:.3g}fps'.format(self) if self.codec_name else None return '{0.codec_name.decode()} {0.framerate:.3g}fps'.format(self) if self.codec_name else None
def update(self, stream): def update(self, stream):
super(VideoStreamInfo, self).update(stream) super(VideoStreamInfo, self).update(stream)
...@@ -196,8 +198,8 @@ class ChatStreamInfo(MSRPStreamInfo): ...@@ -196,8 +198,8 @@ class ChatStreamInfo(MSRPStreamInfo):
self.encryption = 'OTR' if stream.encryption.active else None self.encryption = 'OTR' if stream.encryption.active else None
self.encryption_cipher = stream.encryption.cipher if stream.encryption.active else None self.encryption_cipher = stream.encryption.cipher if stream.encryption.active else None
if self.encryption == 'OTR': if self.encryption == 'OTR':
self.otr_key_fingerprint = stream.encryption.key_fingerprint self.otr_key_fingerprint = stream.encryption.key_fingerprint.hex().upper()
self.otr_peer_fingerprint = stream.encryption.peer_fingerprint self.otr_peer_fingerprint = stream.encryption.peer_fingerprint.hex().upper()
self.otr_peer_name = stream.encryption.peer_name self.otr_peer_name = stream.encryption.peer_name
self.otr_verified = stream.encryption.verified self.otr_verified = stream.encryption.verified
...@@ -908,7 +910,8 @@ class BlinkSession(BlinkSessionBase): ...@@ -908,7 +910,8 @@ class BlinkSession(BlinkSessionBase):
uri += '@' + self.account.id.domain uri += '@' + self.account.id.domain
if not uri.startswith(('sip:', 'sips:')): if not uri.startswith(('sip:', 'sips:')):
uri = 'sip:' + uri uri = 'sip:' + uri
uri = SIPURI.parse(str(uri).translate(None, ' \t'))
uri = SIPURI.parse(str(uri).translate(translation_table))
if URIUtils.is_number(uri.user): if URIUtils.is_number(uri.user):
uri.user = URIUtils.trim_number(uri.user) uri.user = URIUtils.trim_number(uri.user)
if isinstance(self.account, Account): if isinstance(self.account, Account):
...@@ -1656,7 +1659,7 @@ class AudioSessionWidget(base_class, ui_class): ...@@ -1656,7 +1659,7 @@ class AudioSessionWidget(base_class, ui_class):
session.zrtp_widget.hide() session.zrtp_widget.hide()
session.zrtp_widget.peer_name = stream_info.zrtp_peer_name session.zrtp_widget.peer_name = stream_info.zrtp_peer_name
session.zrtp_widget.peer_verified = stream_info.zrtp_verified session.zrtp_widget.peer_verified = stream_info.zrtp_verified
session.zrtp_widget.sas = stream_info.zrtp_sas session.zrtp_widget.sas = stream_info.zrtp_sas.decode()
session.zrtp_widget.setGeometry(rect) session.zrtp_widget.setGeometry(rect)
session.zrtp_widget.show() session.zrtp_widget.show()
session.zrtp_widget.peer_name_value.setFocus(Qt.OtherFocusReason) session.zrtp_widget.peer_name_value.setFocus(Qt.OtherFocusReason)
...@@ -2095,7 +2098,7 @@ class AudioSessionItem(object): ...@@ -2095,7 +2098,7 @@ class AudioSessionItem(object):
def _NH_BlinkSessionInfoUpdated(self, notification): def _NH_BlinkSessionInfoUpdated(self, notification):
if 'media' in notification.data.elements: if 'media' in notification.data.elements:
audio_info = self.blink_session.info.streams.audio audio_info = self.blink_session.info.streams.audio
self.type = 'HD Audio' if audio_info.sample_rate >= 16000 else 'Audio' self.type = 'HD Audio' if audio_info.sample_rate and audio_info.sample_rate >= 16000 else 'Audio'
self.codec_info = audio_info.codec self.codec_info = audio_info.codec
if audio_info.encryption is not None: if audio_info.encryption is not None:
self.widget.srtp_label.setToolTip('Media is encrypted using %s (%s)' % (audio_info.encryption, audio_info.encryption_cipher)) self.widget.srtp_label.setToolTip('Media is encrypted using %s (%s)' % (audio_info.encryption, audio_info.encryption_cipher))
...@@ -4003,7 +4006,7 @@ class BlinkFileTransfer(BlinkSessionBase): ...@@ -4003,7 +4006,7 @@ class BlinkFileTransfer(BlinkSessionBase):
uri += '@' + self.account.id.domain uri += '@' + self.account.id.domain
if not uri.startswith(('sip:', 'sips:')): if not uri.startswith(('sip:', 'sips:')):
uri = 'sip:' + uri uri = 'sip:' + uri
return SIPURI.parse(str(uri).translate(None, ' \t')) return SIPURI.parse(str(uri).translate(translation_table))
def _terminate(self, failure_reason=None): def _terminate(self, failure_reason=None):
self.state = 'ending' # if the state is not ending already, simulate it self.state = 'ending' # if the state is not ending already, simulate it
......
...@@ -115,7 +115,7 @@ class OTRWidget(base_class, ui_class): ...@@ -115,7 +115,7 @@ class OTRWidget(base_class, ui_class):
@staticmethod @staticmethod
def _encode_fingerprint(fingerprint): def _encode_fingerprint(fingerprint):
return re.sub('....', lambda match: match.group(0) + {match.endpos: '', match.endpos//2: '<br/>'}.get(match.end(), ' '), fingerprint.encode('hex').upper()) return re.sub('....', lambda match: match.group(0) + {match.endpos: '', match.endpos//2: '<br/>'}.get(match.end(), ' '), fingerprint.encode().hex().upper())
def _check_name_changes(self): def _check_name_changes(self):
peer_name = self.peer_name_value.text() peer_name = self.peer_name_value.text()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment