com.xiaopy.python.MethodCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chaquopy_java Show documentation
Show all versions of chaquopy_java Show documentation
The Python SDK for Android
package com.xiaopy.python;
import java.util.*;
class MethodCache {
private PyObject obj;
private Map cache = new HashMap<>();
public MethodCache(PyObject obj) {
this.obj = obj;
}
public PyObject get(String name) {
PyObject value = cache.get(name);
if (value == null) {
value = obj.get(name);
if (value == null) {
// Same wording as Python AttributeError.
throw new UnsupportedOperationException(
String.format("'%s' object has no attribute '%s'",
obj.type().get("__name__"), name));
}
cache.put(name, value);
}
return value;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy