• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyObject_CallObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: igraphmodule_i_filehandle_init_cpython_2

static int igraphmodule_i_filehandle_init_cpython_2(igraphmodule_filehandle_t* handle,
        PyObject* object, char* mode) {
    FILE* fp;
    PyObject* fileno_method;
    PyObject* fileno_result;
    int fileno = -1;

    if (object == 0) {
        PyErr_SetString(PyExc_TypeError, "trying to convert a null object "
                "to a file handle");
        return 1;
    }

    handle->object = 0;
    handle->need_close = 0;

    if (PyBaseString_Check(object)) {
        /* We have received a string; we need to open the file denoted by this
         * string now and mark that we opened the file ourselves (so we need
         * to close it when igraphmodule_filehandle_destroy is invoked). */
        handle->object = PyFile_FromString(PyString_AsString(object), mode);
        if (handle->object == 0) {
            /* Could not open the file; just return an error code because an
             * exception was raised already */
            return 1;
        }
        /* Remember that we need to close the file ourselves */
        handle->need_close = 1;
        /* Get a FILE* object from the file */
        fp = PyFile_AsFile(handle->object);
    } else if (PyFile_Check(object)) {
        /* This is a file-like object; store a reference for it and
         * we will handle it later */
        handle->object = object;
        Py_INCREF(handle->object);
        /* Get a FILE* object from the file */
        fp = PyFile_AsFile(handle->object);
    } else {
        /* Check whether the object has a fileno() method. If so, we convert
         * that to a file descriptor and then fdopen() it */
        fileno_method = PyObject_GetAttrString(object, "fileno");
        if (fileno_method != 0) {
            if (PyCallable_Check(fileno_method)) {
                fileno_result = PyObject_CallObject(fileno_method, 0);
                Py_DECREF(fileno_method);
                if (fileno_result != 0) {
                    if (PyInt_Check(fileno_result)) {
                        fileno = (int)PyInt_AsLong(fileno_result);
                        Py_DECREF(fileno_result);
                    } else {
                        Py_DECREF(fileno_result);
                        PyErr_SetString(PyExc_TypeError,
                                "fileno() method of file-like object should return "
                                "an integer");
                        return 1;
                    }
                } else {
                    /* Exception set already by PyObject_CallObject() */
                    return 1;
                }
            } else {
                Py_DECREF(fileno_method);
                PyErr_SetString(PyExc_TypeError,
                        "fileno() attribute of file-like object must be callable");
                return 1;
            }
        } else {
            PyErr_SetString(PyExc_TypeError, "expected filename or file-like object");
                return 1;
        }

        if (fileno > 0) {
            fp = fdopen(fileno, mode);
        } else {
            PyErr_SetString(PyExc_ValueError, "fileno() method returned invalid "
                    "file descriptor");
            return 1;
        }
    }

    handle->fp = fp;
    if (handle->fp == 0) {
        igraphmodule_filehandle_destroy(handle);
        /* This already called Py_DECREF(handle->object), no need to call it */
        PyErr_SetString(PyExc_RuntimeError, "PyFile_AsFile() failed unexpectedly");
        return 1;
    }

    return 0;
}
开发者ID:Sarmentor,项目名称:python-igraph,代码行数:90,代码来源:filehandle.c


示例2: parse_args


//.........这里部分代码省略.........
			continue;
		}

		if (strcmp("--tls12", argv[i]) == 0) {
			options->ssl_versions = tls_v12;
			continue;
		}
#endif // #if OPENSSL_VERSION_NUMBER >= 0x1000008fL || OPENSSL_VERSION_NUMBER >= 0x1000100fL

		if (strcmp("--no_ssl2", argv[i]) == 0) {
			options->ssl_versions &= ~ssl_v2;
			continue;
		}

		if (strcmp("--no_ssl3", argv[i]) == 0) {
			options->ssl_versions &= ~ssl_v3;
			continue;
		}

		if (strcmp("--no_tls1", argv[i]) == 0) {
			options->ssl_versions &= ~tls_v10;
			continue;
		}

		if (strcmp("--no_tls11", argv[i]) == 0) {
			options->ssl_versions &= ~tls_v11;
			continue;
		}

		if (strcmp("--no_tls12", argv[i]) == 0) {
			options->ssl_versions &= ~tls_v12;
			continue;
		}

		if (strcmp("--bugs", argv[i]) == 0) {
			options->sslbugs = 1;
			continue;
		}

		else if (strncmp("--scan_mode=", argv[i], 12) == 0) {
			if (strcmp("fast", argv[i] + 12) == 0) {
				options->scan_mode = SSLSCAN_SCAN_MODE_FAST;
				continue;
			}

			if (strcmp("full", argv[i] + 12) == 0) {
				options->scan_mode = SSLSCAN_SCAN_MODE_FULL;
				continue;
			}

			// ToDo: print error msg
			print_help(argv[0], options);
			return 0;
		}

		// SSL HTTP Get...
		else if (strcmp("--http", argv[i]) == 0) {
			options->http = 1;
			continue;
		}

		if (strncmp("--output=", argv[i], 9) == 0) {
			if(options->py_output_handler == NULL) {
				printf("No output handler");
				continue;
			}

			PyObject *py_func = PyObject_GetAttrString(options->py_output_handler, "load_from_string");
			PyObject *py_args = PyTuple_New(1);
			PyTuple_SetItem(py_args, 0, PyUnicode_FromString(argv[i] + 9));
			PyObject *py_result = PyObject_CallObject(py_func, py_args);
			if(py_result == NULL) {
				PyErr_Print();
			}
			continue;
		}

		if (strncmp("--", argv[i], 2) == 0) {
			PyObject *py_result;
			PyObject *py_args = PyTuple_New(1);
			PyTuple_SetItem(py_args, 0, PyUnicode_FromString(argv[i] + 2));
			py_call_function(options->py_config, "set_value_from_string", py_args, &py_result);
			if (PyObject_RichCompareBool(py_result, PyBool_FromLong(1), Py_EQ) == 1)
				continue;
		}

		// Host
		if (strncmp("--", argv[i], 2) != 0) {
			// Get host...
			parseHostString(argv[i], options);
			continue;
		}

		printf("Unknown option: '%s'\n", argv[i]);
		print_help(argv[0], options);
		// ToDo: define error codes
		return 1;
	}
	return 0;
}
开发者ID:yampolskiy,项目名称:sslscan,代码行数:101,代码来源:main.c


