def popitem_setObject_forKey_(self): try: it = self.keyEnumerator() k = container_unwrap(it.nextObject(), StopIteration) except (StopIteration, IndexError): raise KeyError("popitem on an empty %s" % (type(self).__name__,)) else: result = (k, container_unwrap(self.objectForKey_(k), KeyError)) self.removeObjectForKey_(k) return result
def nsset_pop(self): if len(self) == 0: raise KeyError() v = self.anyObject() self.removeObject_(v) return container_unwrap(v, KeyError)
def nsarray__getitem__(self, idx): if isinstance(idx, slice): start, stop, step = idx.indices(len(self)) return [self[i] for i in range(start, stop, step)] elif not isinstance(idx, int): raise TypeError("index must be a number") if idx < 0: idx += len(self) if idx < 0: raise IndexError("list index out of range") return container_unwrap(self.objectAtIndex_(idx), RuntimeError)
def nsarray__getitem__(self, idx): if isinstance(idx, slice): start, stop, step = idx.indices(len(self)) return [self[i] for i in range(start, stop, step)] elif not isinstance(idx, INT_TYPES): raise TypeError("index must be a number") if idx < 0: idx += len(self) if idx < 0: raise IndexError("list index out of range") return container_unwrap(self.objectAtIndex_(idx), RuntimeError)
def __getitem__objectForKey_(self, key): res = self.objectForKey_(container_wrap(key)) return container_unwrap(res, KeyError, key)
def __next__(self): self._size -= 1 return container_unwrap(self._enum.nextObject(), StopIteration)