More fixes.
- Use logging instead of print to silence errors when possible. - Parse object types as string instead of bytes.
This commit is contained in:
parent
8e15c19fb2
commit
35136f99b0
@ -32,7 +32,7 @@ class InputLineEdit(QtWidgets.QLineEdit):
|
|||||||
textSent = QtCore.Signal(str)
|
textSent = QtCore.Signal(str)
|
||||||
|
|
||||||
def __init__(self, scroll_widget):
|
def __init__(self, scroll_widget):
|
||||||
super().__init__(scroll_widget)
|
super().__init__()
|
||||||
self.scroll_widget = scroll_widget
|
self.scroll_widget = scroll_widget
|
||||||
self._history = []
|
self._history = []
|
||||||
self._history_index = -1
|
self._history_index = -1
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
RE_COLOR_ATTRS = r'[*!/_|]*'
|
RE_COLOR_ATTRS = r'[*!/_|]*'
|
||||||
RE_COLOR_STD = r'(?:%s\d{2})' % RE_COLOR_ATTRS
|
RE_COLOR_STD = r'(?:%s\d{2})' % RE_COLOR_ATTRS
|
||||||
@ -75,6 +76,9 @@ WEECHAT_BASIC_COLORS = (
|
|||||||
('white', 0))
|
('white', 0))
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Color():
|
class Color():
|
||||||
def __init__(self, color_options, debug=False):
|
def __init__(self, color_options, debug=False):
|
||||||
self.color_options = color_options
|
self.color_options = color_options
|
||||||
@ -92,7 +96,7 @@ class Color():
|
|||||||
index = int(color)
|
index = int(color)
|
||||||
return '\x01(Fr%s)' % self.color_options[index]
|
return '\x01(Fr%s)' % self.color_options[index]
|
||||||
except: # noqa: E722
|
except: # noqa: E722
|
||||||
print('Error decoding WeeChat color "%s"' % color)
|
log.debug('Error decoding WeeChat color "%s"' % color)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def _convert_terminal_color(self, fg_bg, attrs, color):
|
def _convert_terminal_color(self, fg_bg, attrs, color):
|
||||||
@ -100,7 +104,7 @@ class Color():
|
|||||||
index = int(color)
|
index = int(color)
|
||||||
return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index))
|
return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index))
|
||||||
except: # noqa: E722
|
except: # noqa: E722
|
||||||
print('Error decoding terminal color "%s"' % color)
|
log.debug('Error decoding terminal color "%s"' % color)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def _convert_color_attr(self, fg_bg, color):
|
def _convert_color_attr(self, fg_bg, color):
|
||||||
@ -123,7 +127,7 @@ class Color():
|
|||||||
return self._convert_terminal_color(fg_bg, attrs,
|
return self._convert_terminal_color(fg_bg, attrs,
|
||||||
WEECHAT_BASIC_COLORS[index][1])
|
WEECHAT_BASIC_COLORS[index][1])
|
||||||
except: # noqa: E722
|
except: # noqa: E722
|
||||||
print('Error decoding color "%s"' % color)
|
log.debug('Error decoding color "%s"' % color)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def _attrcode_to_char(self, code):
|
def _attrcode_to_char(self, code):
|
||||||
|
@ -147,7 +147,7 @@ class Protocol:
|
|||||||
if len(self.data) < 3:
|
if len(self.data) < 3:
|
||||||
self.data = ''
|
self.data = ''
|
||||||
return ''
|
return ''
|
||||||
objtype = bytes(self.data[0:3])
|
objtype = self.data[0:3].decode()
|
||||||
self.data = self.data[3:]
|
self.data = self.data[3:]
|
||||||
return objtype
|
return objtype
|
||||||
|
|
||||||
@ -197,12 +197,9 @@ class Protocol:
|
|||||||
def _obj_str(self):
|
def _obj_str(self):
|
||||||
"""Read a string in data (length on 4 bytes + content)."""
|
"""Read a string in data (length on 4 bytes + content)."""
|
||||||
value = self._obj_len_data(4)
|
value = self._obj_len_data(4)
|
||||||
if value is None:
|
if value in ("", None):
|
||||||
return None
|
return ""
|
||||||
try:
|
|
||||||
return value.decode()
|
return value.decode()
|
||||||
except AttributeError:
|
|
||||||
return value
|
|
||||||
|
|
||||||
def _obj_buffer(self):
|
def _obj_buffer(self):
|
||||||
"""Read a buffer in data (length on 4 bytes + data)."""
|
"""Read a buffer in data (length on 4 bytes + data)."""
|
||||||
@ -227,8 +224,8 @@ class Protocol:
|
|||||||
Read a hashtable in data
|
Read a hashtable in data
|
||||||
(type for keys + type for values + count + items).
|
(type for keys + type for values + count + items).
|
||||||
"""
|
"""
|
||||||
type_keys = self._obj_type().decode()
|
type_keys = self._obj_type()
|
||||||
type_values = self._obj_type().decode()
|
type_values = self._obj_type()
|
||||||
count = self._obj_int()
|
count = self._obj_int()
|
||||||
hashtable = WeechatDict()
|
hashtable = WeechatDict()
|
||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
@ -247,7 +244,7 @@ class Protocol:
|
|||||||
keys_types = []
|
keys_types = []
|
||||||
dict_keys = WeechatDict()
|
dict_keys = WeechatDict()
|
||||||
for key in list_keys:
|
for key in list_keys:
|
||||||
items = list(item for item in key.split(':'))
|
items = key.split(':')
|
||||||
keys_types.append(items)
|
keys_types.append(items)
|
||||||
dict_keys[items[0]] = items[1]
|
dict_keys[items[0]] = items[1]
|
||||||
items = []
|
items = []
|
||||||
@ -258,7 +255,6 @@ class Protocol:
|
|||||||
for _ in enumerate(list_path):
|
for _ in enumerate(list_path):
|
||||||
pointers.append(self._obj_ptr())
|
pointers.append(self._obj_ptr())
|
||||||
for key, objtype in keys_types:
|
for key, objtype in keys_types:
|
||||||
objtype = objtype
|
|
||||||
item[key] = self._obj_cb[objtype]()
|
item[key] = self._obj_cb[objtype]()
|
||||||
item['__path'] = pointers
|
item['__path'] = pointers
|
||||||
items.append(item)
|
items.append(item)
|
||||||
@ -296,7 +292,7 @@ class Protocol:
|
|||||||
|
|
||||||
def _obj_array(self):
|
def _obj_array(self):
|
||||||
"""Read an array of values in data."""
|
"""Read an array of values in data."""
|
||||||
type_values = self._obj_type().decode()
|
type_values = self._obj_type()
|
||||||
count_values = self._obj_int()
|
count_values = self._obj_int()
|
||||||
values = []
|
values = []
|
||||||
for _ in range(count_values):
|
for _ in range(count_values):
|
||||||
@ -328,7 +324,7 @@ class Protocol:
|
|||||||
# read objects
|
# read objects
|
||||||
objects = WeechatObjects(separator=separator)
|
objects = WeechatObjects(separator=separator)
|
||||||
while len(self.data) > 0:
|
while len(self.data) > 0:
|
||||||
objtype = self._obj_type().decode()
|
objtype = self._obj_type()
|
||||||
value = self._obj_cb[objtype]()
|
value = self._obj_cb[objtype]()
|
||||||
objects.append(WeechatObject(objtype, value, separator=separator))
|
objects.append(WeechatObject(objtype, value, separator=separator))
|
||||||
return WeechatMessage(size, size_uncompressed, compression,
|
return WeechatMessage(size, size_uncompressed, compression,
|
||||||
|
Loading…
Reference in New Issue
Block a user