Ver código fonte

Implement ListProxy.{count,index,extend,insert,reverse,sort}

tags/v0.1
Ben Kurtovic 12 anos atrás
pai
commit
b5fb7e18f2
1 arquivos alterados com 32 adições e 10 exclusões
  1. +32
    -10
      mwparserfromhell/smart_list.py

+ 32
- 10
mwparserfromhell/smart_list.py Ver arquivo

@@ -189,22 +189,44 @@ class _ListProxy(list):
def _render(self): def _render(self):
return self._parent[self._start:self._stop:self._step] return self._parent[self._start:self._stop:self._step]


def append(self, obj):
self._parent.insert(self._stop, obj)
def append(self, item):
self._parent.insert(self._stop, item)


count
def count(self, item):
return self._render().count(item)


index
def index(self, item, start=None, stop=None):
if start is not None:
if stop is not None:
return self._render().index(item, start, stop)
return self._render().index(item, start)
return self._render().index(item)


extend
def extend(self, item):
self._parent[self._stop:self._stop] = item


def insert(self, index, obj):
self._parent.insert(self._start + index, obj)
def insert(self, index, item):
self._parent.insert(self._start + index, item)


pop pop


remove remove


reverse

sort
def reverse(self):
item = self._render()
item.reverse()
self._parent[self._start:self._stop:self._step] = item

def sort(self, cmp=None, key=None, reverse=None):
item = self._render()
if cmp is not None:
if key is not None:
if reverse is not None:
item.sort(cmp, key, reverse)
else:
item.sort(cmp, key)
else:
item.sort(cmp)
else:
item.sort()
self._parent[self._start:self._stop:self._step] = item

Carregando…
Cancelar
Salvar