Package org.python.expose

Examples of org.python.expose.TypeBuilder


public class TypeExposerTest extends InterpTestCase {

    public void testMakeBuilder() throws Exception {
        ExposedTypeProcessor etp = new ExposedTypeProcessor(getClass().getClassLoader()
                .getResourceAsStream("org/python/expose/generate/SimpleExposed.class"));
        TypeBuilder t = etp.getTypeExposer().makeBuilder();
        assertEquals("simpleexposed", t.getName());
        assertEquals(SimpleExposed.class, t.getTypeClass());
        assertEquals(false, t.getIsBaseType());
        assertEquals("Docstring", t.getDoc());
        PyType type = PyType.fromClass(SimpleExposed.class);
        PyObject dict = t.getDict(type);
        assertNotNull(dict.__finditem__("simple_method"));
        assertNotNull(dict.__finditem__("prefixed"));
        assertNotNull(dict.__finditem__("__str__"));
        assertNotNull(dict.__finditem__("__repr__"));
        assertNotNull(dict.__finditem__("tostring"));
View Full Code Here


    }

    public void testGoodNew() throws IOException {
        ExposedTypeProcessor etp = new ExposedTypeProcessor(getClass().getClassLoader()
                .getResourceAsStream("org/python/expose/generate/TypeExposerTest$SimplestNew.class"));
        TypeBuilder te = etp.getTypeExposer().makeBuilder();
        assertEquals(true, te.getIsBaseType());
        PyType simplestType = PyType.fromClass(SimplestNew.class);
        PyNewWrapper new_ = (PyNewWrapper)te.getDict(simplestType).__finditem__("__new__");
        assertEquals(Py.One, new_.new_impl(false, null, null, null));
    }
View Full Code Here

        if (Py.BOOTSTRAP_TYPES.contains(underlying_class)) {
            // init will be called again from addBuilder which also removes underlying_class from
            // BOOTSTRAP_TYPES
            return;
        }
        TypeBuilder builder = classToBuilder.get(underlying_class);
        name = builder.getName();
        dict = builder.getDict(this);
        String doc = builder.getDoc();
        // XXX: Can't create a __doc__ str until the PyBaseString/PyString types are
        // created
        if (dict.__finditem__("__doc__") == null && forClass != PyBaseString.class
            && forClass != PyString.class) {
            PyObject docObj;
            if (doc != null) {
                docObj = new PyString(doc);
            } else {
                // XXX: Hack: Py.None may be null during bootstrapping. Most types
                // encountered then should have docstrings anyway
                docObj = Py.None == null ? new PyString() : Py.None;
            }
            dict.__setitem__("__doc__", docObj);
        }
        setIsBaseType(builder.getIsBaseType());
        needs_userdict = dict.__finditem__("__dict__") != null;
        instantiable = dict.__finditem__("__new__") != null;
        cacheDescrBinds();
    }
View Full Code Here

        } catch (ExceptionInInitializerError e) {
            throw Py.JavaError(e);
        } catch (SecurityException e) {
            exc = e;
        }
        TypeBuilder builder = classToBuilder.get(c);
        if (builder == null && exc != null) {
            Py.writeComment("type",
                    "Unable to initialize " + c.getName() + ", a PyObject subclass, due to a " +
                    "security exception, and no type builder could be found for it. If it's an " +
                    "exposed type, it may not work properly.  Security exception: " +
View Full Code Here

TOP

Related Classes of org.python.expose.TypeBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.