本文整理汇总了C++中PySys_GetObject函数的典型用法代码示例。如果您正苦于以下问题:C++ PySys_GetObject函数的具体用法?C++ PySys_GetObject怎么用?C++ PySys_GetObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PySys_GetObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PySys_GetObject
void Plugins::loadFromPath(const ppl6::CString &Path)
{
#ifdef HAVE_PYTHON
ppl6::CDir Dir;
if (!Dir.Open(Path)) return;
PyObject *sysPath = PySys_GetObject("path");
PyObject *path = PyString_FromString(Path);
int result = PyList_Insert(sysPath, 0, path);
Py_DECREF(path);
Dir.Reset();
const ppl6::CDirEntry *entry;
while ((entry=Dir.GetNextPattern("*.py"))) {
ppl6::CArray matches;
if (entry->Filename.PregMatch("/^(.*?)\\.py$/i",matches)) {
ppl6::CString ModuleName=matches.GetString(1);
printf ("Loading Plugin: %s\n",(const char*)ModuleName);
python_modules.push_back(ModuleName);
PyRun_SimpleString("import "+ModuleName+"\n");
}
}
#endif
}
开发者ID:pfedick,项目名称:winmusik,代码行数:25,代码来源:plugins.cpp
示例2: mywrite
static void mywrite(const char* name, FILE* fp, const char* format, va_list va) noexcept {
PyObject* file;
PyObject* error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
file = PySys_GetObject(name);
if (file == NULL || PyFile_AsFile(file) == fp)
vfprintf(fp, format, va);
else {
char buffer[1001];
const int written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
if (PyFile_WriteString(buffer, file) != 0) {
PyErr_Clear();
fputs(buffer, fp);
}
if (written < 0 || (size_t)written >= sizeof(buffer)) {
const char* truncated = "... truncated";
if (PyFile_WriteString(truncated, file) != 0) {
PyErr_Clear();
fputs(truncated, fp);
}
}
}
PyErr_Restore(error_type, error_value, error_traceback);
}
开发者ID:xujun10110,项目名称:pyston,代码行数:25,代码来源:sys.cpp
示例3: PySys_GetObject
static PyObject *__Pyx_GetStdout(void) {
PyObject *f = PySys_GetObject("stdout");
if (!f) {
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
}
return f;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:7,代码来源:r_print.c
示例4: PyOtherSide_init
PyMODINIT_FUNC
PyOtherSide_init()
{
PyObject *pyotherside = PyModule_Create(&PyOtherSideModule);
// Format constants for the image provider return value format
// see http://qt-project.org/doc/qt-5.1/qtgui/qimage.html#Format-enum
PyModule_AddIntConstant(pyotherside, "format_mono", QImage::Format_Mono);
PyModule_AddIntConstant(pyotherside, "format_mono_lsb", QImage::Format_MonoLSB);
PyModule_AddIntConstant(pyotherside, "format_rgb32", QImage::Format_RGB32);
PyModule_AddIntConstant(pyotherside, "format_argb32", QImage::Format_ARGB32);
PyModule_AddIntConstant(pyotherside, "format_rgb16", QImage::Format_RGB16);
PyModule_AddIntConstant(pyotherside, "format_rgb666", QImage::Format_RGB666);
PyModule_AddIntConstant(pyotherside, "format_rgb555", QImage::Format_RGB555);
PyModule_AddIntConstant(pyotherside, "format_rgb888", QImage::Format_RGB888);
PyModule_AddIntConstant(pyotherside, "format_rgb444", QImage::Format_RGB444);
// Custom constant - pixels are to be interpreted as encoded image file data
PyModule_AddIntConstant(pyotherside, "format_data", -1);
PyObject *meta_path = PySys_GetObject("meta_path");
if (meta_path != NULL)
{
PyList_Append(meta_path, pyotherside);
}
return pyotherside;
}
开发者ID:khertan,项目名称:pyotherside,代码行数:28,代码来源:qpython_priv.cpp
示例5: srd_decoder_searchpath_add
/**
* Add an additional search directory for the protocol decoders.
*
* The specified directory is prepended (not appended!) to Python's sys.path,
* in order to search for sigrok protocol decoders in the specified
* directories first, and in the generic Python module directories (and in
* the current working directory) last. This avoids conflicts if there are
* Python modules which have the same name as a sigrok protocol decoder in
* sys.path or in the current working directory.
*
* @param path Path to the directory containing protocol decoders which shall
* be added to the Python sys.path, or NULL.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*
* @private
*
* @since 0.1.0
*/
SRD_PRIV int srd_decoder_searchpath_add(const char *path)
{
PyObject *py_cur_path, *py_item;
srd_dbg("Adding '%s' to module path.", path);
py_cur_path = PySys_GetObject("path");
if (!py_cur_path)
return SRD_ERR_PYTHON;
py_item = PyUnicode_FromString(path);
if (!py_item) {
srd_exception_catch("Failed to create Unicode object");
return SRD_ERR_PYTHON;
}
if (PyList_Insert(py_cur_path, 0, py_item) < 0) {
srd_exception_catch("Failed to insert path element");
Py_DECREF(py_item);
return SRD_ERR_PYTHON;
}
Py_DECREF(py_item);
searchpaths = g_slist_prepend(searchpaths, g_strdup(path));
return SRD_OK;
}
开发者ID:karlp,项目名称:libsigrokdecode,代码行数:45,代码来源:srd.c
示例6: PySys_GetObject
PyObject *set_stdstream(std::string name, PyObject *pystream) {
PyObject *old_pystream = PySys_GetObject(const_cast<char*>(name.c_str())); // borrowed
Py_XINCREF(pystream);
PySys_SetObject(const_cast<char*>(name.c_str()), pystream);
Py_XDECREF(old_pystream);
return old_pystream;
}
开发者ID:nonsleepr,项目名称:PyR,代码行数:7,代码来源:py_stream.cpp
示例7: Py_Initialize
void
TraCIServer::runEmbedded(std::string pyFile) {
PyObject* pName, *pModule;
Py_Initialize();
Py_InitModule("traciemb", EmbMethods);
if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3, ".py")) {
PyObject* sys_path, *path;
char pathstr[] = "path";
sys_path = PySys_GetObject(pathstr);
if (sys_path == NULL || !PyList_Check(sys_path)) {
throw ProcessError("Could not access python sys.path!");
}
path = PyString_FromString(FileHelpers::getFilePath(pyFile).c_str());
PyList_Insert(sys_path, 0, path);
Py_DECREF(path);
FILE* pFile = fopen(pyFile.c_str(), "r");
if (pFile == NULL) {
throw ProcessError("Failed to load \"" + pyFile + "\"!");
}
PyRun_SimpleFile(pFile, pyFile.c_str());
fclose(pFile);
} else {
pName = PyString_FromString(pyFile.c_str());
/* Error checking of pName left out */
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule == NULL) {
PyErr_Print();
throw ProcessError("Failed to load \"" + pyFile + "\"!");
}
}
Py_Finalize();
}
开发者ID:p1tt1,项目名称:sumo,代码行数:33,代码来源:TraCIServer.cpp
示例8: init_local_module
PyObject*
init_local_module(PyObject *m)
{
PyObject *d, *sd, *v;
PyObject *sys_modules, *module;
PyMethodDef *ml;
#ifdef PY3
PyObject *mod_name = PyUnicode_FromString(MODULE_NAME "." LOCAL_MOD_NAME);
#else
PyObject *mod_name = PyBytes_FromString(MODULE_NAME "." LOCAL_MOD_NAME);
#endif
if(mod_name == NULL){
return NULL;
}
LocalObjectType.tp_new = PyType_GenericNew;
if(PyType_Ready(&LocalObjectType) < 0){
return NULL;
}
sys_modules = PySys_GetObject("modules");
d = PyModule_GetDict(m);
module = PyDict_GetItem(d, mod_name);
if(module == NULL) {
module = PyModule_New(MODULE_NAME "." LOCAL_MOD_NAME);
if(module != NULL) {
PyDict_SetItem(sys_modules, mod_name, module);
PyModule_AddObject(m, LOCAL_MOD_NAME, module);
}
}
sd = PyModule_GetDict(module);
for(ml = LocalMod_methods; ml->ml_name != NULL; ml++){
v = PyCFunction_NewEx(ml, (PyObject *)NULL, mod_name);
if(v == NULL) {
goto fin;
}
if(PyDict_SetItemString(sd, ml->ml_name, v) != 0){
Py_DECREF(v);
return NULL;
}
Py_DECREF(v);
}
fin:
Py_DECREF(mod_name);
Py_INCREF(&LocalObjectType);
PyModule_AddObject(module, "local", (PyObject *)&LocalObjectType);
#ifdef PY3
dict_key = PyUnicode_FromString("_jega_local_dict__");
#else
dict_key = PyBytes_FromString("_jega_local_dict__");
#endif
return module;
}
开发者ID:chenbk85,项目名称:jega,代码行数:59,代码来源:local.c
示例9: python_script_error_jump
void python_script_error_jump(const char *filepath, int *lineno, int *offset)
{
PyObject *exception, *value;
PyTracebackObject *tb;
*lineno = -1;
*offset = 0;
PyErr_Fetch(&exception, &value, (PyObject **)&tb);
if (exception && PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
/* no traceback available when SyntaxError.
* python has no api's to this. reference parse_syntax_error() from pythonrun.c */
PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */
if (value) { /* should always be true */
PyObject *message;
PyObject *filename_py, *text_py;
if (parse_syntax_error(value, &message, &filename_py, lineno, offset, &text_py)) {
const char *filename = _PyUnicode_AsString(filename_py);
/* python adds a '/', prefix, so check for both */
if ((BLI_path_cmp(filename, filepath) == 0) ||
((filename[0] == '\\' || filename[0] == '/') &&
BLI_path_cmp(filename + 1, filepath) == 0)) {
/* good */
}
else {
*lineno = -1;
}
}
else {
*lineno = -1;
}
}
}
else {
PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */
PyErr_Print();
for (tb = (PyTracebackObject *)PySys_GetObject("last_traceback");
tb && (PyObject *)tb != Py_None;
tb = tb->tb_next) {
PyObject *coerce;
const char *tb_filepath = traceback_filepath(tb, &coerce);
const int match = ((BLI_path_cmp(tb_filepath, filepath) == 0) ||
((tb_filepath[0] == '\\' || tb_filepath[0] == '/') &&
BLI_path_cmp(tb_filepath + 1, filepath) == 0));
Py_DECREF(coerce);
if (match) {
*lineno = tb->tb_lineno;
/* used to break here, but better find the inner most line */
}
}
}
}
开发者ID:dfelinto,项目名称:blender,代码行数:59,代码来源:bpy_traceback.c
示例10: python_bridge_guard
python_bridge_guard(){
Py_Initialize();
PyObject* sysPath = PySys_GetObject((char*)"path");
PyObject* curDir = PyString_FromString(".");
PyList_Append(sysPath, curDir);
Py_DECREF(curDir);
}
开发者ID:mmcilroy,项目名称:eva_cpp,代码行数:8,代码来源:test_application3.cpp
示例11: PythonRedirector
PythonRedirector(const char* type, PyObject* obj) : std_out(type), out(obj), old(0)
{
if (out) {
Base::PyGILStateLocker lock;
old = PySys_GetObject(const_cast<char*>(std_out));
PySys_SetObject(const_cast<char*>(std_out), out);
}
}
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:8,代码来源:Macro.cpp
示例12: CPyInstance
CPyInstance() {
Py_Initialize();
// Add current dir to system path
PyObject* sysPath = PySys_GetObject((char*)"path");
PyList_Append(sysPath, PyString_FromString("."));
}
开发者ID:rscircus,项目名称:CallPythonFromFortran,代码行数:8,代码来源:pyclass.hpp
示例13: Py_TUF_configure
/*
* Method to call TUFs configure method. This function takes the JSON interposition filename
* as well as the parent repository directory and the parent ssl certificate directory, and
* configures TUF to interpose on update calls
*/
bool Py_TUF_configure(char* tuf_intrp_json, char* p_repo_dir, char* p_ssl_cert_dir) {
//PyObject* Py_TUF_configure(char* tuf_intrp_json, char* p_repo_dir, char* p_ssl_cert_dir){
// Init the python env
Py_Initialize();
//add the current directory to the places to search for TUF
PyObject *path = PySys_GetObject( (char *)"path" );
PyObject *currentDirectory = PyString_FromString( "." );
PyList_Append( path, currentDirectory );
Py_XDECREF( currentDirectory );
//import TUF module
PyObject *moduleName = PyString_FromString( "tuf.interposition" );
PyObject *tufInterMod = PyImport_Import( moduleName );
if ( tufInterMod == NULL ) {
PyErr_Print();
return false;
}
Py_XDECREF( moduleName );
//get the configure function from tuf.interposition
PyObject *configFunction = PyObject_GetAttrString( tufInterMod, "configure" );
if ( configFunction == NULL ) {
PyErr_Print();
return false;
}
Py_XDECREF( tufInterMod );
//convert arguements into Python types and create tuple for CallObject function
PyObject *args = PyTuple_New( 3 );
PyObject *arg0 = PyString_FromString( tuf_intrp_json );
PyTuple_SetItem(args, 0, arg0);
PyObject *arg1 = PyString_FromString( p_repo_dir );
PyTuple_SetItem(args, 1, arg1);
PyObject *arg2 = PyString_FromString( p_ssl_cert_dir );
PyTuple_SetItem(args, 2, arg2);
//calls the config function from the tuf.interposition module
//returns a dictionary with the configurations
//we are currently storing this globally
configDict = PyObject_CallObject( configFunction, args );
//Py_XDECREF( arg0 );
//Py_XDECREF( arg1 );
//Py_XDECREF( arg2 );
//Py_XDECREF( args );
//Py_XDECREF( configFunction );
if ( configDict == NULL ) {
PyErr_Print();
return false;
}
printf( "TUF configured.\n" );
return true;
//return configDict;
}
开发者ID:PoppySeedPlehzr,项目名称:school,代码行数:63,代码来源:tuf_interface.c
示例14: tok_stdin_decode
static int
tok_stdin_decode(struct tok_state *tok, char **inp)
{
PyObject *enc, *sysstdin, *decoded, *utf8;
const char *encoding;
char *converted;
if (PySys_GetFile((char *)"stdin", NULL) != stdin)
return 0;
sysstdin = PySys_GetObject("stdin");
if (sysstdin == NULL || !PyFile_Check(sysstdin))
return 0;
enc = ((PyFileObject *)sysstdin)->f_encoding;
if (enc == NULL || !PyString_Check(enc))
return 0;
Py_INCREF(enc);
encoding = PyString_AsString(enc);
decoded = PyUnicode_Decode(*inp, strlen(*inp), 0, encoding, NULL);
if (decoded == NULL)
goto error_clear;
utf8 = PyUnicode_AsEncodedString(decoded, "utf-8", NULL);
Py_DECREF(decoded);
if (utf8 == NULL)
goto error_clear;
assert(PyString_Check(utf8));
converted = new_string(PyString_AS_STRING(utf8),
PyString_GET_SIZE(utf8));
Py_DECREF(utf8);
if (converted == NULL)
goto error_nomem;
PyMem_FREE(*inp);
*inp = converted;
if (tok->encoding != NULL)
PyMem_FREE(tok->encoding);
tok->encoding = new_string(encoding, strlen(encoding));
if (tok->encoding == NULL)
goto error_nomem;
Py_DECREF(enc);
return 0;
error_nomem:
Py_DECREF(enc);
tok->done = E_NOMEM;
return -1;
error_clear:
/* Fallback to iso-8859-1: for backward compatibility */
Py_DECREF(enc);
PyErr_Clear();
return 0;
}
开发者ID:CRYPTOlab,项目名称:python-resin,代码行数:57,代码来源:tokenizer.c
示例15: pyloader_add_script_path
/* Add to the list of script load paths */
void pyloader_add_script_path(const char *path)
{
PyObject *ppath = PySys_GetObject("path");
if (ppath)
{
PyList_Append(ppath, PyString_FromString(path));
script_paths = g_slist_append(script_paths, g_strdup(path));
}
}
开发者ID:SteveClement,项目名称:irssi-python,代码行数:10,代码来源:pyloader.c
示例16: PySys_GetFile
extern "C" FILE* PySys_GetFile(char* name, FILE* def) noexcept {
FILE* fp = NULL;
PyObject* v = PySys_GetObject(name);
if (v != NULL && PyFile_Check(v))
fp = PyFile_AsFile(v);
if (fp == NULL)
fp = def;
return fp;
}
开发者ID:Thooms,项目名称:pyston,代码行数:9,代码来源:sys.cpp
示例17: PyModule_Create
/*----------------------------MODULE INIT-------------------------*/
PyObject *Geometry_Init(void)
{
PyObject *submodule;
submodule = PyModule_Create(&M_Geometry_module_def);
PyDict_SetItemString(PySys_GetObject("modules"), M_Geometry_module_def.m_name, submodule);
return (submodule);
}
开发者ID:jinjoh,项目名称:NOOR,代码行数:10,代码来源:Geometry.c
示例18: eom_python_module_load
static gboolean
eom_python_module_load (GTypeModule *gmodule)
{
EomPythonModulePrivate *priv = EOM_PYTHON_MODULE_GET_PRIVATE (gmodule);
PyObject *main_module, *main_locals, *locals, *key, *value;
PyObject *module, *fromlist;
Py_ssize_t pos = 0;
g_return_val_if_fail (Py_IsInitialized (), FALSE);
main_module = PyImport_AddModule ("__main__");
if (main_module == NULL) {
g_warning ("Could not get __main__.");
return FALSE;
}
/* If we have a special path, we register it */
if (priv->path != NULL) {
PyObject *sys_path = PySys_GetObject ("path");
PyObject *path = PyString_FromString (priv->path);
if (PySequence_Contains(sys_path, path) == 0)
PyList_Insert (sys_path, 0, path);
Py_DECREF(path);
}
main_locals = PyModule_GetDict (main_module);
/* We need a fromlist to be able to import modules with
* a '.' in the name. */
fromlist = PyTuple_New(0);
module = PyImport_ImportModuleEx (priv->module, main_locals, main_locals, fromlist);
Py_DECREF(fromlist);
if (!module) {
PyErr_Print ();
return FALSE;
}
locals = PyModule_GetDict (module);
while (PyDict_Next (locals, &pos, &key, &value)) {
if (!PyType_Check(value))
continue;
if (PyObject_IsSubclass (value, (PyObject*) PyEomPlugin_Type)) {
priv->type = eom_python_plugin_get_type (gmodule, value);
return TRUE;
}
}
return FALSE;
}
开发者ID:ZrN-kAyDqY,项目名称:eom,代码行数:57,代码来源:eom-python-module.c
示例19: PyErr_WriteUnraisable
/* Call when an exception has occurred but there is no way for Python
to handle it. Examples: exception in __del__ or during GC. */
void
PyErr_WriteUnraisable(PyObject *obj)
{
PyObject *f, *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
f = PySys_GetObject("stderr");
if (f != NULL) {
PyFile_WriteString("Exception ", f);
if (t) {
PyObject* moduleName;
char* className;
assert(PyExceptionClass_Check(t));
className = PyExceptionClass_Name(t);
if (className != NULL) {
char *dot = strrchr(className, '.');
if (dot != NULL)
className = dot+1;
}
moduleName = PyObject_GetAttrString(t, "__module__");
if (moduleName == NULL)
PyFile_WriteString("<unknown>", f);
else {
char* modstr = PyString_AsString(moduleName);
if (modstr &&
strcmp(modstr, "exceptions") != 0)
{
PyFile_WriteString(modstr, f);
PyFile_WriteString(".", f);
}
}
if (className == NULL)
PyFile_WriteString("<unknown>", f);
else
PyFile_WriteString(className, f);
if (v && v != Py_None) {
PyFile_WriteString(": ", f);
if (PyFile_WriteObject(v, f, 0) < 0) {
PyErr_Clear();
PyFile_WriteString("<exception repr() failed>", f);
}
}
Py_XDECREF(moduleName);
}
PyFile_WriteString(" in ", f);
if (PyFile_WriteObject(obj, f, 0) < 0) {
PyErr_Clear();
PyFile_WriteString("<object repr() failed>", f);
}
PyFile_WriteString(" ignored\n", f);
PyErr_Clear(); /* Just in case */
}
Py_XDECREF(t);
Py_XDECREF(v);
Py_XDECREF(tb);
}
开发者ID:irov,项目名称:Mengine,代码行数:58,代码来源:errors.c
示例20: AddPath
void AddPath(const char * path)
{
PyObject * pName = PyUnicode_FromString(path), *syspath;
// reference to Python search path
syspath = PySys_GetObject("path");
// add path to syspath
if (PyList_Insert(syspath, 0, pName))
printf("Error inserting extra path into sys.path list\n");
// reset sys.path object
if (PySys_SetObject("path", syspath))
printf("Error setting sys.path object\n");
}
开发者ID:kbochenina,项目名称:Snap,代码行数:12,代码来源:GenPy.cpp
注:本文中的PySys_GetObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论