def nsmutabledict_fromkeys(cls, keys, value=None): value = container_wrap(value) result = cls.alloc().init() for k in keys: result[container_wrap(k)] = value return result
def nsdict_new(cls, *args, **kwds): if len(args) == 0: pass elif len(args) == 1: d = dict() if isinstance(args[0], collections.Mapping): items = args[0].items() else: items = args[0] for k , v in items: d[container_wrap(k)] = container_wrap(v) for k, v in kwds.items(): d[container_wrap(k)] = container_wrap(v) return cls.dictionaryWithDictionary_(d) else: raise TypeError( "dict expected at most 1 arguments, got {0}".format( len(args))) if kwds: d = dict() for k, v in kwds.items(): d[container_wrap(k)] = container_wrap(v) return cls.dictionaryWithDictionary_(d) return cls.dictionary()
def nsdict_new(cls, *args, **kwds): if len(args) == 0: pass elif len(args) == 1: d = dict() if isinstance(args[0], collections.abc.Mapping): items = args[0].items() else: items = args[0] for k, v in items: d[container_wrap(k)] = container_wrap(v) for k, v in kwds.items(): d[container_wrap(k)] = container_wrap(v) return cls.dictionaryWithDictionary_(d) else: raise TypeError("dict expected at most 1 arguments, got {0}".format( len(args))) if kwds: d = dict() for k, v in kwds.items(): d[container_wrap(k)] = container_wrap(v) return cls.dictionaryWithDictionary_(d) return cls.dictionary()
def nsarray_index(self, item, start=0, stop=_index_sentinel): if start == 0 and stop is _index_sentinel: res = self.indexOfObject_(container_wrap(item)) if res == NSNotFound: raise ValueError("%s.index(x): x not in list" % (type(self).__name__, )) else: itemcount = self.count() if start < 0: start = itemcount + start if start < 0: start = 0 if stop is not _index_sentinel: if stop < 0: stop = itemcount + stop if stop < 0: stop = 0 else: stop = itemcount if itemcount == 0: raise ValueError("%s.index(x): x not in list" % (type(self).__name__, )) if start >= itemcount: raise ValueError("%s.index(x): x not in list" % (type(self).__name__, )) if stop >= itemcount: stop = itemcount - 1 if stop <= start: ln = 0 else: ln = stop - start if ln == 0: raise ValueError("%s.index(x): x not in list" % (type(self).__name__, )) if ln > sys.maxsize: # pragma: no cover ln = sys.maxsize res = self.indexOfObject_inRange_(item, (start, ln)) if res == NSNotFound: raise ValueError("%s.index(x): x not in list" % (type(self).__name__, )) return res
def nsarray_index(self, item, start=0, stop=_index_sentinel): if start == 0 and stop is _index_sentinel: res = self.indexOfObject_(container_wrap(item)) if res == NSNotFound: raise ValueError("%s.index(x): x not in list" % (type(self).__name__,)) else: itemcount = self.count() if start < 0: start = itemcount + start if start < 0: start = 0 if stop is not _index_sentinel: if stop < 0: stop = itemcount + stop if stop < 0: stop = 0 else: stop = itemcount if itemcount == 0: raise ValueError("%s.index(x): x not in list" % (type(self).__name__,)) if start >= itemcount: raise ValueError("%s.index(x): x not in list" % (type(self).__name__,)) if stop >= itemcount: stop = itemcount - 1 if stop <= start: ln = 0 else: ln = stop - start if ln == 0: raise ValueError("%s.index(x): x not in list" % (type(self).__name__,)) if ln > sys.maxsize: # pragma: no cover ln = sys.maxsize res = self.indexOfObject_inRange_(item, (start, ln)) if res == NSNotFound: raise ValueError("%s.index(x): x not in list" % (type(self).__name__,)) return res
def get_objectForKey_(self, key, dflt=None): res = self.objectForKey_(container_wrap(key)) if res is None: res = dflt return res
def __getitem__objectForKey_(self, key): res = self.objectForKey_(container_wrap(key)) return container_unwrap(res, KeyError, key)
def nsarray_extend(self, anArray): for item in anArray: self.addObject_(container_wrap(item))
def nsarray_append(self, anObject): self.addObject_(container_wrap(anObject))
def nsset_add(self, value): hash(value) self.addObject_(container_wrap(value))
def __setitem__setObject_forKey_(self, key, value): self.setObject_forKey_(container_wrap(value), container_wrap(key))
def nsset_remove(self, value): hash(value) value = container_wrap(value) if value not in self: raise KeyError(value) self.removeObject_(value)
def nsdict_fromkeys(cls, keys, value=None): keys = [container_wrap(k) for k in keys] values = [container_wrap(value)]*len(keys) return cls.dictionaryWithObjects_forKeys_(values, keys)
def nsarray__contains__(self, elem): return bool(self.containsObject_(container_wrap(elem)))
def nsarray_insert(self, idx, item): if idx < 0: idx += self.count() if idx < 0: idx = 0 self.insertObject_atIndex_(container_wrap(item), idx)
def contains_objectForKey_(self, key): res = self.objectForKey_(container_wrap(key)) return res is not None
def nsset_discard(self, value): hash(value) self.removeObject_(container_wrap(value))
def __delitem__removeObjectForKey_(self, key): self.removeObjectForKey_(container_wrap(key))
def nsdict_fromkeys(cls, keys, value=None): keys = [container_wrap(k) for k in keys] values = [container_wrap(value)] * len(keys) return cls.dictionaryWithObjects_forKeys_(values, keys)