Add object "htb" (hashtable) in protocol, rename object code "lis" to "inl" (infolist)
This commit is contained in:
parent
93865c21ce
commit
c738936b1e
1 changed files with 24 additions and 11 deletions
|
@ -64,7 +64,7 @@ class WeechatObject:
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
self._obj_cb = {'hda': self._str_value_hdata,
|
self._obj_cb = {'hda': self._str_value_hdata,
|
||||||
'lis': self._str_value_infolist,
|
'inl': self._str_value_infolist,
|
||||||
}
|
}
|
||||||
return '%s: %s' % (self.objtype, self._obj_cb.get(self.objtype, self._str_value_other)())
|
return '%s: %s' % (self.objtype, self._obj_cb.get(self.objtype, self._str_value_other)())
|
||||||
|
|
||||||
|
@ -104,11 +104,21 @@ class Protocol:
|
||||||
'buf': self._obj_buffer,
|
'buf': self._obj_buffer,
|
||||||
'ptr': self._obj_ptr,
|
'ptr': self._obj_ptr,
|
||||||
'tim': self._obj_time,
|
'tim': self._obj_time,
|
||||||
|
'htb': self._obj_hashtable,
|
||||||
'hda': self._obj_hdata,
|
'hda': self._obj_hdata,
|
||||||
'inf': self._obj_info,
|
'inf': self._obj_info,
|
||||||
'lis': self._obj_infolist,
|
'inl': self._obj_infolist,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _obj_type(self):
|
||||||
|
"""Read type in data (3 chars)."""
|
||||||
|
if len(self.data) < 3:
|
||||||
|
self.data = ''
|
||||||
|
return ''
|
||||||
|
objtype = str(self.data[0:3])
|
||||||
|
self.data = self.data[3:]
|
||||||
|
return objtype
|
||||||
|
|
||||||
def _obj_len_data(self, length_size):
|
def _obj_len_data(self, length_size):
|
||||||
"""Read length (1 or 4 bytes), then value with this length."""
|
"""Read length (1 or 4 bytes), then value with this length."""
|
||||||
if len(self.data) < length_size:
|
if len(self.data) < length_size:
|
||||||
|
@ -177,6 +187,18 @@ class Protocol:
|
||||||
return None
|
return None
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
def _obj_hashtable(self):
|
||||||
|
"""Read a hashtable in data (type for keys + type for values + count + items)."""
|
||||||
|
type_keys = self._obj_type()
|
||||||
|
type_values = self._obj_type()
|
||||||
|
count = self._obj_int()
|
||||||
|
hashtable = {}
|
||||||
|
for i in xrange(0, count):
|
||||||
|
key = self._obj_cb[type_keys]()
|
||||||
|
value = self._obj_cb[type_values]()
|
||||||
|
hashtable[key] = value
|
||||||
|
return hashtable
|
||||||
|
|
||||||
def _obj_hdata(self):
|
def _obj_hdata(self):
|
||||||
"""Read a hdata in data."""
|
"""Read a hdata in data."""
|
||||||
path = self._obj_str()
|
path = self._obj_str()
|
||||||
|
@ -228,15 +250,6 @@ class Protocol:
|
||||||
items.append(variables)
|
items.append(variables)
|
||||||
return {'name': name, 'items': items}
|
return {'name': name, 'items': items}
|
||||||
|
|
||||||
def _obj_type(self):
|
|
||||||
"""Read type in data (3 chars)."""
|
|
||||||
if len(self.data) < 3:
|
|
||||||
self.data = ''
|
|
||||||
return ''
|
|
||||||
objtype = str(self.data[0:3])
|
|
||||||
self.data = self.data[3:]
|
|
||||||
return objtype
|
|
||||||
|
|
||||||
def decode(self, data):
|
def decode(self, data):
|
||||||
"""Decode binary data and return list of objects."""
|
"""Decode binary data and return list of objects."""
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
Loading…
Reference in a new issue