Philipp Hörist pushed to branch master at gajim / gajim
Commits: 32e873e6 by Philipp Hörist at 2018-01-03T22:11:42+01:00 Add ALPN Support
- - - - - bd3d195b by Philipp Hörist at 2018-01-03T22:13:33+01:00 Stick to pillow version on Windows build
4.3.0 compiles fine on msys2, later version current not.
- - - - - d3890585 by Philipp Hörist at 2018-01-04T00:08:12+01:00 Refactor css font size parsing
- Get rid of deprecated Gdk.Screen methods - remove support for 'ex' unit - not easily correct implemented and not commonly used
Fixes #8491
- - - - -
4 changed files:
- gajim/common/connection.py - gajim/common/helpers.py - gajim/htmltextview.py - win/_base.sh
Changes:
===================================== gajim/common/connection.py ===================================== --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -63,6 +63,7 @@ from gajim.common import passwords from gajim.common import exceptions from gajim.common import check_X509 from gajim.common.connection_handlers import * +from gajim.common.helpers import version_condition
from gajim.gtkgui_helpers import get_action
@@ -1079,9 +1080,9 @@ class Connection(CommonConnection, ConnectionHandlers): # SRV resolver self._proxy = proxy self._hosts = [ - {'host': h, 'port': p, 'type': 'tls', 'prio': 10, 'weight': 10}, - {'host': h, 'port': ssl_p, 'type': 'ssl', 'prio': 10, 'weight': 10}, - {'host': h, 'port': p, 'type': 'plain', 'prio': 10, 'weight': 10} + {'host': h, 'port': p, 'type': 'tls', 'prio': 10, 'weight': 10, 'alpn': False}, + {'host': h, 'port': ssl_p, 'type': 'ssl', 'prio': 10, 'weight': 10, 'alpn': False}, + {'host': h, 'port': p, 'type': 'plain', 'prio': 10, 'weight': 10, 'alpn': False} ] self._hostname = hostname
@@ -1110,9 +1111,11 @@ class Connection(CommonConnection, ConnectionHandlers): for record in result: service = host[1:] if service.startswith(SERVICE_START_TLS): + record['alpn'] = False self._append_srv_record(record, 'tls') self._append_srv_record(record, 'plain') elif service.startswith(SERVICE_DIRECT_TLS): + record['alpn'] = True self._append_srv_record(record, 'ssl')
self._num_pending_srv_records -= 1 @@ -1209,8 +1212,13 @@ class Connection(CommonConnection, ConnectionHandlers): 'tls_version') cipher_list = app.config.get_per('accounts', self.name, 'cipher_list') - secure_tuple = (self._current_type, cacerts, mycerts, tls_version, - cipher_list) + + if version_condition(nbxmpp.__version__, '0.6.3'): + secure_tuple = (self._current_type, cacerts, mycerts, tls_version, + cipher_list, self._current_host['alpn']) + else: + secure_tuple = (self._current_type, cacerts, mycerts, tls_version, + cipher_list)
con = nbxmpp.NonBlockingClient( domain=self._hostname, @@ -1244,7 +1252,7 @@ class Connection(CommonConnection, ConnectionHandlers): on_connect_failure=self._connect_to_next_host, on_stream_error_cb=self._StreamCB, proxy=self._proxy, - secure_tuple = secure_tuple) + secure_tuple=secure_tuple)
def log_hosttype_info(self, port): msg = '>>>>>> Connecting to %s [%s:%d], type = %s' % (self.name,
===================================== gajim/common/helpers.py ===================================== --- a/gajim/common/helpers.py +++ b/gajim/common/helpers.py @@ -44,6 +44,7 @@ from gajim.common import caps_cache import socket import time from datetime import datetime, timedelta, timezone, tzinfo +from distutils.version import LooseVersion as V
from encodings.punycode import punycode_encode from string import Template @@ -1586,3 +1587,8 @@ def download_image(account, attrs): if proxy and proxy['type'] in ('http', 'socks5'): return _get_img_proxy(attrs, proxy) return _get_img_direct(attrs) + +def version_condition(current_version, required_version): + if V(current_version) < V(required_version): + return False + return True
===================================== gajim/htmltextview.py ===================================== --- a/gajim/htmltextview.py +++ b/gajim/htmltextview.py @@ -67,10 +67,6 @@ __all__ = ['HtmlTextView'] whitespace_rx = re.compile('\s+') allwhitespace_rx = re.compile('^\s*$')
-# pixels = points * display_resolution -display_resolution = 0.3514598*(Gdk.Screen.height() / - float(Gdk.Screen.height_mm())) - # embryo of CSS classes classes = { #'system-message':';display: none', @@ -227,6 +223,11 @@ class HtmlHandler(xml.sax.handler.ContentHandler): self.list_counters = [] # stack (top at head) of list # counters, or None for unordered list
+ def _get_points_from_pixels(self, pixels): + resolution = self.textview.get_screen().get_resolution() + # points = pixels * 72 / resolution + return pixels * 72 / resolution + def _parse_style_color(self, tag, value): color = _parse_css_color(value) tag.set_property('foreground-gdk', color) @@ -236,7 +237,6 @@ class HtmlHandler(xml.sax.handler.ContentHandler): tag.set_property('background-gdk', color) tag.set_property('paragraph-background-gdk', color)
- def _get_current_attributes(self): attrs = self.textview.get_default_attributes() self.iter.backward_char() @@ -266,10 +266,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): val = sign*max(1, min(abs(val), 500)) frac = val/100 if font_relative: - attrs = self._get_current_attributes() - if not attrs.font: - font_size = self.get_font_size() - callback(frac*display_resolution*font_size, *args) + callback(frac, '%', *args) elif block_relative: # CSS says 'Percentage values: refer to width of the closest # block-level ancestor' @@ -285,8 +282,12 @@ class HtmlHandler(xml.sax.handler.ContentHandler): callback(frac, *args) return
- def get_val(): - val = float(value[:-2]) + def get_val(min_val=minl, max_val=maxl): + try: + val = float(value[:-2]) + except: + log.warning('Unable to parse length value "%s"' % value) + return None if val > 0: sign = 1 elif val < 0: @@ -294,27 +295,24 @@ class HtmlHandler(xml.sax.handler.ContentHandler): else: sign = 0 # validate length - return sign*max(minl, min(abs(val*display_resolution), maxl)) - if value.endswith('pt'): # points - callback(get_val()*display_resolution, *args) - - elif value.endswith('em'): # ems, the width of the element's font - attrs = self._get_current_attributes() - if not attrs.font: - font_size = self.get_font_size() - callback(get_val()*display_resolution*font_size, *args) - - elif value.endswith('ex'): # x-height, ~ the height of the letter 'x' - # FIXME: figure out how to calculate this correctly - # for now 'em' size is used as approximation - - attrs = self._get_current_attributes() - if not attrs.font: - font_size = self.get_font_size() - callback(get_val()*display_resolution*font_size, *args) - - elif value.endswith('px'): # pixels - callback(get_val(), *args) + return sign*max(min_val, min(abs(val), max_val)) + if value.endswith('pt'): # points + size = get_val(5, 50) + if size is None: + return + callback(size, 'pt', *args) + + elif value.endswith('em'): + size = get_val(0.3, 4) + if size is None: + return + callback(size, 'em', *args) + + elif value.endswith('px'): # pixels + size = get_val(5, 50) + if size is None: + return + callback(size, 'px', *args)
else: try: @@ -327,13 +325,18 @@ class HtmlHandler(xml.sax.handler.ContentHandler): else: sign = 0 # validate length - val = sign*max(minl, min(abs(val), maxl)) - callback(val, *args) + val = sign*max(5, min(abs(val), 70)) + callback(val, 'px', *args) except Exception: log.warning('Unable to parse length value "%s"' % value)
- def __parse_font_size_cb(length, tag): - tag.set_property('size-points', length/display_resolution) + def __parse_font_size_cb(size, type_, tag): + if type_ in ('em', '%'): + tag.set_property('scale', size) + elif type_ == 'pt': + tag.set_property('size-points', size) + elif type_ == 'px': + tag.set_property('size-points', self._get_points_from_pixels(size)) __parse_font_size_cb = staticmethod(__parse_font_size_cb)
def _parse_style_display(self, tag, value): @@ -830,10 +833,6 @@ class HtmlHandler(xml.sax.handler.ContentHandler): self._jump_line() self._end_span()
- def get_font_size(self): - context = self.conv_textview.tv.get_style_context() - font = context.get_font(Gtk.StateType.NORMAL) - return font.get_size() / Pango.SCALE
class HtmlTextView(Gtk.TextView):
===================================== win/_base.sh ===================================== --- a/win/_base.sh +++ b/win/_base.sh @@ -93,7 +93,7 @@ python-gnupg docutils qrcode keyring -pillow +pillow==4.3.0 "
build_pip install --no-binary ":all:" \
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/b1d45ec008b2ead33e203f5eb3844c0bdb...
--- View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/b1d45ec008b2ead33e203f5eb3844c0bdb... You're receiving this email because of your account on dev.gajim.org.