当前位置: 首页>>代码示例>>C++>>正文


C++ PyDict_Keys函数代码示例

本文整理汇总了C++中PyDict_Keys函数的典型用法代码示例。如果您正苦于以下问题:C++ PyDict_Keys函数的具体用法?C++ PyDict_Keys怎么用?C++ PyDict_Keys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PyDict_Keys函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _scrap_get_types

/*
 * Gets the currently available types from the active clipboard.
 */
static PyObject*
_scrap_get_types (PyObject *self, PyObject *args)
{
    int i = 0;
    char **types;
    PyObject *list;
    PyObject *tmp;
    
    PYGAME_SCRAP_INIT_CHECK ();
    if (!pygame_scrap_lost ())
    {
        switch (_currentmode)
        {
        case SCRAP_SELECTION:
            return PyDict_Keys (_selectiondata);
        case SCRAP_CLIPBOARD:
        default:
            return PyDict_Keys (_clipdata);
        }
    }

    list = PyList_New (0);
    types = pygame_scrap_get_types ();
    if (!types)
        return list;
    while (types[i] != NULL)
    {
        tmp = PyString_FromString (types[i]);
        PyList_Append (list, tmp);
        Py_DECREF (tmp);
        i++;
    }
    return list;
}
开发者ID:ab3,项目名称:pygame-mirror,代码行数:37,代码来源:scrap.c

示例2: castToPyObject

configParserStruct::pythonParser::containerForVariables configParserStruct::pythonParser::listOfVariables( void *Object )
{
  containerForVariables Result;
  
  if ( Object == NULL )
    return Result;

  PyObject *Dict = castToPyObject(Object);

  if ( ! PyDict_Check( Dict ) )
    return Result;

  PyObject *KeysList = PyDict_Keys( Dict );
  Py_ssize_t KeysListSize = PyList_Size( KeysList );

  for ( ptrdiff_t Index = 0; Index < static_cast<ptrdiff_t>(KeysListSize); Index++ )
  {
    PyObject *Key = PyList_GetItem( KeysList, Index );
    PyObject *KeyRepr = PyObject_Repr( Key );
    std::string KeyString = dequoteString( PyString_AsString( KeyRepr ), "'" );
    PyObject *Item = PyDict_GetItem( Dict, Key );
    if ( PyDict_Check(Item) )
    {
      containerForVariables ListOfItemsinSubDict = listOfVariables( Item );
      for ( containerForVariables::const_iterator i = ListOfItemsinSubDict.begin(); i != ListOfItemsinSubDict.end(); ++i )
        Result.insert( KeyString + structSeparator() + *i );
    } else {
      Result.insert( KeyString );
    } 
  }

  return Result;
}
开发者ID:EKhilkevitch,项目名称:configParserStruct,代码行数:33,代码来源:pythonparser.cpp

示例3: checkDictKeys

//----------------------------------------------------------------------------
// Return set(dict.keys()).issubset(set([vkeys, ...])
// keys of dict must be string or unicode in Py2 and string in Py3!
// Parameters:
// dict - the Python dictionary object to be checked
// vkeys - a null-terminated list of keys (char *)
//----------------------------------------------------------------------------
int checkDictKeys(PyObject *dict, const char *vkeys, ...)
{
    int i, j, rc;
    PyObject *dkeys = PyDict_Keys(dict);              // = dict.keys()
    if (!dkeys) return 0;                             // no valid dictionary
    j = PySequence_Size(dkeys);                       // len(dict.keys())
    PyObject *validkeys = PyList_New(0);              // make list of valid keys
    va_list ap;                                       // def var arg list
    va_start(ap, vkeys);                              // start of args
    while (vkeys != 0)                                // reached end yet?
        { // build list of valid keys to check against
#if PY_MAJOR_VERSION < 3
        PyList_Append(validkeys, PyBytes_FromString(vkeys));    // Python 2
#else
        PyList_Append(validkeys, PyUnicode_FromString(vkeys));  // python 3
#endif
        vkeys = va_arg(ap, const char *);             // get next char string
        }
    va_end(ap);                                       // end the var args loop
    rc = 1;                                           // prepare for success
    for (i = 0; i < j; i++)
    {   // loop through dictionary keys
        if (!PySequence_Contains(validkeys, PySequence_GetItem(dkeys, i)))
            {
            rc = 0;
            break;
            }
    }
    Py_DECREF(validkeys);
    Py_DECREF(dkeys);
    return rc;
}
开发者ID:bhramoss,项目名称:code,代码行数:39,代码来源:recipe-580799.c

