"""A more or less complete user-defined wrapper around list objects."""
def __init__(self
, initlist
=None):
# XXX should this accept an arbitrary sequence?
if type(initlist
) == type(self
.data
):
elif isinstance(initlist
, UserList
):
self
.data
[:] = initlist
.data
[:]
self
.data
= list(initlist
)
def __repr__(self
): return repr(self
.data
)
def __lt__(self
, other
): return self
.data
< self
.__cast
(other
)
def __le__(self
, other
): return self
.data
<= self
.__cast
(other
)
def __eq__(self
, other
): return self
.data
== self
.__cast
(other
)
def __ne__(self
, other
): return self
.data
!= self
.__cast
(other
)
def __gt__(self
, other
): return self
.data
> self
.__cast
(other
)
def __ge__(self
, other
): return self
.data
>= self
.__cast
(other
)
if isinstance(other
, UserList
): return other
.data
def __cmp__(self
, other
):
return cmp(self
.data
, self
.__cast
(other
))
def __contains__(self
, item
): return item
in self
.data
def __len__(self
): return len(self
.data
)
def __getitem__(self
, i
): return self
.data
[i
]
def __setitem__(self
, i
, item
): self
.data
[i
] = item
def __delitem__(self
, i
): del self
.data
[i
]
def __getslice__(self
, i
, j
):
i
= max(i
, 0); j
= max(j
, 0)
return self
.__class
__(self
.data
[i
:j
])
def __setslice__(self
, i
, j
, other
):
i
= max(i
, 0); j
= max(j
, 0)
if isinstance(other
, UserList
):
self
.data
[i
:j
] = other
.data
elif isinstance(other
, type(self
.data
)):
self
.data
[i
:j
] = list(other
)
def __delslice__(self
, i
, j
):
i
= max(i
, 0); j
= max(j
, 0)
def __add__(self
, other
):
if isinstance(other
, UserList
):
return self
.__class
__(self
.data
+ other
.data
)
elif isinstance(other
, type(self
.data
)):
return self
.__class
__(self
.data
+ other
)
return self
.__class
__(self
.data
+ list(other
))
def __radd__(self
, other
):
if isinstance(other
, UserList
):
return self
.__class
__(other
.data
+ self
.data
)
elif isinstance(other
, type(self
.data
)):
return self
.__class
__(other
+ self
.data
)
return self
.__class
__(list(other
) + self
.data
)
def __iadd__(self
, other
):
if isinstance(other
, UserList
):
elif isinstance(other
, type(self
.data
)):
return self
.__class
__(self
.data
*n
)
def append(self
, item
): self
.data
.append(item
)
def insert(self
, i
, item
): self
.data
.insert(i
, item
)
def pop(self
, i
=-1): return self
.data
.pop(i
)
def remove(self
, item
): self
.data
.remove(item
)
def count(self
, item
): return self
.data
.count(item
)
def index(self
, item
, *args
): return self
.data
.index(item
, *args
)
def reverse(self
): self
.data
.reverse()
def sort(self
, *args
, **kwds
): self
.data
.sort(*args
, **kwds
)
if isinstance(other
, UserList
):
self
.data
.extend(other
.data
)