public PyDictionary getCompareStateDict() { if (compareStateDict == null) { compareStateDict = new PyDictionary(); } return compareStateDict; }
engine.eval(defines + "\n" + script, context); PyDictionary oJython = (PyDictionary) engine.get("result"); Iterator it = oJython.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next();
public static PyObject list_dialects() { return _dialects.keys(); }
PyDictionary environ = new PyDictionary(); environ.put("REQUEST_METHOD", request.getMethod().toString()); environ.put( "SCRIPT_NAME", request.getPathInfo().substring(request.getPathInfo().lastIndexOf("/"))); environ.put("SERVER_NAME", new PyString(request.getServerName())); environ.put("SERVER_PORT", String.valueOf(request.getServerPort())); environ.put("PATH_INFO", request.getPathInfo()); environ.put("QUERY_STRING", request.getQueryString()); environ.put("wsgi.version", new PyTuple(new PyInteger(0), new PyInteger(1))); environ.put("wsgi.url_scheme", request.getScheme()); environ.put("wsgi.input", new PyFile(request.getInputStream())); environ.put("wsgi.errors", new PyFile(System.err)); environ.put("wsgi.multithread", true); environ.put("wsgi.multitprocess", false); environ.put("wsgi.run_once", false); return environ;
final private void load_dict() { int k = marker(); PyDictionary d = new PyDictionary(); for (int i = 0; i < k; i += 2) { PyObject value = pop(); PyObject key = pop(); d.__setitem__(key, value); } pop(); push(d); }
PyDictionary callableBindings = new PyDictionary(); callableBindings.update(bindings);
/** * Equivalent to the standard Python __dir__ method. * * @return a list of names defined by this object. **/ public PyObject __dir__() { PyDictionary accum = new PyDictionary(); __rawdir__(accum); PyList ret = accum.keys(); ret.sort(); return ret; }
@Override public Map<String, Parameter<?>> getOutputs(ScriptEngine engine) throws ScriptException { PyDictionary outputs = (PyDictionary) process(engine).__getattr__("outputs"); Map<String, Parameter<?>> map = new TreeMap<String, Parameter<?>>(); for (String name : (List<String>) outputs.keys()) { PyTuple output = (PyTuple) outputs.get(name); Object type = output.__getitem__(0); Object desc = output.__getitem__(1); // map every key in the optional dictionary as parameter metadata entry Map<String, Object> metadata = null; if (output.size() == 3) { PyDictionary meta = (PyDictionary) output.get(2); if (meta != null && !meta.isEmpty()) { metadata = new HashMap<String, Object>(); for (Object key : meta.keySet()) { metadata.put((String) key, meta.get(key)); } } } map.put(name, parameter(name, type, 1, 1, desc, null, metadata)); } return map; }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___eq___doc) final PyObject dict___eq__(PyObject otherObj) { PyType thisType = getType(); PyType otherType = otherObj.getType(); if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType) || otherType == PyObject.TYPE) { return null; } PyDictionary other = (PyDictionary)otherObj; int an = getMap().size(); int bn = other.getMap().size(); if (an != bn) { return Py.False; } PyList akeys = keys(); for (int i = 0; i < an; i++) { PyObject akey = akeys.pyget(i); PyObject bvalue = other.__finditem__(akey); if (bvalue == null) { return Py.False; } PyObject avalue = __finditem__(akey); if (!avalue._eq(bvalue).__nonzero__()) { return Py.False; } } return Py.True; }
@ExposedMethod(doc = BuiltinDocs.dict_copy_doc) final PyDictionary dict_copy() { return new PyDictionary(getMap()); // no need to clone() }
public PyObject __call__(PyObject[] args, String[] keywords) { ConcurrentMap map = (ConcurrentMap) (factory.__call__().__tojava__(ConcurrentMap.class)); PyDictionary dict; if (dict_type == null) { dict = new PyDictionary(map, true); } else { dict = new PyDictionaryDerived(dict_type, map, true); } dict.updateCommon(args, keywords, "dict"); return dict; }
PyDictionary inputs = (PyDictionary) process(engine).__getattr__("inputs"); if (args.size() != inputs.size()) { throw new RuntimeException( String.format( "process function specified %d arguments but" + " describes %d inputs", args.size(), inputs.size())); for (int i = 0; i < args.size(); i++) { String arg = args.get(i).toString(); PyTuple input = (PyTuple) inputs.get(arg); if (input == null) { throw new RuntimeException( HashSet<String> otherKeys = new HashSet<String>(meta.keySet()); otherKeys.remove("min"); otherKeys.remove("max"); metadata.put(key, meta.get(key));
private <T> T getParameter(PyDictionary meta, String key, Class<T> targetType, T defaultValue) { if (!meta.containsKey(key)) { return defaultValue; } Object value = meta.get(key); return (T) Converters.convert(value, targetType); }
private static PyObject mapEq(PyObject self, PyObject other) { Map<Object, Object> selfMap = ((Map<Object, Object>) self.getJavaProxy()); if (other.getType().isSubType(PyDictionary.TYPE)) { PyDictionary oDict = (PyDictionary) other; if (selfMap.size() != oDict.size()) { return Py.False; } for (Object jkey : selfMap.keySet()) { Object jval = selfMap.get(jkey); PyObject oVal = oDict.__finditem__(Py.java2py(jkey)); if (oVal == null) { return Py.False; } if (!Py.java2py(jval)._eq(oVal).__nonzero__()) { return Py.False; } } return Py.True; } else { Object oj = other.getJavaProxy(); if (oj instanceof Map) { Map<Object, Object> oMap = (Map<Object, Object>) oj; return Py.newBoolean(selfMap.equals(oMap)); } else { return null; } } }
private void load_ext(int length) { int code = read_binint(length); // TODO: support _extension_cache PyObject key = inverted_registry.get(Py.newInteger(code)); if (key == null) { throw new PyException(Py.ValueError, "unregistered extension code " + code); } String module = key.__finditem__(0).toString(); String name = key.__finditem__(1).toString(); push(find_class(module, name)); }
public PyObject __abs__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__abs__"); if (impl!=null) return impl.__get__(this,self_type).__call__(); return super.__abs__(); }
public static PyObject pigToPython(Object object) { if (object instanceof Tuple) { return pigTupleToPyTuple((Tuple) object); } else if (object instanceof DataBag) { PyList list = new PyList(); for (Tuple bagTuple : (DataBag) object) { list.add(pigTupleToPyTuple(bagTuple)); } return list; } else if (object instanceof Map<?, ?>) { PyDictionary newMap = new PyDictionary(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { newMap.put(entry.getKey(), pigToPython(entry.getValue())); } return newMap; } else if (object instanceof DataByteArray) { return Py.java2py(((DataByteArray) object).get()); } else { return Py.java2py(object); } }
/** * Motivated by a NPE reported on http://bugs.jython.org/issue1174. */ public void testBasicEval() throws Exception { PyDictionary test = new PyDictionary(); test.__setitem__(new PyUnicode("one"), new PyUnicode("two")); PythonInterpreter.initialize(System.getProperties(), null, new String[] {}); PythonInterpreter interp = new PythonInterpreter(); PyObject pyo = interp.eval("{u'one': u'two'}"); assertEquals(test, pyo); }
try { if (arg3 instanceof PyStringMap) { PyDictionary d = new PyDictionary(); d.update(arg3); arg3 = d;
@ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.dict___cmp___doc) final int dict___cmp__(PyObject otherObj) { PyType thisType = getType(); PyType otherType = otherObj.getType(); if (otherType != thisType && !thisType.isSubType(otherType) int an = getMap().size(); int bn = other.getMap().size(); if (an < bn) { return -1; PyList akeys = keys(); PyList bkeys = other.keys(); PyObject avalue = __finditem__(akey); PyObject bvalue = other.__finditem__(bkey); if (avalue == null) { if (bvalue == null) {