Пример #1
0
static PyObject *
meth_richcompare(PyObject *self, PyObject *other, int op)
{
    PyCFunctionObject *a, *b;
    PyObject *res;
    int eq;

    if (op != Py_EQ && op != Py_NE) {
        /* Py3K warning if comparison isn't == or !=.  */
        if (PyErr_WarnPy3k("builtin_function_or_method order "
                           "comparisons not supported in 3.x", 1) < 0) {
            return NULL;
        }

        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    else if (!PyCFunction_Check(self) || !PyCFunction_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    a = (PyCFunctionObject *)self;
    b = (PyCFunctionObject *)other;
    eq = a->m_self == b->m_self;
    if (eq)
        eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
    if (op == Py_EQ)
        res = eq ? Py_True : Py_False;
    else
        res = eq ? Py_False : Py_True;
    Py_INCREF(res);
    return res;
}
Пример #2
0
PyObject *
Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
{
    if (name[0] == '_' && name[1] == '_') {
        if (strcmp(name, "__methods__") == 0) {
            if (PyErr_WarnPy3k("__methods__ not supported in 3.x",
                               1) < 0)
                return NULL;
            return listmethodchain(chain);
        }
        if (strcmp(name, "__doc__") == 0) {
            const char *doc = self->ob_type->tp_doc;
            if (doc != NULL)
                return PyString_FromString(doc);
        }
    }
    while (chain != NULL) {
        PyMethodDef *ml = chain->methods;
        for (; ml->ml_name != NULL; ml++) {
            if (name[0] == ml->ml_name[0] &&
                strcmp(name+1, ml->ml_name+1) == 0)
                /* XXX */
                return PyCFunction_New(ml, self);
        }
        chain = chain->link;
    }
    PyErr_SetString(PyExc_AttributeError, name);
    return NULL;
}
Пример #3
0
void
initOSATerminology(void)
{
    if (PyErr_WarnPy3k("In 3.x, the OSATerminology module is removed.", 1) < 0)
        return;
    Py_InitModule("OSATerminology", OSATerminology_methods);
}
Пример #4
0
void
initfm(void)
{
    if (PyErr_WarnPy3k("the fm module has been removed in "
                       "Python 3.0", 2) < 0)
        return;

    Py_InitModule("fm", fm_methods);
    if (m == NULL)
        return;
    fminit();
}
Пример #5
0
PyMODINIT_FUNC
initfl(void)
{
    
    if (PyErr_WarnPy3k("the fl module has been removed in "
                       "Python 3.0", 2) < 0)
        return;
    
	Py_InitModule("fl", forms_methods);
	if (m == NULL)
		return;
	foreground();
	fl_init();
}
Пример #6
0
PyMODINIT_FUNC
initdl(void)
{
	PyObject *m, *d, *x;

    if (PyErr_WarnPy3k("the dl module has been removed in "
                        "Python 3.0; use the ctypes module instead", 2) < 0)
        return;    

	/* Initialize object type */
	Py_TYPE(&Dltype) = &PyType_Type;

	/* Create the module and add the functions */
	m = Py_InitModule("dl", dl_methods);
	if (m == NULL)
		return;

	/* Add some symbolic constants to the module */
	d = PyModule_GetDict(m);
	Dlerror = x = PyErr_NewException("dl.error", NULL, NULL);
	PyDict_SetItemString(d, "error", x);
	x = PyInt_FromLong((long)RTLD_LAZY);
	PyDict_SetItemString(d, "RTLD_LAZY", x);
#define INSINT(X)    insint(d,#X,X)
#ifdef RTLD_NOW
        INSINT(RTLD_NOW);
#endif
#ifdef RTLD_NOLOAD
        INSINT(RTLD_NOLOAD);
#endif
#ifdef RTLD_GLOBAL
        INSINT(RTLD_GLOBAL);
#endif
#ifdef RTLD_LOCAL
        INSINT(RTLD_LOCAL);
#endif
#ifdef RTLD_PARENT
        INSINT(RTLD_PARENT);
#endif
#ifdef RTLD_GROUP
        INSINT(RTLD_GROUP);
#endif
#ifdef RTLD_WORLD
        INSINT(RTLD_WORLD);
#endif
#ifdef RTLD_NODELETE
        INSINT(RTLD_NODELETE);
#endif
}
void
initMacOS(void)
{
    PyObject *m, *d;

    if (PyErr_WarnPy3k("In 3.x, MacOS is removed.", 1))
        return;

    m = Py_InitModule("MacOS", MacOS_Methods);
    d = PyModule_GetDict(m);

    /* Initialize MacOS.Error exception */
    MacOS_Error = PyMac_GetOSErrException();
    if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
        return;
    Rftype.ob_type = &PyType_Type;
    Py_INCREF(&Rftype);
    if (PyDict_SetItemString(d, "ResourceForkType", (PyObject *)&Rftype) != 0)
        return;
    /*
    ** This is a hack: the following constant added to the id() of a string
    ** object gives you the address of the data. Unfortunately, it is needed for
    ** some of the image and sound processing interfaces on the mac:-(
    */
    {
        PyStringObject *p = 0;
        long off = (long)&(p->ob_sval[0]);

        if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0)
            return;
    }
#define PY_RUNTIMEMODEL "macho"
    if (PyDict_SetItemString(d, "runtimemodel",
                            Py_BuildValue("s", PY_RUNTIMEMODEL)) != 0)
        return;
#if defined(WITH_NEXT_FRAMEWORK)
#define PY_LINKMODEL "framework"
#elif defined(Py_ENABLE_SHARED)
#define PY_LINKMODEL "shared"
#else
#define PY_LINKMODEL "static"
#endif
    if (PyDict_SetItemString(d, "linkmodel",
                            Py_BuildValue("s", PY_LINKMODEL)) != 0)
        return;

}
Пример #8
0
static PyObject *
buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
    PyObject *ob;
    Py_ssize_t offset = 0;
    Py_ssize_t size = Py_END_OF_BUFFER;

    if (PyErr_WarnPy3k("buffer() not supported in 3.x", 1) < 0)
        return NULL;

    if (!_PyArg_NoKeywords("buffer()", kw))
        return NULL;

    if (!PyArg_ParseTuple(args, "O|nn:buffer", &ob, &offset, &size))
        return NULL;
    return PyBuffer_FromObject(ob, offset, size);
}
Пример #9
0
static int
cell_compare(PyCellObject *a, PyCellObject *b)
{
	/* Py3K warning for comparisons  */
	if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
					   1) < 0) {
		return -2;
	}

	if (a->ob_ref == NULL) {
		if (b->ob_ref == NULL)
			return 0;
		return -1;
	} else if (b->ob_ref == NULL)
		return 1;
	return PyObject_Compare(a->ob_ref, b->ob_ref);
}
Пример #10
0
static PyObject *
code_richcompare(PyObject *self, PyObject *other, int op)
{
    PyCodeObject *co, *cp;
    int eq;
    PyObject *res;

    if ((op != Py_EQ && op != Py_NE) ||
        !PyCode_Check(self) ||
        !PyCode_Check(other)) {

        /* Py3K warning if types are not equal and comparison
        isn't == or !=  */
        if (PyErr_WarnPy3k("code inequality comparisons not supported "
                           "in 3.x", 1) < 0) {
            return NULL;
        }

        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    co = (PyCodeObject *)self;
    cp = (PyCodeObject *)other;

    eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = co->co_argcount == cp->co_argcount;
    if (!eq) goto unequal;
    eq = co->co_nlocals == cp->co_nlocals;
    if (!eq) goto unequal;
    eq = co->co_flags == cp->co_flags;
    if (!eq) goto unequal;
    eq = co->co_firstlineno == cp->co_firstlineno;
    if (!eq) goto unequal;
    eq = PyObject_RichCompareBool(co->co_code, cp->co_code, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_consts, cp->co_consts, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_names, cp->co_names, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_varnames, cp->co_varnames, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_freevars, cp->co_freevars, Py_EQ);
    if (eq <= 0) goto unequal;
    eq = PyObject_RichCompareBool(co->co_cellvars, cp->co_cellvars, Py_EQ);
    if (eq <= 0) goto unequal;

    if (op == Py_EQ)
        res = Py_True;
    else
        res = Py_False;
    goto done;

  unequal:
    if (eq < 0)
        return NULL;
    if (op == Py_NE)
        res = Py_True;
    else
        res = Py_False;

  done:
    Py_INCREF(res);
    return res;
}
Пример #11
0
static int cobject_deprecation_warning(void)
{
	return PyErr_WarnPy3k("CObject type is not supported in 3.x. "
		"Please use capsule objects instead.", 1);
}