示例4: dump_ret_msg

/**
 * parse the return PyObject and store the result into task_ret_pool
 */
static void
dump_ret_msg(PyObject *pRet)
{
    if ( pRet == NULL) {
        throw std::runtime_error("pycall failed");
    }
    char *ret_err_msg;
    int rsize = PyDict_Size(pRet);
    int taskid;
    download_ret_t dr_ret;                  // down return mesg structure 
    PyObject *pret_keys_list = PyDict_Keys(pRet);
    pthread_mutex_lock(&retmtx);
    for (int i = 0; i < rsize; i++) {
        PyObject *pkey_item = PyList_GetItem(pret_keys_list, i);
        PyObject *pvalue_tuple = PyDict_GetItem(pRet, pkey_item);
        PyObject *pret_flag = PyTuple_GetItem(pvalue_tuple, 0);
        PyObject *perr_msg = PyTuple_GetItem(pvalue_tuple, 1);
        taskid = PyInt_AsLong(pkey_item);
        dr_ret.ret_flag = PyInt_AsLong(pret_flag);
        ret_err_msg = PyString_AsString(perr_msg);
        strncpy(dr_ret.err_msg, ret_err_msg, NAME_LEN);
        task_ret_pool[taskid] = dr_ret;
    }
    pthread_mutex_unlock(&retmtx);
}
开发者ID:colin-zhou,项目名称:reserve,代码行数:28,代码来源:download.cpp

示例5: PyDict_Keys

std::map<std::string, std::string> PythonTools::dtom( PyObject* d )
{
    std::map<std::string, std::string> results;
    if ( d != NULL && PyDict_Check( d ) )
    {
        PyObject* keyList = PyDict_Keys( d );
        PyObject* curKey;
        PyObject* curVal;
        for ( int i = 0; i < PyList_Size( keyList ); i++ )
        {
            curKey = PyList_GetItem( keyList, i );
            curVal = PyDict_GetItem( d, curKey );
            char* valstr = PyString_AsString( curVal );
            if ( valstr == NULL )
                gravUtil::logWarning( "PythonTools::dtom(): "
                        "value not a string\n" );
            char* keystr = PyString_AsString( curKey );
            if ( keystr == NULL )
                gravUtil::logWarning( "PythonTools::dtom(): "
                        "key not a string\n" );
            if ( keystr != NULL && valstr != NULL )
                results[ keystr ] = valstr;
        }
    }
    return results;
}
开发者ID:Adhesion,项目名称:grav,代码行数:26,代码来源:PythonTools.cpp

示例6: resulttuple_dir

/**
 * Extends __dir__ with the extra attributes accessible through
 * resulttuple_getattro()
 */
static PyObject *
resulttuple_dir(PyObject *self)
{
    PyObject *mapping_attr;
    PyObject *items = NULL;
    PyObject *mapping = NULL;
    PyObject *mapping_values = NULL;
    PyObject *result = NULL;

    mapping_attr = PYGLIB_PyUnicode_FromString (tuple_indices_key);
    mapping = PyTuple_Type.tp_getattro (self, mapping_attr);
    Py_DECREF (mapping_attr);
    if (mapping == NULL)
        goto error;
    items = PyObject_Dir ((PyObject*)self->ob_type);
    if (items == NULL)
        goto error;
    mapping_values = PyDict_Keys (mapping);
    if (mapping_values == NULL)
        goto error;
    result = PySequence_InPlaceConcat (items, mapping_values);

error:
    Py_XDECREF (items);
    Py_XDECREF (mapping);
    Py_XDECREF (mapping_values);

    return result;
}
开发者ID:Distrotech,项目名称:pygobject,代码行数:33,代码来源:pygi-resulttuple.c