示例3: terrain_chunk_read

TerrainChunk* terrain_chunk_read(Reader* r, int version) {
    PyObject* block_type_table = NULL;

    TerrainChunk* tc = (TerrainChunk*)PyObject_CallObject((PyObject*)&TerrainChunkType, NULL);
    FAIL_IF(tc == NULL);

    tc->version = version;
    tc->save = calloc(sizeof(TerrainChunkSave), 1);

    READ(tc->save->save_id);
    FAIL_IF(read_register_object(r, tc->save->save_id, (PyObject*)tc) < 0);
    READ(tc->stable_id);


    if (version >= 5) {
        READ(tc->flags);
    }

    uint16_t buf[1 << (3 * CHUNK_BITS)];
    READ(buf);

    block_type_table = read_block_type_table(r);
    FAIL_IF(block_type_table == NULL);
    for (int i = 0; i < 1 << (3 * CHUNK_BITS); ++i) {
        PyObject* key = PyLong_FromLong(buf[i]);
        FAIL_IF(key == NULL);

        PyObject* value = PyDict_GetItem(block_type_table, key);
        if (value == NULL) {
            Py_DECREF(key);
            goto fail;
        }

        Py_INCREF(value);
        if (PyList_SetItem(tc->blocks, i, value) < 0) {
            // XXX: SetItem does steal the reference even on failure, right?
            Py_DECREF(key);
            goto fail;
        }
    }
    Py_DECREF(block_type_table);
    block_type_table = NULL;


    // No script extras for TerrainChunk yet.
    if (version >= 999999) {
        tc->save->extra_raw = extra_read(r, version);
        FAIL_IF(tc->save->extra_raw  == NULL);
    } else {
        Py_INCREF(Py_None);
        tc->save->extra_raw = Py_None;
    }


    uint32_t count;
    READ(count);
    for (uint32_t i = 0; i < count; ++i) {
        Structure* obj = structure_read(r, version);
        FAIL_IF(obj == NULL);
        FAIL_IF(PyList_Append(tc->child_structures, (PyObject*)obj) == -1);
    }

    return tc;

fail:
    SET_EXC();
    Py_XDECREF(tc);
    Py_XDECREF(block_type_table);
    return NULL;
}
开发者ID:OliveBloom,项目名称:everfree-outpost,代码行数:70,代码来源:terrain_chunk.c


示例4: objToJSONFile

PyObject* objToJSONFile(PyObject* self, PyObject *args, PyObject *kwargs)
{
	PyObject *data;
	PyObject *file;
	PyObject *string;
	PyObject *write;
	PyObject *argtuple;

	PRINTMARK();

	if (!PyArg_ParseTuple (args, "OO", &data, &file)) {
		return NULL;
	}

	if (!PyObject_HasAttrString (file, "write"))
	{
		PyErr_Format (PyExc_TypeError, "expected file");
		return NULL;
	}

	write = PyObject_GetAttrString (file, "write");

	if (!PyCallable_Check (write)) {
		Py_XDECREF(write);
		PyErr_Format (PyExc_TypeError, "expected file");
		return NULL;
	}

	argtuple = PyTuple_Pack(1, data);

	string = objToJSON (self, argtuple, kwargs);

	if (string == NULL)
	{
		Py_XDECREF(write);
		Py_XDECREF(argtuple);
		return NULL;
	}

	argtuple = PyTuple_Pack (1, string);
	if (argtuple == NULL)
	{
		Py_XDECREF(write);
		return NULL;
	}
	if (PyObject_CallObject (write, argtuple) == NULL)
	{
		Py_XDECREF(write);
		Py_XDECREF(argtuple);
		return NULL;
	}

	Py_XDECREF(write);
	Py_XDECREF(argtuple);
	Py_XDECREF(string);

	PRINTMARK();

	Py_RETURN_NONE;
	

}
开发者ID:paintcan,项目名称:ultrajson,代码行数:62,代码来源:objToJSON.c


示例5: PyUnicode_AsUTF8


