public PyDictionary getCompareStateDict() { if (compareStateDict == null) { compareStateDict = new PyDictionary(); } return compareStateDict; }
public PyLocal(PyType subType) { super(subType); // Don't lazy load the underlying dict in the instantiating thread; that would // call __init__ a the second time tdict.set(new Object[] { new PyDictionary() }); }
@Override public PyObject fastGetDict() { Object[] local = tdict.get(); PyDictionary ldict = (PyDictionary)(local[0]); if (ldict == null) { ldict = new PyDictionary(); local[0] = ldict; dispatch__init__(args, keywords); } return ldict; }
private PyDictionary getDictionary() { return new PyDictionary(getMap()); }
final private void load_empty_dictionary() { push(new PyDictionary()); }
@ExposedMethod(doc = BuiltinDocs.dict_copy_doc) final PyDictionary dict_copy() { return new PyDictionary(getMap()); // no need to clone() }
/** * Initialize the environ dict from System.getenv. environ may be empty when the * security policy doesn't grant us access. */ private static PyObject getEnviron() { PyObject environ = new PyDictionary(); Map<String, String> env; try { env = System.getenv(); } catch (SecurityException se) { return environ; } for (Map.Entry<String, String> entry : env.entrySet()) { environ.__setitem__( Py.newStringOrUnicode(entry.getKey()), Py.newStringOrUnicode(entry.getValue())); } return environ; }
/** * 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; }
@ExposedGet(name = "keywords") public PyObject getKeywords() { if (keywords.length == 0) { return Py.None; } int argc = args.length - keywords.length; PyObject kwDict = new PyDictionary(); for (int i = 0; i < keywords.length; i++) { kwDict.__setitem__(Py.newString(keywords[i]), args[argc + i]); } return kwDict; }
PyObject files = new PyDictionary(); try { readZipFile(zipFile, files);
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; }
/** * Constructor for handling the consumption of data. * * @param connection the database connection * @param dataHandler a custom DataHandler for the cursor, can be None * @param tableName the table to insert the data * @param exclude the columns to be excluded from insertion on the destination, all if None * @param bindings the optional bindings for the destination, this allows morphing of types during the copy * @param batchsize the optional batchsize for the inserts */ public DBSink(PyConnection connection, Class dataHandler, String tableName, PyObject exclude, PyObject bindings, int batchsize) { super(connection, dataHandler, tableName); this.sql = Py.None; this.rows = new PyList(); this.bindings = bindings; this.batchsize = batchsize; this.exclude = new HashSet(); this.indexedBindings = new PyDictionary(); if (exclude != Py.None) { for (int i = 0; i < exclude.__len__(); i++) { PyObject lowered = Py.newString(((PyString) exclude.__getitem__(i)).lower()); this.exclude.add(lowered); } } }
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); }
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); }
public PyObject groupdict(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("groupdict", args, kws, "default"); PyObject def = ap.getPyObject(0, Py.None); PyObject result = new PyDictionary(); if (pattern.groupindex == null) return result; PyObject keys = pattern.groupindex.invoke("keys"); PyObject key; for (int i = 0; (key = keys.__finditem__(i)) != null; i++) { PyObject item = getslice(key, def); result.__setitem__(key, item); } return result; }
PyDictionary sqltype = new PyDictionary();
@KeywordArgs(names = {"remoteServers", "startDate", "endDate"}, types = {List.class, Date.class, Date.class}) public PyDictionary getRemoteLogEntries(PyObject[] pyArgs, String[] keywords) throws JSONException { PyArgumentMap args = PyArgumentMap.interpretPyArgs(pyArgs, keywords, GetLogsScriptFunctions.class, "getRemoteLogEntries"); List<String> remoteServers = (List<String>) args.getArg("remoteServers"); if (remoteServers == null || remoteServers.size() == 0) { throw Py.ValueError("Missing required argument remoteServers"); } Date startDate = args.getDateArg("startDate"); Date endDate = args.getDateArg("endDate"); HashMap<String, List<LogEvent>> logsMap = getLogEntriesInternal(remoteServers, startDate, endDate); PyDictionary dict = new PyDictionary(); for(String key: logsMap.keySet()){ DatasetBuilder dataBuilder = new DatasetBuilder() .colNames("level","name","timestamp","message") .colTypes(String.class,String.class,Date.class,String.class); List<LogEvent> events = logsMap.get(key); // Convert the logging events into dataset rows for(LogEvent event: events){ dataBuilder.addRow(event.getLevel().toString(), event.getLoggerName(), new Date(event.getTimestamp()), event.getMessage().toString()); } dict.put(key, dataBuilder.build()); } return dict; }
public void testBasicTypes() { assertRoundtrip(Py.None); assertRoundtrip(Py.True); assertRoundtrip(Py.False); assertRoundtrip(Py.newInteger(42)); assertRoundtrip(Py.newLong(47)); assertRoundtrip(Py.newString("Jython: Python for the Java Platform")); assertRoundtrip(Py.newUnicode("Drink options include \uD83C\uDF7A, \uD83C\uDF75, \uD83C\uDF77, and \u2615")); Map<PyObject, PyObject> map = new HashMap<>(); map.put(Py.newString("OEIS interesting number"), Py.newInteger(14228)); map.put(Py.newString("Hardy-Ramanujan number"), Py.newInteger(1729)); assertRoundtrip(new PyDictionary(map)); assertRoundtrip(new PyList(new PyObject[]{Py.newInteger(1), Py.newInteger(28), Py.newInteger(546), Py.newInteger(9450), Py.newInteger(157773)})); // A001234 assertRoundtrip(new PySet(new PyObject[]{Py.Zero, Py.One})); assertRoundtrip(new PyFrozenSet(new PyTuple(Py.newInteger(1), Py.newInteger(2), Py.newInteger(3)))); assertRoundtrip(new PyTuple(Py.newInteger(2), Py.newInteger(8), Py.newInteger(248), Py.newInteger(113281))); // A012345 }
try { if (arg3 instanceof PyStringMap) { PyDictionary d = new PyDictionary(); d.update(arg3); arg3 = d;