示例7: dictkeys

int
dictkeys(const int handle)
{
    PyObject *v;
    PyObject *obj = getObjectFromHandle(handle);
    v = PyDict_Keys(obj);
    return newHandle(v);
}
开发者ID:monnerat,项目名称:iseriespython,代码行数:8,代码来源:i5pgm_old.c

示例8: PyErr_NoMemory

static char *build_headers_string(PyObject *dict)
{
    Py_ssize_t i, dict_len, buf_pos, buf_size, req_space, free_space;
    PyObject *keys, *key_ob;
    char *key, *value, *header_s;
    const char *header_format = "%s: %s\r\n";
    buf_size = 512;
    buf_pos = 0;
    if ((header_s = (char *) malloc(buf_size * sizeof(char))) == NULL) {
        PyErr_NoMemory();
        return NULL;
    }
    if (dict == NULL || dict == Py_None) {
        sprintf(header_s, "%s", "");
        return header_s;
    }
    if (!PyDict_Check(dict)) {
        PyErr_SetString(PyExc_TypeError, "Headers must be a dict");
        return NULL;
    }

    memset(header_s, '\0', (size_t) buf_size);
    if ((keys = PyDict_Keys(dict)) == NULL) {
        PyErr_SetString(PyExc_TypeError, "Key must not be null.");
        free(header_s);
        return NULL;
    }
    dict_len = PyList_Size(keys);
    for (i = 0; i < dict_len; ++i) {
        key_ob = PyList_GetItem(keys, i);
        if ((key = PyString_AsString(key_ob)) == NULL) {
            free(header_s);
            return NULL;
        }
        if ((value = PyString_AsString(PyDict_GetItem(dict, key_ob))) == NULL) {
            free(header_s);
            return NULL;
        }

        //Make sure header_s has enough space
        req_space = strlen(key) + strlen(value) + strlen(header_format);
        free_space = buf_size - buf_pos;
        while ((req_space + 1) > free_space) {  // +1 to be sure final '\0' fits
            if ((header_s = (char *) realloc(header_s, buf_size * 2)) == NULL) {
                PyErr_NoMemory();
                free(header_s);
                return NULL;
            }
            buf_size *= 2;
            free_space = buf_size - buf_pos;
        }
        sprintf(header_s + buf_pos, header_format, key, value);
        buf_pos += req_space;
    }
    header_s[buf_pos + 1] = '\0';
    return header_s;
}
开发者ID:mjwolf,项目名称:httplib,代码行数:57,代码来源:archonhttpmodule.c

示例9: print_dict

static void print_dict(PyObject *dict) {
	PyObject *keys = PyDict_Keys(dict);
	for (Py_ssize_t i = 0; i < PyList_Size(keys); ++i) {
		PyObject *key = PyList_GetItem(keys, i);
		debug("\t%s", PyUnicode_AsUTF8(key));
		Py_DECREF(key);
	}
	Py_DECREF(keys);
}
开发者ID:mtu-most,项目名称:franklin,代码行数:9,代码来源:module.cpp

示例10: py2c

 static std::map<K,V> py2c(PyObject * ob) {
   pyref keys = PyDict_Keys(ob);
   pyref values = PyDict_Values(ob);
   std::map<K,V> res;
   int len = PyDict_Size(ob);
   for (int i = 0; i < len; i++)
     res.emplace(py_converter<K>::py2c(PyList_GET_ITEM((PyObject*)keys, i)),  //borrowed ref
                 py_converter<V>::py2c(PyList_GET_ITEM((PyObject*)values, i))); //borrowed ref
   return res;
 }
开发者ID:JaksaVucicevic,项目名称:triqs,代码行数:10,代码来源:map.hpp

示例11: printDict

