本文整理汇总了C++中PyDict_Contains函数的典型用法代码示例。如果您正苦于以下问题:C++ PyDict_Contains函数的具体用法?C++ PyDict_Contains怎么用?C++ PyDict_Contains使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyDict_Contains函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: c_i18n
//! i18n method, used in scripts
static PyObject *
c_i18n(PyObject *self, PyObject *args)
{
PyObject *py_dict;
PyObject *py_value;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &py_dict)) {
return NULL;
}
PyObject *py_lang = PyString_FromString(sender_language());
if (!PyDict_Contains(py_dict, py_lang)) {
py_lang = PyString_FromString("en");
}
if (PyDict_Contains(py_dict, py_lang)) {
py_value = PyDict_GetItem(py_dict, py_lang);
Py_INCREF(py_value);
return py_value;
}
else {
PyErr_Format(PyExc_COMAR_Script, "'en' locale string should be provided by default in COMAR scripts.");
return NULL;
}
}
开发者ID:Pardus-Linux,项目名称:COMAR,代码行数:26,代码来源:script.c
示例2: PyBobIpGaborSimilarity_init
static int PyBobIpGaborSimilarity_init(PyBobIpGaborSimilarityObject* self, PyObject* args, PyObject* kwargs) {
BOB_TRY
char** kwlist1 = Similarity_doc.kwlist(1);
char** kwlist2 = Similarity_doc.kwlist(0);
// two ways to call
PyObject* k = Py_BuildValue("s", kwlist1[0]);
auto k_ = make_safe(k);
if (
(kwargs && PyDict_Contains(kwargs, k)) ||
(args && PyTuple_Size(args) == 1 && PyBobIoHDF5File_Check(PyTuple_GetItem(args, 0)))
){
PyBobIoHDF5FileObject* hdf5;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist1, &PyBobIoHDF5File_Converter, &hdf5)) return -1;
auto hdf5_ = make_safe(hdf5);
self->cxx.reset(new bob::ip::gabor::Similarity(*hdf5->f));
} else {
const char* name = 0;
PyBobIpGaborTransformObject* gwt = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|O!", kwlist2, &name, &PyBobIpGaborTransform_Type, &gwt)) return -1;
if (gwt)
self->cxx.reset(new bob::ip::gabor::Similarity(bob::ip::gabor::Similarity::name_to_type(name), gwt->cxx));
else
self->cxx.reset(new bob::ip::gabor::Similarity(bob::ip::gabor::Similarity::name_to_type(name)));
}
return 0;
BOB_CATCH_MEMBER("Similarity constructor", -1)
}
开发者ID:183amir,项目名称:bob.ip.gabor,代码行数:29,代码来源:similarity.cpp
示例3:
static PyObject *app_translations_py_messages_register(BlenderAppTranslations *self, PyObject *args, PyObject *kw)
{
#ifdef WITH_INTERNATIONAL
static const char *kwlist[] = {"module_name", "translations_dict", NULL};
PyObject *module_name, *uuid_dict;
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!:bpy.app.translations.register", (char **)kwlist, &PyUnicode_Type,
&module_name, &PyDict_Type, &uuid_dict))
{
return NULL;
}
if (PyDict_Contains(self->py_messages, module_name)) {
PyErr_Format(PyExc_ValueError,
"bpy.app.translations.register: translations message cache already contains some data for "
"addon '%s'", (const char *)_PyUnicode_AsString(module_name));
return NULL;
}
PyDict_SetItem(self->py_messages, module_name, uuid_dict);
/* Clear cached messages dict! */
_clear_translations_cache();
#else
(void)self;
(void)args;
(void)kw;
#endif
/* And we are done! */
Py_RETURN_NONE;
}
开发者ID:diekev,项目名称:blender,代码行数:32,代码来源:bpy_app_translations.c
示例4: loadModule_
PyObject* loadModule_(const QString& name)
{
PyObject* module_dict = PyImport_GetModuleDict();
if(!module_dict)
{
Log.error() << "Could not obtain module dictionary" << std::endl;
return 0;
}
PyObject* mod_name = PyString_FromString(name.toAscii().data());
PyObject* module = 0;
if(PyDict_Contains(module_dict, mod_name))
{
module = PyDict_GetItem(module_dict, mod_name);
}
else
{
//This could leak the imported module. Need to check...
module = PyImport_ImportModule(name.toAscii().data());
}
Py_XDECREF(mod_name);
if(!module || PyErr_Occurred())
{
PyErr_Print();
return 0;
}
return module;
}
开发者ID:HeyJJ,项目名称:ball,代码行数:35,代码来源:pyInterpreter.C
示例5: qd_entity_set_map_key_value_string
qd_error_t qd_entity_set_map_key_value_string(qd_entity_t *entity, const char *attribute, const char *key, const char *value)
{
if (!key)
return QD_ERROR_VALUE;
PyObject *py_key = PyString_FromString(key);
PyObject *py_value = PyString_FromString(value);
PyObject *py_attribute = PyString_FromString(attribute);
qd_error_t ret = QD_ERROR_NONE;
if (PyDict_Contains((PyObject*)entity, py_attribute) == 1) {
PyObject* dict = PyDict_GetItem((PyObject*)entity, py_attribute);
if (PyDict_SetItem(dict, py_key, py_value) < 0)
ret = QD_ERROR_PYTHON;
}
else
ret = QD_ERROR_VALUE;
Py_XDECREF(py_key);
Py_XDECREF(py_value);
Py_XDECREF(py_attribute);
return ret;
}
开发者ID:scholzj,项目名称:qpid-dispatch,代码行数:25,代码来源:entity.c
示例6: proxy_has_key
static PyObject *
proxy_has_key(proxyobject *pp, PyObject *key)
{
int res = PyDict_Contains(pp->dict, key);
if (res < 0)
return NULL;
return PyBool_FromLong(res);
}
开发者ID:develersrl,项目名称:dspython,代码行数:8,代码来源:descrobject.c
示例7: getVariableRef
//=============================================================================
// METHOD: SPELLvariableMonitor::getVariableRef
//=============================================================================
PyObject* SPELLvariableMonitor::getVariableRef( const std::string& name )
{
if (PyDict_Contains(m_frame->f_globals, SSTRPY(name)))
{
return PyDict_GetItemString(m_frame->f_globals, name.c_str());
}
return NULL;
}
开发者ID:seciltabur,项目名称:spell-sat,代码行数:11,代码来源:SPELLvariableMonitor.C
示例8: PyList_New
static PyObject *pair_repr(PyObject *self) {
PyObject *tmp = NULL;
PyObject *col = PyList_New(0);
PyObject *found = PyDict_New();
size_t index = 0;
PyObject *rest = self;
PyObject *rest_id;
PyList_Append(col, _str_cons_paren);
while (rest->ob_type == &SibPairType) {
rest_id = PyLong_FromVoidPtr(rest);
if (PyDict_Contains(found, rest_id)) {
/* recursive pair detected */
PyList_Append(col, _str_recursive_true);
if (rest != self) {
tmp = PyDict_GetItem(found, rest_id);
PyList_Insert(col, PyLong_AsSize_t(tmp) - 1, _str_cons_paren);
PyList_Append(col, _str_close_paren);
}
Py_DECREF(rest_id);
rest = NULL;
break;
} else {
index += 2;
tmp = PyLong_FromSize_t(index);
PyDict_SetItem(found, rest_id, tmp);
Py_DECREF(tmp);
tmp = PyObject_Repr(SibPair_CAR(rest));
PyList_Append(col, tmp);
PyList_Append(col, _str_comma_space);
Py_DECREF(tmp);
rest = SibPair_CDR(rest);
Py_DECREF(rest_id);
}
}
if (rest) {
PyList_Append(col, PyObject_Repr(rest));
}
PyList_Append(col, _str_close_paren);
tmp = PyUnicode_Join(_str_empty, col);
Py_DECREF(col);
Py_DECREF(found);
return tmp;
}
开发者ID:obriencj,项目名称:python-sibilant,代码行数:56,代码来源:pair.c
示例9: get_common_objects
static int get_common_objects(PyObject *cookie,
const void *key,
size_t nkey,
lcb_error_t err,
pycbc_ConnectionObject **conn,
pycbc_ResultBaseObject **res,
int restype,
pycbc_MultiResultObject **mres)
{
PyObject *hkey;
int rv;
assert(Py_TYPE(cookie) == &pycbc_MultiResultType);
*mres = (pycbc_MultiResultObject*)cookie;
*conn = (*mres)->parent;
CB_THR_END(*conn);
rv = pycbc_tc_decode_key(*conn, key, nkey, &hkey);
if (rv < 0) {
push_fatal_error(*mres);
return -1;
}
/**
* Now, get/set the result object
*/
if (restype == RESTYPE_BASE) {
*res = (pycbc_ResultBaseObject*)pycbc_result_new(*conn);
} else if (restype == RESTYPE_OPERATION) {
*res = (pycbc_ResultBaseObject*)pycbc_opresult_new(*conn);
} else if (restype == RESTYPE_VALUE) {
*res = (pycbc_ResultBaseObject*)pycbc_valresult_new(*conn);
} else {
abort();
}
assert(PyDict_Contains((PyObject*)*mres, hkey) == 0);
PyDict_SetItem((PyObject*)*mres, hkey, (PyObject*)*res);
Py_DECREF(*res);
(*res)->key = hkey;
(*res)->rc = err;
if (err != LCB_SUCCESS) {
(*mres)->all_ok = 0;
}
return 0;
}
开发者ID:yamingd,项目名称:couchbase-python-client,代码行数:55,代码来源:callbacks.c
示例10: MapPyValPresent
static s_bool MapPyValPresent(const SMap *self, const char *key, s_erc *error)
{
SMapPy *pMap = (SMapPy*)self;
PyObject *pKey = NULL;
int rv;
S_CLR_ERR(error);
S_CHECK_PY_MAP(pMap, "MapPyValPresent");
pKey = s_set_pyobject_str(key, error);
if (S_CHK_ERR(error, S_CONTERR,
"MapPyValPresent",
"Call to \"s_set_pyobject_str\" failed"))
return FALSE;
rv = PyDict_Contains(S_PY_DICT(pMap), pKey);
if (rv == -1)
{
char *py_error = s_get_python_error_str();
if (py_error)
{
S_CTX_ERR(error, S_FAILURE,
"MapPyValPresent",
"Call to \"PyDict_Contains\" failed. Reported error: %s",
py_error);
S_FREE(py_error);
}
else
{
S_CTX_ERR(error, S_FAILURE,
"MapPyValPresent",
"Call to \"PyDict_Contains\" failed");
}
/* decrement reference of pKey */
Py_XDECREF(pKey);
return FALSE;
}
/* decrement reference of pKey */
Py_XDECREF(pKey);
if (rv == 1)
return TRUE;
return FALSE;
/* for S_CHECK_PY_MAP */
failure:
return FALSE;
}
开发者ID:Cyofanni,项目名称:speect,代码行数:54,代码来源:py_map.c
示例11: dictionaryRemoveUserEntries
/**
* @brief Removes all the entries from the dictionary related to the given user
*
* pythonInit() must have been called before or an error will occur (the module is not loaded)
* @param user Name of the user whose entries will be removed
* @return 1 on success, or 0 otherwise
*/
int dictionaryRemoveUserEntries(const char* user){
PyObject *dictionary;
if((dictionary = getDictionary()) == Py_None){
return 0;
}
if(PyDict_Contains(PyDict_GetItemString(dictionary, "incoming"), PyUnicode_FromString(user))){
PyDict_DelItemString(PyDict_GetItemString(dictionary, "incoming"), user);
}
if(PyDict_Contains(PyDict_GetItemString(dictionary, "outgoing"), PyUnicode_FromString(user))){
PyDict_DelItemString(PyDict_GetItemString(dictionary, "outgoing"), user);
}
setDictionary(dictionary);
Py_XDECREF(dictionary);
return 1;
}
开发者ID:Sbalbp,项目名称:Pidgin_Translator_Plugin,代码行数:27,代码来源:python_interface.c
示例12: DEBUG
//=============================================================================
// METHOD: SPELLvariableMonitor::retrieveLocalVariables()
//=============================================================================
void SPELLvariableMonitor::retrieveLocalVariables(std::vector<SPELLvarInfo>& vars)
{
DEBUG("[VM] Retrieve Locals");
/*
* Bottom stack frame is discarded,
* as globals and locals are the same dictionary
*/
if (m_frame->f_back == NULL) return;
/*
* Get the names defined in the current code, including arguments
*/
std::vector<std::string> varNames = retrieveNames();
/*
* Iterate over the locals dictionary, retrieving the names contained in
* varNames
*/
PyFrame_FastToLocals(m_frame);
PyObject* dict = m_frame->f_locals;
DEBUG("[VM] Frame: " + PYCREPR(m_frame));
for( unsigned int index = 0; index< varNames.size(); index++)
{
std::string varName = varNames[index];
PyObject* pyVarName = SSTRPY(varName);
if (PyDict_Contains( dict, pyVarName ))
{
PyObject* object = PyDict_GetItem( dict, pyVarName );
if (!SPELLpythonHelper::instance().isInstance(object, "Database", "spell.lib.adapter.databases.database"))
{
if (PyCallable_Check(object)) continue;
if (PyClass_Check(object)) continue;
if (PyModule_Check(object)) continue;
if (PyInstance_Check(object)) continue;
}
DEBUG("[VM] Processing " + varName);
std::string type = PYSSTR( PyObject_Type(object) );
DEBUG("[VM] Type : " + type);
std::string value = PYREPR( object );
DEBUG("[VM] Value : " + value);
DEBUG("[VM] Global : " + BSTR(false));
DEBUG("[VM] Registered: " + BSTR(isRegistered(varName)));
// Mark empty values (empty strings) as "<empty>"
if (value == "") value = EMPTY_STRING;
vars.push_back( SPELLvarInfo(varName, type, value, false, isRegistered(varName)) );
}
}
PyFrame_LocalsToFast(m_frame,0);
}
开发者ID:seciltabur,项目名称:spell-sat,代码行数:56,代码来源:SPELLvariableMonitor.C
示例13: PyDict_New
static PyObject *PyKAdminPrincipal_get_keys(PyKAdminPrincipalObject *self, void *closure) {
/*
key structure:
{
kvno: [("enctype", "salt"), ("enctype", "salt")],
kvno: ...
}
*/
PyObject *kvno = NULL;
PyObject *enctype = NULL;
PyObject *salttype = NULL;
PyObject *tuple = NULL;
PyObject *list = NULL;
PyObject *keys = PyDict_New();
ssize_t index = 0;
for (; index < self->entry.n_key_data; index++) {
krb5_key_data *key_data = &self->entry.key_data[index];
kvno = PyUnifiedLongInt_FromLong(key_data->key_data_kvno);
enctype = pykadmin_key_enctype_name(key_data);
salttype = pykadmin_key_salttype_name(key_data);
tuple = PyTuple_Pack(2, enctype, salttype);
if (kvno) {
if (PyDict_Contains(keys, kvno)) {
list = PyDict_GetItem(keys, kvno);
} else {
list = PyList_New(0);
PyDict_SetItem(keys, kvno, list);
}
}
if (list && tuple) {
PyList_Append(list, tuple);
}
}
return keys;
}
开发者ID:Kowh,项目名称:python-kadmin,代码行数:52,代码来源:PyKAdminPrincipalObject.c
示例14: pymongoc_client_pool_tp_new
static PyObject *
pymongoc_client_pool_tp_new (PyTypeObject *self,
PyObject *args,
PyObject *kwargs)
{
pymongoc_client_pool_t *pyclient_pool;
mongoc_uri_t *uri;
const char *uri_str;
PyObject *key = NULL;
PyObject *pyuri = NULL;
PyObject *ret = NULL;
if (kwargs) {
key = PyString_FromStringAndSize("uri", 3);
if (PyDict_Contains(kwargs, key)) {
if (!(pyuri = PyDict_GetItem(kwargs, key))) {
goto cleanup;
} else if (!PyString_Check(pyuri)) {
PyErr_SetString(PyExc_TypeError, "uri must be a string.");
goto cleanup;
}
}
}
uri_str = pyuri ? PyString_AsString(pyuri) : NULL;
uri = mongoc_uri_new (uri_str);
pyclient_pool = (pymongoc_client_pool_t *)
PyType_GenericNew (&pymongoc_client_pool_type, NULL, NULL);
if (!pyclient_pool) {
goto cleanup;
}
pyclient_pool->client_pool = mongoc_client_pool_new (uri);
if (!pyclient_pool->client_pool) {
PyErr_SetString (PyExc_TypeError, "Invalid URI string.");
Py_DECREF (pyclient_pool);
pyclient_pool = NULL;
goto cleanup;
}
ret = (PyObject *)pyclient_pool;
cleanup:
if (uri) {
mongoc_uri_destroy (uri);
}
Py_XDECREF (key);
Py_XDECREF (pyuri);
return ret;
}
开发者ID:glee314,项目名称:mongo-c-driver,代码行数:52,代码来源:pymongoc-client-pool.c
示例15: LRU_contains
static PyObject *
LRU_contains(LRU *self, PyObject *args)
{
PyObject *key;
if (!PyArg_ParseTuple(args, "O", &key))
return NULL;
if (PyDict_Contains(self->dict, key)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
开发者ID:pombredanne,项目名称:lru-dict,代码行数:13,代码来源:lru.c
示例16: c_i18n
//! i18n method, used in scripts
static PyObject *
c_i18n(PyObject *self, PyObject *args)
{
PyObject *py_dict;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &py_dict)) {
return NULL;
}
PyObject *py_lang = PyString_FromString(sender_language());
if (!PyDict_Contains(py_dict, py_lang)) {
py_lang = PyString_FromString("en");
}
if (PyDict_Contains(py_dict, py_lang)) {
return PyDict_GetItem(py_dict, py_lang);
}
else {
PyErr_Format(PyExc_COMAR_Script, "Script is lack of default ('en') locale string.");
return NULL;
}
}
开发者ID:dhirajkhatiwada1,项目名称:uludag,代码行数:23,代码来源:script.c
示例17: __Pyx_Globals
static PyObject* __Pyx_Globals(void) {
Py_ssize_t i;
//PyObject *d;
PyObject *names = NULL;
PyObject *globals = PyObject_GetAttrString($module_cname, "__dict__");
if (!globals) {
PyErr_SetString(PyExc_TypeError,
"current module must have __dict__ attribute");
goto bad;
}
names = PyObject_Dir($module_cname);
if (!names)
goto bad;
for (i = PyList_GET_SIZE(names)-1; i >= 0; i--) {
#if CYTHON_COMPILING_IN_PYPY
PyObject* name = PySequence_GetItem(names, i);
if (!name)
goto bad;
#else
PyObject* name = PyList_GET_ITEM(names, i);
#endif
if (!PyDict_Contains(globals, name)) {
PyObject* value = PyObject_GetAttr($module_cname, name);
if (!value) {
#if CYTHON_COMPILING_IN_PYPY
Py_DECREF(name);
#endif
goto bad;
}
if (PyDict_SetItem(globals, name, value) < 0) {
#if CYTHON_COMPILING_IN_PYPY
Py_DECREF(name);
#endif
Py_DECREF(value);
goto bad;
}
}
#if CYTHON_COMPILING_IN_PYPY
Py_DECREF(name);
#endif
}
Py_DECREF(names);
return globals;
// d = PyDictProxy_New(globals);
// Py_DECREF(globals);
// return d;
bad:
Py_XDECREF(names);
Py_XDECREF(globals);
return NULL;
}
开发者ID:87,项目名称:cython,代码行数:51,代码来源:Builtins.c
示例18: validate_model_member
//! Tells if model.member is defined in model database
int
validate_model_member(const char *model, const char *member, int type)
{
/*!
* Tells if model.member is defined in model database.
*
* @model Model name
* @member Member (method or signal name)
* @type 0 if member is a method, 1 if member is a signal
* @return 0 if valid, -1 if invalid
*
*/
if (PyDict_Contains(PyDict_GetItemString(py_core, "models"), PyString_FromString(model))) {
PyObject *py_dict_model = PyDict_GetItemString(PyDict_GetItemString(py_core, "models"), model);
if (PyDict_Contains(py_dict_model, PyString_FromString(member))) {
PyObject *py_tuple = PyDict_GetItemString(py_dict_model, member);
if (PyInt_AsLong(PyTuple_GetItem(py_tuple, 0)) == (long) type) {
return 0;
}
}
}
return -1;
}
开发者ID:Pardus-Linux,项目名称:COMAR,代码行数:25,代码来源:script.c
示例19: dictionaryHasUser
/**
* @brief Checks whether the dictionary contains language pair information for a given user
*
* pythonInit() must have been called before or an error will occur (the module is not loaded)
* @param user Name of the user to look for
* @param direction Direction to look for the user in ("incoming" or "outgoing")
* @return 1 if there is a language pair for the user, or 0 otherwise
*/
int dictionaryHasUser(const char* user, const char* direction){
int has_user;
PyObject *dictionary;
if((dictionary = getDictionary()) == Py_None){
return 0;
}
has_user = PyDict_Contains(
PyDict_GetItemString(dictionary, direction),
PyUnicode_FromString(user));
Py_XDECREF(dictionary);
return has_user;
}
开发者ID:Sbalbp,项目名称:Pidgin_Translator_Plugin,代码行数:23,代码来源:python_interface.c
示例20: return
inline struct IPData *FindIp(uint32_t ipaddr)
{
unsigned int Counter;
static time_t last_error = 0;
#ifndef HAVE_PYTHON
for (Counter=0; Counter < IpCount; Counter++)
if (IpTable[Counter].ip == ipaddr)
return (&IpTable[Counter]);
#else
PyObject *oIP;
PyObject *oCounter;
oIP=PyInt_FromLong(ipaddr);
Counter=PyDict_Contains(IpTableDict, oIP);
if (Counter==-1){
printf("PyDict_Contains had an error.\n");
abort();
}
if (Counter){
Counter=PyInt_AsLong(PyDict_GetItem(IpTableDict, oIP));
Py_DECREF(oIP);
return &IpTable[Counter];
}
#endif
if (IpCount >= IP_NUM)
{
time_t current_error = time(NULL);
if (current_error > last_error + 30)
{
last_error = current_error;
syslog(LOG_ERR, "Maximum tracked IP's (%d) is too low, some ips will be ignored. Possible network scan?", IP_NUM);
}
return(NULL);
}
#ifndef HAVE_PYTHON
IpTable[IpCount].ip = ipaddr;
return (&IpTable[IpCount++]);
#else
oCounter=PyInt_FromLong(IpCount);
IpTable[IpCount].ip = ipaddr;
PyDict_SetItem(IpTableDict, oIP, oCounter);
Py_DECREF(oCounter);
Py_DECREF(oIP);
return (&IpTable[IpCount++]);
#endif
}
开发者ID:MikeWarriner,项目名称:bandwidthd,代码行数:45,代码来源:bandwidthd.cpp
注:本文中的PyDict_Contains函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论