Use OrderedDict (if python >= 2.7) to display ordered dicts in objects (debug window and testproto.py)
This commit is contained in:
parent
2c6975d9c8
commit
be3c1edaf1
@ -31,7 +31,16 @@
|
|||||||
# start dev
|
# start dev
|
||||||
#
|
#
|
||||||
|
|
||||||
import struct, zlib
|
import collections, struct, zlib
|
||||||
|
|
||||||
|
if hasattr(collections, 'OrderedDict'):
|
||||||
|
# python >= 2.7
|
||||||
|
class WeechatDict(collections.OrderedDict):
|
||||||
|
def __str__(self):
|
||||||
|
return '{%s}' % ', '.join(['%s: %s' % (repr(key), repr(self[key])) for key in self])
|
||||||
|
else:
|
||||||
|
# python <= 2.6
|
||||||
|
WeechatDict = dict
|
||||||
|
|
||||||
class WeechatObject:
|
class WeechatObject:
|
||||||
def __init__(self, objtype, value, separator='\n'):
|
def __init__(self, objtype, value, separator='\n'):
|
||||||
@ -50,14 +59,14 @@ class WeechatObject:
|
|||||||
lines = ['%skeys: %s%s%spath: %s' % (self.separator1, str(self.value['keys']), self.separator, self.indent, str(self.value['path']))]
|
lines = ['%skeys: %s%s%spath: %s' % (self.separator1, str(self.value['keys']), self.separator, self.indent, str(self.value['path']))]
|
||||||
for i, item in enumerate(self.value['items']):
|
for i, item in enumerate(self.value['items']):
|
||||||
lines.append(' item %d:%s%s' % ((i + 1), self.separator,
|
lines.append(' item %d:%s%s' % ((i + 1), self.separator,
|
||||||
self.separator.join(['%s%s: %s' % (self.indent * 2, key, self._str_value(value)) for key, value in sorted(item.items())])))
|
self.separator.join(['%s%s: %s' % (self.indent * 2, key, self._str_value(value)) for key, value in item.items()])))
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
def _str_value_infolist(self):
|
def _str_value_infolist(self):
|
||||||
lines = ['%sname: %s' % (self.separator1, self.value['name'])]
|
lines = ['%sname: %s' % (self.separator1, self.value['name'])]
|
||||||
for i, item in enumerate(self.value['items']):
|
for i, item in enumerate(self.value['items']):
|
||||||
lines.append(' item %d:%s%s' % ((i + 1), self.separator,
|
lines.append(' item %d:%s%s' % ((i + 1), self.separator,
|
||||||
self.separator.join(['%s%s: %s' % (self.indent * 2, key, self._str_value(value)) for key, value in sorted(item.items())])))
|
self.separator.join(['%s%s: %s' % (self.indent * 2, key, self._str_value(value)) for key, value in item.items()])))
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
def _str_value_other(self):
|
def _str_value_other(self):
|
||||||
@ -197,7 +206,7 @@ class Protocol:
|
|||||||
type_keys = self._obj_type()
|
type_keys = self._obj_type()
|
||||||
type_values = self._obj_type()
|
type_values = self._obj_type()
|
||||||
count = self._obj_int()
|
count = self._obj_int()
|
||||||
hashtable = {}
|
hashtable = WeechatDict()
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
key = self._obj_cb[type_keys]()
|
key = self._obj_cb[type_keys]()
|
||||||
value = self._obj_cb[type_values]()
|
value = self._obj_cb[type_values]()
|
||||||
@ -212,14 +221,15 @@ class Protocol:
|
|||||||
list_path = path.split('/')
|
list_path = path.split('/')
|
||||||
list_keys = keys.split(',')
|
list_keys = keys.split(',')
|
||||||
keys_types = []
|
keys_types = []
|
||||||
dict_keys = {}
|
dict_keys = WeechatDict()
|
||||||
for key in list_keys:
|
for key in list_keys:
|
||||||
items = 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 = []
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
item = {}
|
item = WeechatDict()
|
||||||
|
item['__path'] = []
|
||||||
pointers = []
|
pointers = []
|
||||||
for p in range(0, len(list_path)):
|
for p in range(0, len(list_path)):
|
||||||
pointers.append(self._obj_ptr())
|
pointers.append(self._obj_ptr())
|
||||||
@ -246,7 +256,7 @@ class Protocol:
|
|||||||
items = []
|
items = []
|
||||||
for i in range(0, count_items):
|
for i in range(0, count_items):
|
||||||
count_vars = self._obj_int()
|
count_vars = self._obj_int()
|
||||||
variables = {}
|
variables = WeechatDict()
|
||||||
for v in range(0, count_vars):
|
for v in range(0, count_vars):
|
||||||
var_name = self._obj_str()
|
var_name = self._obj_str()
|
||||||
var_type = self._obj_type()
|
var_type = self._obj_type()
|
||||||
|
Loading…
Reference in New Issue
Block a user