def __setitem__(self, i, item): if isinstance(i, slice): o = [] o_tmp = item if type(o_tmp) not in (list, tuple) and not isinstance(o_tmp, UserList): o_tmp = list(o_tmp) for item in o_tmp: if type(item) == unicode: o.append(u_encode(item)) else: o.append(item) MultiPurposeList.__setitem__(self, i, o) else: _i = item if type(_i) is unicode: _i = u_encode(item) # TODO: fix this bug properly, it is really strange that it fails on # python3 without it. Problem is that when _i = ['* '] it fails in # UserList.__setitem__() but if it is changed in debuggr in __setitem__ # like item[0] = '* ' it works, hence this is some quirk with unicode # stuff but very likely vim 7.4 BUG too. if isinstance(_i, UserList) and sys.version_info > (3, ): _i = [s.encode('utf8').decode('utf8') for s in _i] MultiPurposeList.__setitem__(self, i, _i)
def __getitem__(self, i): if isinstance(i, slice): return [u_decode(item) if type(item) is str else item \ for item in MultiPurposeList.__getitem__(self, i)] else: item = MultiPurposeList.__getitem__(self, i) if type(item) is str: return u_decode(item) return item
def __setslice__(self, i, j, other): o = [] o_tmp = other if type(o_tmp) not in (list, tuple) and not isinstance(o_tmp, UserList): o_tmp = list(o_tmp) for item in o_tmp: if type(item) == unicode: o.append(item.encode(u'utf-8')) else: o.append(item) MultiPurposeList.__setslice__(self, i, j, o)
def extend(self, other): o = [] o_tmp = other if type(o_tmp) not in (list, tuple) and not isinstance(o_tmp, UserList): o_tmp = list(o_tmp) for i in o_tmp: if type(i) is unicode: o.append(i.encode(u'utf-8')) else: o.append(i) MultiPurposeList.extend(self, o)
def __setitem__(self, i, item): _i = item if type(_i) is unicode: _i = u_encode(item) # TODO: fix this bug properly, it is really strange that it fails on # python3 without it. Problem is that when _i = ['* '] it fails in # UserList.__setitem__() but if it is changed in debuggr in __setitem__ # like item[0] = '* ' it works, hence this is some quirk with unicode # stuff but very likely vim 7.4 BUG too. if isinstance(_i, UserList) and sys.version_info > (3, ): _i = [s.encode('utf8').decode('utf8') for s in _i] MultiPurposeList.__setitem__(self, i, _i)
def __iadd__(self, other): o = [] o_tmp = other if type(o_tmp) not in (list, tuple) and not isinstance(o_tmp, UserList): o_tmp = list(o_tmp) for i in o_tmp: if type(i) is unicode: o.append(u_encode(i)) else: o.append(i) return MultiPurposeList.__iadd__(self, o)
def append(self, item): i = item if type(item) is str: i = item.encode(u'utf-8') MultiPurposeList.append(self, i)
def __setitem__(self, i, item): _i = item if type(_i) is unicode: _i = item.encode(u'utf-8') MultiPurposeList.__setitem__(self, i, _i)
def __getslice__(self, i, j): return [item.decode(u'utf-8') if type(item) is str else item \ for item in MultiPurposeList.__getslice__(self, i, j)]
def __getitem__(self, i): item = MultiPurposeList.__getitem__(self, i) if type(item) is str: return item.decode(u'utf-8') return item
def index(self, item, *args): i = item if type(i) is unicode: i = u_encode(item) MultiPurposeList.index(self, i, *args)
def pop(self, i=-1): return MultiPurposeList.pop(self, i).decode(u'utf-8')
def pop(self, i=-1): return u_decode(MultiPurposeList.pop(self, i))
def append(self, item): i = item if type(item) is str: i = u_encode(item) MultiPurposeList.append(self, i)
def insert(self, i, item): _i = item if type(_i) is str: _i = item.encode(u'utf-8') MultiPurposeList.insert(self, i, _i)
def __init__(self, vimbuffer, on_change=None): MultiPurposeList.__init__(self, on_change=on_change) # replace data with vimbuffer to make operations change the actual # buffer self.data = vimbuffer
def index(self, item, *args): i = item if type(i) is unicode: i = item.encode(u'utf-8') MultiPurposeList.index(self, i, *args)
def __contains__(self, item): i = item if type(i) is unicode: i = item.encode(u'utf-8') return MultiPurposeList.__contains__(self, i)
def insert(self, i, item): _i = item if type(_i) is str: _i = u_encode(item) MultiPurposeList.insert(self, i, _i)