//.........这里部分代码省略.........
		Py_DECREF(transList);
		return NULL;
	}

	jl = AB_Job_List2_new();
	AB_Job_List2_PushBack(jl, job);
	ctx = AB_ImExporterContext_new();
	rv = AB_Banking_ExecuteJobs(self->ab, jl, ctx);

	if (rv)
	{
		PyErr_SetString(ExecutionFailed, "Could not retrieve transactions!");
		Py_DECREF(transList);
		return NULL;
	}

	// With success. No process the result.
	ai = AB_ImExporterContext_GetFirstAccountInfo (ctx);
	while(ai)
	{
		const AB_TRANSACTION *t;
		
		t = AB_ImExporterAccountInfo_GetFirstTransaction(ai);
		while(t) {
			const AB_VALUE *v;
			AB_TRANSACTION_STATUS state;

			v=AB_Transaction_GetValue(t);
			if (v) {
				const GWEN_STRINGLIST *sl;
				const GWEN_TIME *tdtime;
				const char *purpose;
				const char *remoteName;
				aqbanking_Transaction *trans = (aqbanking_Transaction*) PyObject_CallObject((PyObject *) &aqbanking_TransactionType, NULL);

				/* The purpose (memo field) might contain multiple lines.
				 * Therefore AqBanking stores the purpose in a string list
				 * of which the first entry is used in this tutorial */
				sl = AB_Transaction_GetPurpose(t);
				if (sl)
				{
					purpose = GWEN_StringList_FirstString(sl);
					if (purpose == NULL) {
						purpose = "";
					}
				}
				else
				{
					purpose = "";
				}

#ifdef DEBUGSTDERR
				fprintf(stderr, "[%-10d]: [%-10s/%-10s][%-10s/%-10s] %-32s (%.2f %s)\n",
						AB_Transaction_GetUniqueId(t),
						AB_Transaction_GetRemoteIban(t),
						AB_Transaction_GetRemoteBic(t),
						AB_Transaction_GetRemoteAccountNumber(t),
						AB_Transaction_GetRemoteBankCode(t),
						purpose,
						AB_Value_GetValueAsDouble(v),
						AB_Value_GetCurrency(v)
				);
#endif

				tdtime = AB_Transaction_GetDate(t);
				tmpDateTime = PyLong_AsDouble(PyLong_FromSize_t(GWEN_Time_Seconds(tdtime)));
开发者ID:jannh,项目名称:python-aqbanking,代码行数:67,代码来源:aqbanking.cpp


示例6: CString

CString CGenethonDoc::runTest2(PyObject *pModule, CString& function) {

    CString output = CString();
    CString format = CString();
    PyObject *pDict, *pFunc;
    PyObject *pValue, *pArgTuple;
    PyObject *ptype, *pvalue, *ptraceback;

    int i;

    // Set the path to include the current directory in case the module is located there. Found from
    // http://stackoverflow.com/questions/7624529/python-c-api-doesnt-load-module
    // and http://stackoverflow.com/questions/7283964/embedding-python-into-c-importing-modules


    if (pModule != NULL) {
        pFunc = PyObject_GetAttrString(pModule, function);   //Get the function by its name
        // pFunc is a new reference

        if (pFunc && PyCallable_Check(pFunc)) {

            //Set up a tuple that will contain the function arguments. In this case, the
            //function requires two tuples, so we set up a tuple of size 2.
            pArgTuple = PyTuple_New(2);


            PyObject* s1 = PySequence_Tuple(PyUnicode_FromString("ASBSDBASJBB"));
            PyObject* s2 = PySequence_Tuple(PyUnicode_FromString("ASHADKBBJSS"));
            PyObject* s3 = PySequence_Tuple(PyUnicode_FromString("ABSFDHSGJAS"));

            PyObject* a = PyTuple_Pack(3, s1, s2, s3);
            PyTuple_SetItem(pArgTuple, 0, a);

            // color matrix
            PyObject *l = PyList_New(3);
            for (size_t i = 0; i<3; i++) {
                PyObject *li = PyList_New(11);
                for (size_t j = 0; j < 11; j++) {
                    pValue = PyLong_FromLong(0);
                    PyList_SetItem(li, j, pValue);
                }
                PyList_SetItem(l, i, li);
            }
//			PyObject *av = Py_BuildValue("(O)", l);
            PyTuple_SetItem(pArgTuple, 1, l);

            //Call the python function
            pValue = PyObject_CallObject(pFunc, pArgTuple);

            for (size_t i = 0; i<3; i++) {
                PyObject *li = PyList_GetItem(l, i);
                output.Append("[");
                for (size_t j = 0; j < 11; j++) {
                    PyObject *pListV = PyList_GetItem(li, j);
                    long lon = PyLong_AsLong(pListV);
                    format.Format("%ld,", lon);
                    output.Append(format.GetString());
//					Py_DECREF(pListV);
                }
                output.Append("]\n");
//				Py_DECREF(li);
            }
//			Py_DECREF(l);
            //			Py_DECREF(s1);
//			Py_DECREF(s2);
//			Py_DECREF(s3);
//			Py_DECREF(a);

            if (pValue != NULL) {
                PyObject* v = PyObject_GetAttrString(pModule, "richTextOutput");
//				output.Format("Result of call: %ld", PyLong_AsLong(pValue));
                Py_DECREF(pValue);
            }
            //Some error catching
            else {
                Py_DECREF(pFunc);
                Py_DECREF(pModule);
                return handlePyError();
            }
        }
        else {
            if (PyErr_Occurred()) {
                return handlePyError();
            }
        }
        Py_XDECREF(pFunc);
        Py_DECREF(pModule);
    }
    else {
        return handlePyError();
    }
    return output;
}
开发者ID:karlnicholas,项目名称:GeneThon,代码行数:93,代码来源:GenethonDoc.cpp


示例7: itemregion

void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
{
	gRegion itemregion(eRect(offset, m_itemsize));
	eListboxStyle *local_style = 0;
	eRect sel_clip(m_selection_clip);
	bool cursorValid = this->cursorValid();
	gRGB border_color;
	int border_size = 0;

	if (sel_clip.valid())
		sel_clip.moveBy(offset);

		/* get local listbox style, if present */
	if (m_listbox)
	{
		local_style = m_listbox->getLocalStyle();
		border_size = local_style->m_border_size;
		border_color = local_style->m_border_color;
	}

	painter.clip(itemregion);
	clearRegion(painter, style, local_style, ePyObject(), ePyObject(), ePyObject(), ePyObject(), selected, itemregion, sel_clip, offset, cursorValid);

	ePyObject items, buildfunc_ret;

	if (m_list && cursorValid)
	{
			/* a multicontent list can be used in two ways:
				either each item is a list of (TYPE,...)-tuples,
				or there is a template defined, which is a list of (TYPE,...)-tuples,
				and the list is an unformatted tuple. The template then references items from the list.
			*/
		items = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference!

		if (m_buildFunc)
		{
			if (PyCallable_Check(m_buildFunc))  // when we have a buildFunc then call it
			{
				if (PyTuple_Check(items))
					buildfunc_ret = items = PyObject_CallObject(m_buildFunc, items);
				else
					eDebug("[eListboxPythonMultiContent] items is no tuple");
			}
			else
				eDebug("[eListboxPythonMultiContent] buildfunc is not callable");
		}

		if (!items)
		{
			eDebug("[eListboxPythonMultiContent] error getting item %d", m_cursor);
			goto error_out;
		}

		if (!m_template)
		{
			if (!PyList_Check(items))
			{
				eDebug("[eListboxPythonMultiContent] list entry %d is not a list (non-templated)", m_cursor);
				goto error_out;
			}
		} else
		{
			if (!PyTuple_Check(items))
			{
				eDebug("[eListboxPythonMultiContent] list entry %d is not a tuple (templated)", m_cursor);
				goto error_out;
			}
		}

		ePyObject data;

			/* if we have a template, use the template for the actual formatting.
				we will later detect that "data" is present, and refer to that, instead
				of the immediate value. */
		int start = 1;
		if (m_template)
		{
			data = items;
			items = m_template;
			start = 0;
		}

		int size = PyList_Size(items);
		for (int i = start; i < size; ++i)
		{
			ePyObject item = PyList_GET_ITEM(items, i); // borrowed reference!

			if (!item)
			{
				eDebug("[eListboxPythonMultiContent] ?");
				goto error_out;
			}

			if (!PyTuple_Check(item))
			{
				eDebug("[eListboxPythonMultiContent] did not receive a tuple.");
				goto error_out;
			}

			int size = PyTuple_Size(item);
//.........这里部分代码省略.........
开发者ID:Akki01,项目名称:enigma2,代码行数:101,代码来源:elistboxcontent.cpp


示例8: embed_sim_init


//.........这里部分代码省略.........
    }

    if (!PyCallable_Check(simlog_func)) {
        PyErr_Print();
        fprintf(stderr, "_printRecord is not callable");
        goto cleanup;
    }

    set_log_handler(simlog_func);

    Py_DECREF(simlog_func);

    simlog_func = PyObject_GetAttrString(simlog_obj, "_willLog");
    if (simlog_func == NULL) {
        PyErr_Print();
        fprintf(stderr, "Failed to get the _willLog method");
        goto cleanup;
    }

    if (!PyCallable_Check(simlog_func)) {
        PyErr_Print();
        fprintf(stderr, "_willLog is not callable");
        goto cleanup;
    }

    set_log_filter(simlog_func);

    argv_list = PyList_New(0);
    for (i = 0; i < info->argc; i++) {
        arg_value = PyString_FromString(info->argv[i]);
        PyList_Append(argv_list, arg_value);
    }

    arg_dict = PyModule_GetDict(cocotb_module);
    PyDict_SetItemString(arg_dict, "argv", argv_list);

    argc = PyInt_FromLong(info->argc);
    PyDict_SetItemString(arg_dict, "argc", argc);

    if (!PyCallable_Check(simlog_func)) {
        PyErr_Print();
        fprintf(stderr, "_printRecord is not callable");
        goto cleanup;
    }

    LOG_INFO("Running on %s version %s", info->product, info->version);
    LOG_INFO("Python interpreter initialised and cocotb loaded!");

    // Now that logging has been set up ok we initialise the testbench
    if (-1 == PyObject_SetAttrString(cocotb_module, "SIM_NAME", PyString_FromString(info->product))) {
        PyErr_Print();
        fprintf(stderr, "Unable to set SIM_NAME");
        goto cleanup;
    }

    // Hold onto a reference to our _fail_test function
    pEventFn = PyObject_GetAttrString(cocotb_module, "_sim_event");

    if (!PyCallable_Check(pEventFn)) {
        PyErr_Print();
        fprintf(stderr, "cocotb._sim_event is not callable");
        goto cleanup;
    }
    Py_INCREF(pEventFn);

    cocotb_init = PyObject_GetAttrString(cocotb_module, "_initialise_testbench");         // New reference

    if (cocotb_init == NULL || !PyCallable_Check(cocotb_init)) {
        if (PyErr_Occurred())
            PyErr_Print();
        fprintf(stderr, "Cannot find function \"%s\"\n", "_initialise_testbench");
        Py_DECREF(cocotb_init);
        goto cleanup;
    }

    cocotb_args = PyTuple_New(1);
    PyTuple_SetItem(cocotb_args, 0, PyLong_FromLong((long)dut));        // Note: This function “steals” a reference to o.
    cocotb_retval = PyObject_CallObject(cocotb_init, cocotb_args);

    if (cocotb_retval != NULL) {
        LOG_DEBUG("_initialise_testbench successful");
        Py_DECREF(cocotb_retval);
    } else {
        PyErr_Print();
        fprintf(stderr,"Call failed\n");
        gpi_sim_end();
        goto cleanup;
    }

    FEXIT

cleanup:
    if (cocotb_module) {
        Py_DECREF(cocotb_module);
    }
    if (arg_dict) {
        Py_DECREF(arg_dict);
    }
    PyGILState_Release(gstate);
}
开发者ID:FinnG,项目名称:cocotb,代码行数:101,代码来源:gpi_embed.c


示例9: session_connect

PyObject *
session_connect(PyObject *self, PyObject *args)
{
    sp_session_config config;
    PyObject *client;
    sp_session *session;
    sp_error error;
    char *username, *password;
    char *cache_location, *settings_location, *user_agent;

    if (!PyArg_ParseTuple(args, "O", &client))
        return NULL;
    PyEval_InitThreads();

    memset(&config, 0, sizeof(config));
    config.api_version = SPOTIFY_API_VERSION;
    config.userdata = (void *)client;
    config.callbacks = &g_callbacks;

    cache_location = PySpotify_GetConfigString(client, "cache_location");
    if (!cache_location)
        return NULL;
    config.cache_location = cache_location;
#ifdef DEBUG
    fprintf(stderr, "[DEBUG]-session- Cache location is '%s'\n",
            cache_location);
#endif

    settings_location = PySpotify_GetConfigString(client, "settings_location");
    config.settings_location = settings_location;
#ifdef DEBUG
    fprintf(stderr, "[DEBUG]-session- Settings location is '%s'\n",
            settings_location);
#endif

    PyObject *application_key =
        PyObject_GetAttr(client, PyBytes_FromString("application_key"));
    if (!application_key) {
        PyErr_SetString(SpotifyError,
                        "application_key not set");
        return NULL;
    }
    else if (!PyBytes_Check(application_key)) {
        PyErr_SetString(SpotifyError,
                        "application_key must be a byte string");
        return NULL;
    }
    char *s_appkey;
    Py_ssize_t l_appkey;

    PyBytes_AsStringAndSize(application_key, &s_appkey, &l_appkey);
    config.application_key_size = l_appkey;
    config.application_key = PyMem_Malloc(l_appkey);
    memcpy((char *)config.application_key, s_appkey, l_appkey);

    user_agent = PySpotify_GetConfigString(client, "user_agent");
    if (!user_agent)
        return NULL;
    if (strlen(user_agent) > 255) {
        PyErr_SetString(SpotifyError, "user agent must be 255 characters max");
    }
    config.user_agent = user_agent;
#ifdef DEBUG
        fprintf(stderr, "[DEBUG]-session- User agent set to '%s'\n",
                            user_agent);
#endif
    username = PySpotify_GetConfigString(client, "username");
    if (!username)
        return NULL;

    password = PySpotify_GetConfigString(client, "password");
    if (!password)
        return NULL;

    Py_BEGIN_ALLOW_THREADS;
#ifdef DEBUG
    fprintf(stderr, "[DEBUG]-session- creating session...\n");
#endif
    error = sp_session_create(&config, &session);
    Py_END_ALLOW_THREADS;
    if (error != SP_ERROR_OK) {
        PyErr_SetString(SpotifyError, sp_error_message(error));
        return NULL;
    }
    session_constructed = 1;

#ifdef DEBUG
    fprintf(stderr, "[DEBUG]-session- login as %s in progress...\n",
            username);
#endif
    Py_BEGIN_ALLOW_THREADS;
    sp_session_login(session, username, password);
    Py_END_ALLOW_THREADS;
    g_session = session;
    Session *psession =
        (Session *) PyObject_CallObject((PyObject *)&SessionType, NULL);
    psession->_session = session;
    return (PyObject *)psession;
}
开发者ID:JoeConyers,项目名称:SpotifyRemote,代码行数:99,代码来源:session.c


示例10: itemrect


//.........这里部分代码省略.........
		if (selected && local_style && local_style->m_selection)
			painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHATEST);

			/* the first tuple element is a string for the left side.
			   the second one will be called, and the result shall be an tuple.

			   of this tuple,
			   the first one is the type (string).
			   the second one is the value. */
		if (PyTuple_Check(item))
		{
				/* handle left part. get item from tuple, convert to string, display. */
			text = PyTuple_GET_ITEM(item, 0);
			text = PyObject_Str(text); /* creates a new object - old object was borrowed! */
			const char *configitemstring = (text && PyString_Check(text)) ? PyString_AsString(text) : "<not-a-string>";
			Py_XDECREF(text);
			eSize itemsize = eSize(m_itemsize.width()-10, m_itemsize.height());
			ePoint textoffset = ePoint(offset.x()+5, offset.y());

				/* when we have no label, align value to the left. (FIXME:
				   don't we want to specifiy this individually?) */
			int value_alignment_left = !*configitemstring;

				/* now, handle the value. get 2nd part from tuple*/
			if (PyTuple_Size(item) >= 2) // when no 2nd entry is in tuple this is a non selectable entry without config part
				value = PyTuple_GET_ITEM(item, 1);

			if (value)
			{
				ePyObject args = PyTuple_New(1);
				PyTuple_SET_ITEM(args, 0, PyInt_FromLong(selected));

					/* CallObject will call __call__ which should return the value tuple */
				value = PyObject_CallObject(value, args);

				if (PyErr_Occurred())
					PyErr_Print();

				Py_DECREF(args);
					/* the PyInt was stolen. */
			}

				/*  check if this is really a tuple */
			if (value && PyTuple_Check(value))
			{
					/* convert type to string */
				ePyObject type = PyTuple_GET_ITEM(value, 0);
				const char *atype = (type && PyString_Check(type)) ? PyString_AsString(type) : 0;

				if (atype)
				{
					if (!strcmp(atype, "text"))
					{
						ePyObject pvalue = PyTuple_GET_ITEM(value, 1);
						const char *value = (pvalue && PyString_Check(pvalue)) ? PyString_AsString(pvalue) : "<not-a-string>";
						eRect tmp = eRect(textoffset, itemsize);
						eTextPara *para = new eTextPara(tmp);
						para->setFont(fnt2);
						para->renderString(value);
						valueWidth = para->getBoundBox().width();

						painter.setFont(fnt2);
						painter.renderText(eRect(textoffset, itemsize), value, (value_alignment_left ?
							gPainter::RT_HALIGN_LEFT : gPainter::RT_HALIGN_RIGHT) |
							gPainter::RT_VALIGN_CENTER, border_color, border_size);
开发者ID:Akki01,项目名称:enigma2,代码行数:66,代码来源:elistboxcontent.cpp


示例11: init_zope_security_checker

PyMODINIT_FUNC
init_zope_security_checker(void)
{
  PyObject* m;

  CheckerType.tp_new = PyType_GenericNew;
  if (PyType_Ready(&CheckerType) < 0)
    return;

  _defaultChecker = PyObject_CallFunction((PyObject*)&CheckerType, "{}");
  if (_defaultChecker == NULL)
    return;

#define INIT_STRING(S) \
if((str_##S = PyString_InternFromString(#S)) == NULL) return

  INIT_STRING(checkPermission);
  INIT_STRING(__Security_checker__);
  INIT_STRING(interaction);

  if ((_checkers = PyDict_New()) == NULL)
    return;

  NoProxy = PyObject_CallObject((PyObject*)&PyBaseObject_Type, NULL);
  if (NoProxy == NULL)
    return;

  if ((m = PyImport_ImportModule("zope.security._proxy")) == NULL) return;
  if ((Proxy = PyObject_GetAttrString(m, "_Proxy")) == NULL) return;
  Py_DECREF(m);

  if ((m = PyImport_ImportModule("zope.security._definitions")) == NULL) return;
  thread_local = PyObject_GetAttrString(m, "thread_local");
  if (thread_local == NULL) return;
  Py_DECREF(m);

  if ((m = PyImport_ImportModule("zope.security.interfaces")) == NULL) return;
  ForbiddenAttribute = PyObject_GetAttrString(m, "ForbiddenAttribute");
  if (ForbiddenAttribute == NULL) return;
  Unauthorized = PyObject_GetAttrString(m, "Unauthorized");
  if (Unauthorized == NULL) return;
  Py_DECREF(m);

  if ((m = PyImport_ImportModule("zope.security.checker")) == NULL) return;
  CheckerPublic = PyObject_GetAttrString(m, "CheckerPublic");
  if (CheckerPublic == NULL) return;
  Py_DECREF(m);

  if ((_available_by_default = PyList_New(0)) == NULL) return;

  m = Py_InitModule3("_zope_security_checker", module_methods,
                     "C optimizations for zope.security.checker");

  if (m == NULL)
    return;

#define EXPORT(N) Py_INCREF(N); PyModule_AddObject(m, #N, N)

  EXPORT(_checkers);
  EXPORT(NoProxy);
  EXPORT(_defaultChecker);
  EXPORT(_available_by_default);

  Py_INCREF(&CheckerType);
  PyModule_AddObject(m, "Checker", (PyObject *)&CheckerType);
}
开发者ID:kislovm,项目名称:findburo,代码行数:66,代码来源:_zope_security_checker.c


示例12: pyg_signal_class_closure_marshal

static void
pyg_signal_class_closure_marshal(GClosure *closure,
				 GValue *return_value,
				 guint n_param_values,
				 const GValue *param_values,
				 gpointer invocation_hint,
				 gpointer marshal_data)
{
    PyGILState_STATE state;
    GObject *object;
    PyObject *object_wrapper;
    GSignalInvocationHint *hint = (GSignalInvocationHint *)invocation_hint;
    gchar *method_name, *tmp;
    PyObject *method;
    PyObject *params, *ret;
    guint i, len;

    state = pyglib_gil_state_ensure();

    g_return_if_fail(invocation_hint != NULL);
    /* get the object passed as the first argument to the closure */
    object = g_value_get_object(&param_values[0]);
    g_return_if_fail(object != NULL && G_IS_OBJECT(object));

    /* get the wrapper for this object */
    object_wrapper = pygobject_new(object);
    g_return_if_fail(object_wrapper != NULL);

    /* construct method name for this class closure */
    method_name = g_strconcat("do_", g_signal_name(hint->signal_id), NULL);

    /* convert dashes to underscores.  For some reason, g_signal_name
     * seems to convert all the underscores in the signal name to
       dashes??? */
    for (tmp = method_name; *tmp != '\0'; tmp++)
	if (*tmp == '-') *tmp = '_';

    method = PyObject_GetAttrString(object_wrapper, method_name);
    g_free(method_name);

    if (!method) {
	PyErr_Clear();
	Py_DECREF(object_wrapper);
	pyglib_gil_state_release(state);
	return;
    }
    Py_DECREF(object_wrapper);

    /* construct Python tuple for the parameter values; don't copy boxed values
       initially because we'll check after the call to see if a copy is needed. */
    params = PyTuple_New(n_param_values - 1);
    for (i = 1; i < n_param_values; i++) {
	PyObject *item = pyg_value_as_pyobject(&param_values[i], FALSE);

	/* error condition */
	if (!item) {
	    Py_DECREF(params);
	    pyglib_gil_state_release(state);
	    return;
	}
	PyTuple_SetItem(params, i - 1, item);
    }

    ret = PyObject_CallObject(method, params);

    /* Copy boxed values if others ref them, this needs to be done regardless of
       exception status. */
    len = PyTuple_Size(params);
    for (i = 0; i < len; i++) {
	PyObject *item = PyTuple_GetItem(params, i);
	if (item != NULL && PyObject_TypeCheck(item, &PyGBoxed_Type)
	    && item->ob_refcnt != 1) {
	    PyGBoxed* boxed_item = (PyGBoxed*)item;
	    if (!boxed_item->free_on_dealloc) {
		gpointer boxed_ptr = pyg_boxed_get_ptr (boxed_item);
		pyg_boxed_set_ptr (boxed_item, g_boxed_copy (boxed_item->gtype, boxed_ptr));
		boxed_item->free_on_dealloc = TRUE;
	    }
	}
    }

    if (ret == NULL) {
	PyErr_Print();
	Py_DECREF(method);
	Py_DECREF(params);
	pyglib_gil_state_release(state);
	return;
    }
    Py_DECREF(method);
    Py_DECREF(params);
    if (G_IS_VALUE(return_value))
	pyg_value_from_pyobject(return_value, ret);
    Py_DECREF(ret);
    pyglib_gil_state_release(state);
}
开发者ID:RIFTIO,项目名称:pygobject,代码行数:95,代码来源:pygtype.c


示例13: pyg_closure_marshal

static void
pyg_closure_marshal(GClosure *closure,
		    GValue *return_value,
		    guint n_param_values,
		    const GValue *param_values,
		    gpointer invocation_hint,
		    gpointer marshal_data)
{
    PyGILState_STATE state;
    PyGClosure *pc = (PyGClosure *)closure;
    PyObject *params, *ret;
    guint i;

    state = pyglib_gil_state_ensure();

    /* construct Python tuple for the parameter values */
    params = PyTuple_New(n_param_values);
    for (i = 0; i < n_param_values; i++) {
	/* swap in a different initial data for connect_object() */
	if (i == 0 && G_CCLOSURE_SWAP_DATA(closure)) {
	    g_return_if_fail(pc->swap_data != NULL);
	    Py_INCREF(pc->swap_data);
	    PyTuple_SetItem(params, 0, pc->swap_data);
	} else {
	    PyObject *item = pyg_value_as_pyobject(&param_values[i], FALSE);

	    /* error condition */
	    if (!item) {
            if (!PyErr_Occurred ())
                PyErr_SetString (PyExc_TypeError,
                                 "can't convert parameter to desired type");

            if (pc->exception_handler)
                pc->exception_handler (return_value, n_param_values, param_values);
            else
                PyErr_Print();

            goto out;
	    }
	    PyTuple_SetItem(params, i, item);
	}
    }
    /* params passed to function may have extra arguments */
    if (pc->extra_args) {
	PyObject *tuple = params;
	params = PySequence_Concat(tuple, pc->extra_args);
	Py_DECREF(tuple);
    }
    ret = PyObject_CallObject(pc->callback, params);
    if (ret == NULL) {
	if (pc->exception_handler)
	    pc->exception_handler(return_value, n_param_values, param_values);
	else
	    PyErr_Print();
	goto out;
    }

    if (G_IS_VALUE(return_value) && pyg_value_from_pyobject(return_value, ret) != 0) {
	/* If we already have an exception set, use that, otherwise set a
	 * generic one */
	if (!PyErr_Occurred())
	    PyErr_SetString(PyExc_TypeError,
                            "can't convert return value to desired type");

	if (pc->exception_handler)
	    pc->exception_handler(return_value, n_param_values, param_values);
	else
	    PyErr_Print();
    }
    Py_DECREF(ret);

 out:
    Py_DECREF(params);
    pyglib_gil_state_release(state);
}
开发者ID:RIFTIO,项目名称:pygobject,代码行数:75,代码来源:pygtype.c


示例14: pyt_exec_str

static void pyt_exec_str(RESULT * result, const char *module, const char *function, int argc, const char *argv[])
{

    PyObject *pName, *pModule, *pDict, *pFunc;
    PyObject *pArgs, *pValue;
    const char *rv = NULL;
    int i;

    pName = PyString_FromString(module);
    /* Error checking of pName left out */

    pModule = PyImport_Import(pName);
    Py_DECREF(pName);

    if (pModule != NULL) {
        pDict = PyModule_GetDict(pModule);
        /* pDict is a borrowed reference */

        pFunc = PyDict_GetItemString(pDict, function);
        /* pFun: Borrowed reference */

        if (pFunc && PyCallable_Check(pFunc)) {
            pArgs = PyTuple_New(argc);
            for (i = 0; i < argc; ++i) {
                pValue = PyString_FromString(argv[i]);
                if (!pValue) {
                    Py_DECREF(pArgs);
                    Py_DECREF(pModule);
                    error("Cannot convert argument \"%s\" to python format", argv[i]);
                    SetResult(&result, R_STRING, "");
                    return;
                }
                /* pValue reference stolen here: */
                PyTuple_SetItem(pArgs, i, pValue);
            }
            pValue = PyObject_CallObject(pFunc, pArgs);
            Py_DECREF(pArgs);
            if (pValue != NULL) {
                rv = PyString_AsString(pValue);
                SetResult(&result, R_STRING, rv);
                Py_DECREF(pValue);
                /* rv is now a 'dangling reference' */
                return;
            } else {
                Py_DECREF(pModule);
                error("Python call failed (\"%s.%s\")", module, function);
                /* print traceback on stderr */
                PyErr_PrintEx(0);
                SetResult(&result, R_STRING, "");
                return;
            }
            /* pDict and pFunc are borrowed and must not be Py_DECREF-ed */
        } else {
            error("Can not find python function \"%s.%s\"", module, function);
        }
        Py_DECREF(pModule);
    } else {
        error("Failed to load python module \"%s\"", module);
        /* print traceback on stderr */
        PyErr_PrintEx(0);
    }
    SetResult(&result, R_STRING, "");
    return;
}
开发者ID:KP1533TM2,项目名称:lcd4linux,代码行数:64,代码来源:plugin_python.c


示例15: ContentObject_obj_from_ccn

PyObject *
ContentObject_obj_from_ccn(PyObject *py_content_object)
{
    struct ccn_charbuf *content_object;
    struct ccn_parsed_ContentObject *parsed_content_object;
    PyObject *py_obj_ContentObject, *py_o;
    int r;
    struct ccn_charbuf *signature;
    PyObject *py_signature;
    struct ccn_charbuf *signed_info;
    PyObject *py_signed_info;

    if (!CCNObject_ReqType(CONTENT_OBJECT, py_content_object))
        return NULL;

    content_object = CCNObject_Get(CONTENT_OBJECT, py_content_object);
    parsed_content_object = _pyccn_content_object_get_pco(py_content_object);
    if (!parsed_content_object)
        return NULL;

    debug("ContentObject_from_ccn_parsed content_object->length=%zd\n",
          content_object->length);

    py_obj_ContentObject = PyObject_CallObject(g_type_ContentObject, NULL);
    if (!py_obj_ContentObject)
        return NULL;

    /* Name */
    py_o = Name_obj_from_ccn_parsed(py_content_object);
    JUMP_IF_NULL(py_o, error);
    r = PyObject_SetAttrString(py_obj_ContentObject, "name", py_o);
    Py_DECREF(py_o);
    JUMP_IF_NEG(r, error);

    /* Content */
    py_o = Content_from_ccn_parsed(content_object, parsed_content_object);
    JUMP_IF_NULL(py_o, error);
    r = PyObject_SetAttrString(py_obj_ContentObject, "content", py_o);
    Py_DECREF(py_o);
    JUMP_IF_NEG(r, error);

    /* Signature */
    debug("ContentObject_from_ccn_parsed Signature\n");
    py_signature = CCNObject_New_charbuf(SIGNATURE, &signature);
    JUMP_IF_NULL(py_signature, error);
    r = ccn_charbuf_append(signature,
                           &content_object->buf[parsed_content_object->offset[CCN_PCO_B_Signature]],
                           (size_t) (parsed_content_object->offset[CCN_PCO_E_Signature]
                                     - parsed_content_object->offset[CCN_PCO_B_Signature]));
    if (r < 0) {
        PyErr_NoMemory();
        Py_DECREF(py_signature);
        goto error;
    }

    py_o = Signature_obj_from_ccn(py_signature);
    Py_DECREF(py_signature);
    JUMP_IF_NULL(py_o, error);
    r = PyObject_SetAttrString(py_obj_ContentObject, "signature", py_o);
    Py_DECREF(py_o);
    JUMP_IF_NEG(r, error);

    debug("ContentObject_from_ccn_parsed SignedInfo\n");

    py_signed_info = CCNObject_New_charbuf(SIGNED_INFO, &signed_info);
    JUMP_IF_NULL(py_signed_info, error);

    r = ccn_charbuf_append(signed_info,
                           &content_object->buf[parsed_content_object->offset[CCN_PCO_B_SignedInfo]],
                           (size_t) (parsed_content_object->offset[CCN_PCO_E_SignedInfo]
                                     - parsed_content_object->offset[CCN_PCO_B_SignedInfo]));
    if (r < 0) {
        PyErr_NoMemory();
        Py_DECREF(py_signed_info);
        goto error;
    }

    py_o = SignedInfo_obj_from_ccn(py_signed_info);
    Py_DECREF(py_signed_info);
    JUMP_IF_NULL(py_o, error);
    r = PyObject_SetAttrString(py_obj_ContentObject, "signedInfo", py_o);
    Py_DECREF(py_o);
    JUMP_IF_NEG(r, error);

    debug("ContentObject_from_ccn_parsed DigestAlgorithm\n");
    // TODO...  Note this seems to default to nothing in the library...?
    r = PyObject_SetAttrString(py_obj_ContentObject, "digestAlgorithm", Py_None);
    JUMP_IF_NEG(r, error);

    /* Original data  */
    debug("ContentObject_from_ccn_parsed ccn_data\n");
    r = PyObject_SetAttrString(py_obj_ContentObject, "ccn_data", py_content_object);
    JUMP_IF_NEG(r, error);

    r = PyObject_SetAttrString(py_obj_ContentObject, "ccn_data_dirty", Py_False);
    JUMP_IF_NEG(r, error);

    debug("ContentObject_from_ccn_parsed complete\n");

    return py_obj_ContentObject;
//.........这里部分代码省略.........
开发者ID:takeda,项目名称:PyCCN,代码行数:101,代码来源:methods_contentobject.c


示例16: if


//.........这里部分代码省略.........
								painter.setForegroundColor(m_color[eventForegroundSelected]);
							else
								painter.setForegroundColor(gRGB(0xe7b53f));
						}
						break;
					}
					continue;
				}
				case celServiceEventProgressbar:
				{
					if (area.width() > 0 && isPlayable && service_info && !service_info->getEvent(*m_cursor, evt))
					{
						char buffer[15];
						snprintf(buffer, sizeof(buffer), "%d %%", (int)(100 * (now - evt->getBeginTime()) / evt->getDuration()));
						text = buffer;
						flags|=gPainter::RT_HALIGN_RIGHT;
						break;
					}
					continue;
				}
				}

				eRect tmp = area;
				int xoffs = 0;
				ePtr<gPixmap> piconPixmap;

				if (e == celServiceName)
				{
					//picon stuff
					if (isPlayable && PyCallable_Check(m_GetPiconNameFunc))
					{
						ePyObject pArgs = PyTuple_New(1);
						PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(ref.toString().c_str()));
						ePyObject pRet = PyObject_CallObject(m_GetPiconNameFunc, pArgs);
						Py_DECREF(pArgs);
						if (pRet)
						{
							if (PyString_Check(pRet))
							{
								std::string piconFilename = PyString_AS_STRING(pRet);
								if (!piconFilename.empty())
									loadPNG(piconPixmap, piconFilename.c_str());
							}
							Py_DECREF(pRet);
						}
					}
					xoffs = xoffset;
					tmp.setWidth(((!isPlayable || m_column_width == -1 || (!piconPixmap && !m_column_width)) ? tmp.width() : m_column_width) - xoffs);
				}

				eTextPara *para = new eTextPara(tmp);
				para->setFont(m_element_font[e]);
				para->renderString(text.c_str());

				if (e == celServiceName)
				{
					eRect bbox = para->getBoundBox();

					int servicenameWidth = ((!isPlayable || m_column_width == -1 || (!piconPixmap && !m_column_width)) ? bbox.width() : m_column_width);
					m_element_position[celServiceInfo].setLeft(area.left() + servicenameWidth + 8 + xoffs);
					m_element_position[celServiceInfo].setTop(area.top());
					m_element_position[celServiceInfo].setWidth(area. 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyObject_ClearWeakRefs函数代码示例发布时间:2022-05-30
下一篇:
C++ PyObject_CallMethodObjArgs函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap