@Override public void __delitem__(String key) { Object ret = table.remove(key); if (ret == null) { throw Py.KeyError(key); } }
public PyObject pop(PyObject key) { if (table.size() == 0) { throw Py.KeyError("pop(): dictionary is empty"); } return stringmap_pop(key, null); }
/** * Return the value for the keyword, raise a KeyError if the keyword does * not exist. */ public PyObject kw(String kw) { if (!hasKw(kw)) { throw Py.KeyError(kw); } return keywords.get(kw); }
public PyObject __getitem__(String key) { PyObject o = __finditem__(key); if (null == o) { throw Py.KeyError(key); } else { return o; } }
@ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject stringmap_popitem() { Iterator<Entry<Object, PyObject>> it = table.entrySet().iterator(); if (!it.hasNext()) { throw Py.KeyError("popitem(): dictionary is empty"); } PyTuple tuple = itemTuple(it.next()); it.remove(); return tuple; }
@ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject dict_popitem() { Iterator<Entry<PyObject, PyObject>> it = getMap().entrySet().iterator(); if (!it.hasNext()) { throw Py.KeyError("popitem(): dictionary is empty"); } Entry<PyObject, PyObject> entry = it.next(); PyTuple tuple = new PyTuple(entry.getKey(), entry.getValue()); it.remove(); return tuple; }
@Override public PyObject __call__(PyObject key) { Object jkey = Py.tojava(key, Object.class); if (asMap().remove(jkey) == null) { throw Py.KeyError(key); } return Py.None; } };
@Override public PyObject __call__(PyObject value) { boolean removed = asSet().remove(value.__tojava__(Object.class)); if (!removed) { throw Py.KeyError(value); } return Py.None; } };
@ExposedMethod(defaults = "null", doc = BuiltinDocs.dict_pop_doc) final PyObject stringmap_pop(PyObject key, PyObject failobj) { PyObject value = table.remove(pyToKey(key)); if (value == null) { if (failobj == null) { throw Py.KeyError(key); } else { return failobj; } } return value; }
@ExposedMethod(doc = BuiltinDocs.dict___getitem___doc) protected final PyObject defaultdict___getitem__(PyObject key) { try { return backingMap.get(key); } catch (Exception ex) { throw Py.KeyError(key); } }
@Override public PyObject __call__() { if (asMap().size() == 0) { throw Py.KeyError("popitem(): map is empty"); } Object key = asMap().keySet().toArray()[0]; Object val = asMap().remove(key); return Py.java2py(val); } };
@ExposedMethod(defaults = "null", doc = BuiltinDocs.dict_pop_doc) final PyObject dict_pop(PyObject key, PyObject defaultValue) { if (!getMap().containsKey(key)) { if (defaultValue == null) { throw Py.KeyError(key); } return defaultValue; } return getMap().remove(key); }
@Override public void __delitem__(String key) { int scope = context.getAttributesScope(key); if (scope == -1) throw Py.KeyError(key); context.removeAttribute(key, scope); }
/** * This method does NOT call __setitem__ instead it relies on the fact that it is * called within the context of `CacheLoader#load` to actually insert the value * into the dict. */ @ExposedMethod final PyObject defaultdict___missing__(PyObject key) { if (defaultFactory == Py.None) { throw Py.KeyError(key); } return defaultFactory.__call__(); }
@ExposedMethod(doc = BuiltinDocs.dict___delitem___doc) final void stringmap___delitem__(PyObject key) { if (key instanceof PyString) { __delitem__(((PyString)key).internedString()); } else { Object ret = table.remove(key); if (ret == null) { throw Py.KeyError(key); } } }
@ExposedMethod(doc = BuiltinDocs.dict___delitem___doc) final void dict___delitem__(PyObject key) { Object ret = getMap().remove(key); if (ret == null) { throw Py.KeyError(key.toString()); } }
@Override public PyObject __call__(PyObject key) { Object jkey = Py.tojava(key, Object.class); if (asMap().containsKey(jkey)) { return Py.java2py(asMap().get(jkey)); } else { throw Py.KeyError(key); } } };
@Override public PyObject __call__(PyObject key, PyObject _default) { Object jkey = Py.tojava(key, Object.class); if (asMap().containsKey(jkey)) { PyObject value = Py.java2py(asMap().remove(jkey)); assert (value != null); return Py.java2py(value); } else { if (_default == null) { throw Py.KeyError(key); } return _default; } } };
@ExposedMethod(doc = BuiltinDocs.dict___getitem___doc) final PyObject stringmap___getitem__(PyObject key) { if (key instanceof PyString) { return __getitem__(((PyString)key).internedString()); } else { PyObject o = __finditem__(key); if (null == o) { throw Py.KeyError(key); } else { return o; } } }
@ExposedMethod(doc = BuiltinDocs.dict___getitem___doc) protected final PyObject dict___getitem__(PyObject key) { PyObject result = getMap().get(key); if (result != null) { return result; } // Look up __missing__ method if we're a subclass. PyType type = getType(); if (type != TYPE) { PyObject missing = type.lookup("__missing__"); if (missing != null) { return missing.__get__(this, type).__call__(key); } } throw Py.KeyError(key); }