void printDict(PyObject* obj) {  
	if (!PyDict_Check(obj))  
		return;  
	PyObject *k, *keys;  
	keys = PyDict_Keys(obj);  
	for (int i = 0; i < PyList_GET_SIZE(keys); i++) {  
		k = PyList_GET_ITEM(keys, i);  
		char* c_name = PyString_AsString(k);  
		printf("%s\n", c_name);  
	}  
}  
开发者ID:hpzhong,项目名称:tyd,代码行数:11,代码来源:cpp.cpp

示例12: printDict

void printDict(PyObject* obj) {
	if (!PyDict_Check(obj))
		return;
	PyObject *k, *keys;
	keys = PyDict_Keys(obj);// get keys of the dictionary,list output
	for (int i = 0; i < PyList_GET_SIZE(keys); i++) {
		k = PyList_GET_ITEM(keys, i);
		char* c_name = PyString_AsString(k);
		printf("%s/n", c_name);
	}
}
开发者ID:chenxianpao,项目名称:Template,代码行数:11,代码来源:main.cpp

示例13: list

list dict_base::keys() const
{
    if (check_exact(this))
    {
        return list(detail::new_reference(
                        PyDict_Keys(this->ptr())));
    }
    else
    {
        return assume_list(this->attr("keys")());
    }
}
开发者ID:NeoAnomaly,项目名称:xray,代码行数:12,代码来源:dict.cpp

示例14: py_set_colormap

static PyObject* py_set_colormap(PyObject *self, PyObject *args,
                                 PyObject *kwargs) {

  const char *kwnames[] = {"name", "pairs", NULL};
  PyObject *newdict, *keys, *vals;
  PyObject *result = NULL;
  VMDApp *app;
  char *name;

  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!:color.set_colormap",
                                   (char**) kwnames, &name, &PyDict_Type,
                                   &newdict))
    return NULL;

  if (!(app = get_vmdapp()))
    return NULL;

  keys = PyDict_Keys(newdict);
  vals = PyDict_Values(newdict);

  for (int i=0; i<PyList_Size(keys); i++) {
    char *keyname = as_charptr(PyList_GetItem(keys, i));
    char *valname = as_charptr(PyList_GetItem(vals, i));

    if (!keyname || !valname || PyErr_Occurred()) {
      PyErr_SetString(PyExc_ValueError, "set_colormap dictionary invalid");
      goto cleanup;
    }

    if (!app->color_change_name(name, keyname, valname)) {
      PyErr_SetString(PyExc_ValueError,
                      "Invalid color category or item specified");
      goto cleanup;
    }
  }
  result = Py_None;

  // Getting the keys and values from the dictionary makes a new reference.
  // We tell Python we're done with it so as to not leak memory.
  // This needs to happen even if there was a problem setting color, which is
  // why we don't return NULL from the error checking statements above.
cleanup:
  Py_DECREF(keys);
  Py_DECREF(vals);

  Py_XINCREF(result);
  return result;
}
开发者ID:Eigenstate,项目名称:vmd-python,代码行数:48,代码来源:py_color.C

示例15: ops

//=============================================================================
// METHOD: SPELLconfigDict::reset()
//=============================================================================
void SPELLconfigDict::reset( PyObject* dict )
{
	m_values.clear();
	if (dict)
	{
		SPELLsafePythonOperations ops ("SPELLconfigDict::reset()");
		SPELLpyHandle keys = PyDict_Keys(dict);
		unsigned int numKeys = PyList_Size(keys.get());
		for( unsigned int idx = 0; idx < numKeys; idx++ )
		{
			PyObject* key = PyList_GetItem( keys.get(), idx );
			PyObject* value = PyDict_GetItem( dict, key );
			m_values.insert( std::make_pair( PYSSTR(key), SPELLpyValue(value) ));
		}
	}
}
开发者ID:Spacecraft-Code,项目名称:SPELL,代码行数:19,代码来源:SPELLconfigDict.C


注:本文中的PyDict_Keys函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。