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):
tzinfo=timezone)
try:
settings = SIPSimpleSettings()
response = urllib.request.urlopen(settings.server.enrollment_url, urllib.parse.urlencode(dict(enrollment_data)))
response_data = json.loads(response.read().replace(r'\/', '/'))
data = urllib.parse.urlencode(dict(enrollment_data))
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)
if response_data['success']:
try:
......
......@@ -61,9 +61,9 @@ class ChatStyleError(Exception): pass
class ChatHtmlTemplates(object):
def __init__(self, style_path):
try:
self.message = open(os.path.join(style_path, 'html/message.html')).read().decode('utf-8')
self.message_continuation = open(os.path.join(style_path, 'html/message_continuation.html')).read().decode('utf-8')
self.notification = open(os.path.join(style_path, 'html/notification.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()
self.notification = open(os.path.join(style_path, 'html/notification.html')).read()
except (OSError, IOError):
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):
#
class Link(object):
__slots__ = 'prev', 'next', 'key', '__weakref__'
__slots__ = 'prev', 'next', '__next__', 'key', '__weakref__'
class OrderedSet(MutableSet):
......@@ -241,12 +241,12 @@ class ChatContent(object, metaclass=ABCMeta):
@property
def date(self):
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
def time(self):
language, encoding = locale.getlocale(locale.LC_TIME)
return self.timestamp.strftime('%H:%M').decode(encoding or 'ascii')
return self.timestamp.strftime('%H:%M')
@property
def text_direction(self):
......@@ -1739,21 +1739,22 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
video_info = blink_session.info.streams.video
chat_info = blink_session.info.streams.chat
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'):
state_map = {'initialized': 'Disconnected',
'connecting/dns_lookup': 'Finding destination',
'connecting': 'Connecting',
'connecting/dns_lookup': 'Finding destination...',
'connecting': 'Connecting...',
'connecting/ringing': 'Ringing',
'connecting/starting': 'Starting media',
'connecting/starting': 'Starting media...',
'connected': 'Connected'}
if blink_session.state == 'ended':
self.status_value_label.setForegroundRole(QPalette.AlternateBase if blink_session.state.error else QPalette.WindowText)
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.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
self.status_title_label.setVisible(not want_duration)
......@@ -2206,13 +2207,14 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
message = notification.data.message
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/'):
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:
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()
if account_manager.has_account(uri):
account = account_manager.get_account(uri)
......
......@@ -116,7 +116,7 @@ class HTTPURL(str):
class FileURL(str):
def __new__(cls, value):
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)
......
......@@ -54,6 +54,7 @@ from blink.widgets.util import ContextMenuActions
__all__ = ['Group', 'Contact', 'ContactModel', 'ContactSearchModel', 'ContactListView', 'ContactSearchListView', 'ContactEditorDialog', 'URIUtils']
translation_table = dict.fromkeys(map(ord, ' \t'), None)
@implementer(IObserver)
class VirtualGroupManager(object, metaclass=Singleton):
......@@ -4681,11 +4682,11 @@ class URIUtils(object):
@classmethod
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
def trim_number(cls, token):
return cls.number_trim_re.sub('', token)
return cls.number_trim_re.sub('', token.decode()).encode()
@classmethod
def find_contact(cls, uri, display_name=None, exact=True):
......@@ -4697,7 +4698,7 @@ class URIUtils(object):
uri += '@' + AccountManager().default_account.id.domain
if not uri.startswith(('sip:', 'sips:')):
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):
uri.user = cls.trim_number(uri.user)
is_number = True
......
......@@ -62,7 +62,7 @@ class BlinkPresenceState(object):
hostname = socket.gethostname()
except Exception:
hostname = 'localhost'
account_id = hashlib.md5(self.account.id).hexdigest()
account_id = hashlib.md5(self.account.id.encode()).hexdigest()
timestamp = ISOTimestamp.now()
doc = pidf.PIDF(str(self.account.uri))
......
......@@ -127,7 +127,7 @@ class IconManager(object, metaclass=Singleton):
pixmap.save(buffer, 'png')
data = str(buffer.data())
with open(filename, 'wb') as f:
f.write(data)
f.write(data.encode())
icon = QIcon(pixmap)
icon.filename = filename
icon.content = data
......@@ -154,7 +154,7 @@ class IconManager(object, metaclass=Singleton):
pixmap.save(buffer, 'png')
data = str(buffer.data())
with open(filename, 'wb') as f:
f.write(data)
f.write(data.encode())
icon = QIcon(pixmap)
icon.filename = filename
icon.content = data
......
......@@ -57,6 +57,8 @@ from blink.widgets.zrtp import ZRTPWidget
__all__ = ['ClientConference', 'ConferenceDialog', 'AudioSessionModel', 'AudioSessionListView', 'ChatSessionModel', 'ChatSessionListView', 'SessionManager']
translation_table = dict.fromkeys(map(ord, ' \t'), None)
class Container(object):
pass
......@@ -159,7 +161,7 @@ class MSRPStreamInfo(object, metaclass=ABCMeta):
class AudioStreamInfo(RTPStreamInfo):
@property
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):
......@@ -169,7 +171,7 @@ class VideoStreamInfo(RTPStreamInfo):
@property
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):
super(VideoStreamInfo, self).update(stream)
......@@ -196,8 +198,8 @@ class ChatStreamInfo(MSRPStreamInfo):
self.encryption = 'OTR' if stream.encryption.active else None
self.encryption_cipher = stream.encryption.cipher if stream.encryption.active else None
if self.encryption == 'OTR':
self.otr_key_fingerprint = stream.encryption.key_fingerprint
self.otr_peer_fingerprint = stream.encryption.peer_fingerprint
self.otr_key_fingerprint = stream.encryption.key_fingerprint.hex().upper()
self.otr_peer_fingerprint = stream.encryption.peer_fingerprint.hex().upper()
self.otr_peer_name = stream.encryption.peer_name
self.otr_verified = stream.encryption.verified
......@@ -908,7 +910,8 @@ class BlinkSession(BlinkSessionBase):
uri += '@' + self.account.id.domain
if not uri.startswith(('sip:', 'sips:')):
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):
uri.user = URIUtils.trim_number(uri.user)
if isinstance(self.account, Account):
......@@ -1656,7 +1659,7 @@ class AudioSessionWidget(base_class, ui_class):
session.zrtp_widget.hide()
session.zrtp_widget.peer_name = stream_info.zrtp_peer_name
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.show()
session.zrtp_widget.peer_name_value.setFocus(Qt.OtherFocusReason)
......@@ -2095,7 +2098,7 @@ class AudioSessionItem(object):
def _NH_BlinkSessionInfoUpdated(self, notification):
if 'media' in notification.data.elements:
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
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))
......@@ -4003,7 +4006,7 @@ class BlinkFileTransfer(BlinkSessionBase):
uri += '@' + self.account.id.domain
if not uri.startswith(('sip:', 'sips:')):
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):
self.state = 'ending' # if the state is not ending already, simulate it
......
......@@ -115,7 +115,7 @@ class OTRWidget(base_class, ui_class):
@staticmethod
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):
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