private static PyType getLazyType() { if (lazyType == null) { lazyType = PyType.fromClass(PyStringMap.class); } return lazyType; }
public PyObject adapt(Object o) { return PyType.fromClass((Class<?>)o, false); }
public static synchronized PyType fromClass(Class<?> c) { return fromClass(c, true); }
public PyNewWrapper(Class c, String name, int minargs, int maxargs) { this(PyType.fromClass(c), name, minargs, maxargs); }
/** * Fills the base and bases of this type with the type of baseClass as sets its mro to this type * followed by the mro of baseClass. */ protected void computeLinearMro(Class<?> baseClass) { base = PyType.fromClass(baseClass, false); mro = new PyType[base.mro.length + 1]; System.arraycopy(base.mro, 0, mro, 1, base.mro.length); mro[0] = this; bases = new PyObject[] {base}; }
/** * The standard constructor for a <code>PyObject</code>. It will set the <code>objtype</code> * field to correspond to the specific subclass of <code>PyObject</code> being instantiated. **/ public PyObject() { objtype = PyType.fromClass(getClass(), false); if (gcMonitorGlobal) gc.monitorObject(this); }
public static void addGetitem() { PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getitem__", 1) { @Override public PyObject __call__(PyObject arg) { CustomizableMapHolder inst = Py.tojava(self, CustomizableMapHolder.class); String key = Py.tojava(arg, String.class); return Py.java2py(inst.held.get(key)); } }; PyType.fromClass(CustomizableMapHolder.class).addMethod(meth); }
public static void addPostdefined() { PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getitem__", 1) { @Override public PyObject __call__(PyObject arg) { return arg; } }; PyType.fromClass(PostdefinedGetitem.class).addMethod(meth); }
public static void addPredefined() { PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getitem__", 1) { @Override public PyObject __call__(PyObject arg) { return arg; } }; PyType.fromClass(FirstPredefinedGetitem.class).addMethod(meth); PyType.fromClass(SecondPredefinedGetitem.class).addMethod(meth); } }
private synchronized static PyType addFromClass(Class<?> c, Set<PyJavaType> needsInners) { if (ExposeAsSuperclass.class.isAssignableFrom(c)) { PyType exposedAs = fromClass(c.getSuperclass(), false); class_to_type.put(c, exposedAs); return exposedAs; } return createType(c, needsInners); }
public static void addSetitem() { PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__setitem__", 2) { @Override public PyObject __call__(PyObject arg1, PyObject arg2) { CustomizableMapHolder inst = Py.tojava(self, CustomizableMapHolder.class); String key = Py.tojava(arg1, String.class); Integer val = Py.tojava(arg2, Integer.class); inst.held.put(key, val); return Py.None; } }; PyType.fromClass(CustomizableMapHolder.class).addMethod(meth); }
public static PyObject wrapJavaObject(Object o) { PyObject obj = new PyObjectDerived(PyType.fromClass(o.getClass(), false)); JyAttribute.setAttr(obj, JyAttribute.JAVA_PROXY_ATTR, o); return obj; }
private Object readResolve() { if (underlying_class != null) { return PyType.fromClass(underlying_class, false); } PyObject mod = imp.importName(module.intern(), false); PyObject pytyp = mod.__getattr__(name.intern()); if (!(pytyp instanceof PyType)) { throw Py.TypeError(module + "." + name + " must be a type for deserialization"); } return pytyp; } }
@Override public Object __tojava__(Class c) { if (c.isInstance(this)) return this; if (instclass.__tojava__ != null) { // try { PyObject ret = instclass.__tojava__.__call__(this, PyType.fromClass(c)); if (ret == Py.None) return Py.NoConversion; if (ret != this) return ret.__tojava__(c); /*} catch (PyException exc) { System.err.println("Error in __tojava__ method"); Py.printException(exc); }*/ } return Py.NoConversion; }
@Override public PyObject __get__(PyObject obj, PyObject type) { if (obj != null) { if (this.type.isAssignableFrom(obj.getClass())) { return bind(obj); } else { throw Py.TypeError(String.format("descriptor '%s' for '%s' objects doesn't apply " + "to '%s' object", info.getName(), PyType.fromClass(this.type), obj.getType())); } } return this; }
public static void clearAdditions() { PyObject dict = PyType.fromClass(CustomizableMapHolder.class).fastGetDict(); for (String name : new String[] {"__getitem__", "__setitem__", "__getattribute__"}) { if (dict.__finditem__(name) != null) { dict.__delitem__(name); } } }
static PyObject createFromClass(String name, Class<?> c) { // Two choices. c implements PyRunnable or c is Java package if (PyRunnable.class.isAssignableFrom(c)) { try { return createFromCode(name, ((PyRunnable)c.newInstance()).getMain()); } catch (InstantiationException e) { throw Py.JavaError(e); } catch (IllegalAccessException e) { throw Py.JavaError(e); } } return PyType.fromClass(c, false); // xxx? }
public static void classDictInit(PyObject dict) { dict.__setitem__("LockType", PyType.fromClass(PyLock.class)); dict.__setitem__("_local", PyLocal.TYPE); dict.__setitem__("interruptAllThreads", null); }
public synchronized static void addBuilder(Class<?> forClass, TypeBuilder builder) { if (classToBuilder == null) { classToBuilder = Generic.map(); } classToBuilder.put(forClass, builder); if (class_to_type.containsKey(forClass)) { if (!BootstrapTypesSingleton.getInstance().remove(forClass)) { Py.writeWarning("init", "Bootstrapping class not in BootstrapTypesSingleton.getInstance()[class=" + forClass + "]"); } // The types in BootstrapTypesSingleton.getInstance() are initialized before their builders are assigned, // so do the work of addFromClass & fillFromClass after the fact fromClass(builder.getTypeClass()).init(builder.getTypeClass(), null); } }