コード例 #1
0
ファイル: pycomps_groups.c プロジェクト: dmach/libcomps
PyObject* PyCOMPSGroups_get(PyObject *self, PyObject *key) {
    if (PySlice_Check(key)) {
        return list_get_slice(self, key);
    } else if (PyINT_CHECK(key)) {
        return list_getitem(self, PyINT_ASLONG(key));
    } else if (PyUnicode_Check(key) || PyBytes_Check(key)){
        return list_getitem_byid(self, key);
    } else {
        PyErr_SetString(PyExc_TypeError, "Key must be index interger or slice"
                                         "or string id");
        return NULL;
    }
}
コード例 #2
0
ファイル: pycomps.c プロジェクト: rholy/libcomps
char __pycomps_dict_to_def_opts(PyObject* pobj, void *cobj) {
    PyObject *val;
    COMPS_DefaultsOptions ** options = (COMPS_DefaultsOptions**)cobj;
    int x;
    long tmp;
    const char *keys2[] = {"default_uservisible", "default_biarchonly",
                           "default_default", NULL
                          };
    const char *keys1[] = {"default_pkgtype", NULL};
    *options = malloc(sizeof(COMPS_DefaultsOptions));
    bool *props2[] = {&(*options)->default_uservisible,
                      &(*options)->default_biarchonly,
                      &(*options)->default_default
                     };
    int *props1[] = {&(*options)->default_pkgtype};
    **options = COMPS_DDefaultsOptions;

    if (!PyDict_Check(pobj)) {
        cobj = NULL;
        return 0;
    } else {
        for (x = 0; keys1[x] != NULL; x++) {
            val = PyDict_GetItemString(pobj, keys1[x]);
            if (val) {
                if (PyINT_CHECK(val)) {
                    tmp = PyINT_ASLONG(val);
                }
                tmp = PyLong_AsLong(val);
                if (tmp == COMPS_PACKAGE_DEFAULT ||
                        tmp == COMPS_PACKAGE_OPTIONAL ||
                        tmp == COMPS_PACKAGE_CONDITIONAL ||
                        tmp == COMPS_PACKAGE_MANDATORY) {
                    *props1[x] = tmp;
                }
            }
        }
        for (x = 0; keys2[x] != NULL; x++) {
            val = PyDict_GetItemString(pobj, keys2[x]);
            if (val && PyBool_Check(val)) {
                if (val == Py_True)
                    *props2[x] = true;
                else
                    *props2[x] = false;
            }
        }
    }
    return 1;
}