本文整理汇总了C++中PyUnicode_DecodeFSDefault函数的典型用法代码示例。如果您正苦于以下问题:C++ PyUnicode_DecodeFSDefault函数的具体用法?C++ PyUnicode_DecodeFSDefault怎么用?C++ PyUnicode_DecodeFSDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyUnicode_DecodeFSDefault函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFileData
PyObject* getFileData(int argc, char *argv[])
{
PyObject *BioModule = PyImport_ImportModule("Bio");
const char *filename, *filetype, *pycmdToRun;
filename = (const char *)PyUnicode_DecodeFSDefault(argv[1]);
filetype = (const char *)PyUnicode_DecodeFSDefault(argv[2]);
std::string cmdToRun = "import Bio\nBio.SeqIO.parse(";
cmdToRun = cmdToRun + filename + std::string(",") + filetype;
pycmdToRun = cmdToRun.c_str();
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PyObject* filedata;
filedata = PyRun_String(pycmdToRun, 0, NULL, NULL);
Py_DECREF(filename);
Py_DECREF(filetype);
Py_Finalize();
PyMem_RawFree(program);
return filedata;
}
示例2: psutil_proc_name_and_args
/*
* Return process name and args as a Python tuple.
*/
static PyObject *
psutil_proc_name_and_args(PyObject *self, PyObject *args) {
int pid;
char path[1000];
psinfo_t info;
const char *procfs_path;
PyObject *py_name;
PyObject *py_args;
if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
#if PY_MAJOR_VERSION >= 3
py_name = PyUnicode_DecodeFSDefault(info.pr_fname);
if (!py_name)
return NULL;
py_args = PyUnicode_DecodeFSDefault(info.pr_psargs);
if (!py_args)
return NULL;
return Py_BuildValue("OO", py_name, py_args);
#else
return Py_BuildValue("ss", info.pr_fname, info.pr_psargs);
#endif
}
示例3: psutil_proc_name_and_args
/*
* Return process name and args as a Python tuple.
*/
static PyObject *
psutil_proc_name_and_args(PyObject *self, PyObject *args) {
int pid;
char path[1000];
psinfo_t info;
const char *procfs_path;
PyObject *py_name = NULL;
PyObject *py_args = NULL;
PyObject *py_retlist = NULL;
if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
py_name = PyUnicode_DecodeFSDefault(info.pr_fname);
if (!py_name)
goto error;
py_args = PyUnicode_DecodeFSDefault(info.pr_psargs);
if (!py_args)
goto error;
py_retlist = Py_BuildValue("OO", py_name, py_args);
if (!py_retlist)
goto error;
Py_DECREF(py_name);
Py_DECREF(py_args);
return py_retlist;
error:
Py_XDECREF(py_name);
Py_XDECREF(py_args);
Py_XDECREF(py_retlist);
return NULL;
}
示例4: psutil_users
/*
* Return users currently connected on the system.
*/
static PyObject *
psutil_users(PyObject *self, PyObject *args) {
struct utmpx *ut;
PyObject *py_tuple = NULL;
PyObject *py_username = NULL;
PyObject *py_tty = NULL;
PyObject *py_hostname = NULL;
PyObject *py_user_proc = NULL;
PyObject *py_retlist = PyList_New(0);
if (py_retlist == NULL)
return NULL;
setutxent();
while (NULL != (ut = getutxent())) {
if (ut->ut_type == USER_PROCESS)
py_user_proc = Py_True;
else
py_user_proc = Py_False;
py_username = PyUnicode_DecodeFSDefault(ut->ut_user);
if (! py_username)
goto error;
py_tty = PyUnicode_DecodeFSDefault(ut->ut_line);
if (! py_tty)
goto error;
py_hostname = PyUnicode_DecodeFSDefault(ut->ut_host);
if (! py_hostname)
goto error;
py_tuple = Py_BuildValue(
"(OOOfOi)",
py_username, // username
py_tty, // tty
py_hostname, // hostname
(float)ut->ut_tv.tv_sec, // tstamp
py_user_proc, // (bool) user process
ut->ut_pid // process id
);
if (py_tuple == NULL)
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_username);
Py_DECREF(py_tty);
Py_DECREF(py_hostname);
Py_DECREF(py_tuple);
}
endutxent();
return py_retlist;
error:
Py_XDECREF(py_username);
Py_XDECREF(py_tty);
Py_XDECREF(py_hostname);
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
endutxent();
return NULL;
}
示例5: psutil_disk_partitions
/*
* Return disk mounted partitions as a list of tuples including device,
* mount point and filesystem type.
*/
static PyObject *
psutil_disk_partitions(PyObject *self, PyObject *args) {
FILE *file;
struct mnttab mt;
PyObject *py_dev = NULL;
PyObject *py_mountp = NULL;
PyObject *py_tuple = NULL;
PyObject *py_retlist = PyList_New(0);
if (py_retlist == NULL)
return NULL;
file = fopen(MNTTAB, "rb");
if (file == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
goto error;
}
while (getmntent(file, &mt) == 0) {
py_dev = PyUnicode_DecodeFSDefault(mt.mnt_special);
if (! py_dev)
goto error;
py_mountp = PyUnicode_DecodeFSDefault(mt.mnt_mountp);
if (! py_mountp)
goto error;
py_tuple = Py_BuildValue(
"(OOss)",
py_dev, // device
py_mountp, // mount point
mt.mnt_fstype, // fs type
mt.mnt_mntopts); // options
if (py_tuple == NULL)
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_dev);
Py_DECREF(py_mountp);
Py_DECREF(py_tuple);
}
fclose(file);
return py_retlist;
error:
Py_XDECREF(py_dev);
Py_XDECREF(py_mountp);
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
if (file != NULL)
fclose(file);
return NULL;
}
示例6: mkgrent
static PyObject *
mkgrent(struct group *p)
{
int setIndex = 0;
PyObject *v = PyStructSequence_New(&StructGrpType), *w;
char **member;
if (v == NULL)
return NULL;
if ((w = PyList_New(0)) == NULL) {
Py_DECREF(v);
return NULL;
}
for (member = p->gr_mem; *member != NULL; member++) {
PyObject *x = PyUnicode_DecodeFSDefault(*member);
if (x == NULL || PyList_Append(w, x) != 0) {
Py_XDECREF(x);
Py_DECREF(w);
Py_DECREF(v);
return NULL;
}
Py_DECREF(x);
}
#define SET(i,val) PyStructSequence_SET_ITEM(v, i, val)
SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_name));
#ifdef __VMS
SET(setIndex++, Py_None);
Py_INCREF(Py_None);
#else
if (p->gr_passwd)
SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_passwd));
else {
SET(setIndex++, Py_None);
Py_INCREF(Py_None);
}
#endif
SET(setIndex++, PyLong_FromLong((long) p->gr_gid));
SET(setIndex++, w);
#undef SET
if (PyErr_Occurred()) {
Py_DECREF(v);
return NULL;
}
return v;
}
示例7: _py_append_local_extension_path
static void
_py_append_local_extension_path(PyObject *path)
{
assert(path != NULL);
assert(PyList_Check(path));
char localpath[PATH_MAX];
if(path_builder_local_extensions(localpath, PATH_MAX))
{
DEBUGF("python", "Appending local extension directory to Python path: %s", localpath);
PyObject *location = PyUnicode_DecodeFSDefault(localpath);
if(location)
{
PyList_Append(path, location);
}
else
{
fprintf(stderr, "Invalid encoding: %s\n", localpath);
}
}
else
{
WARNING("python", "Couldn't build local extension path.");
}
}
示例8: PyErr_SetString
// FIXME: add string array support
static PyObject *mx2char(const mxArray *pArray)
{
size_t buflen;
char *buf;
PyObject *lRetval;
if (mxGetM(pArray) > 1) {
PyErr_SetString(mlabraw_error, "Only 1 Dimensional strings are currently supported");
return NULL;
}
buflen = mxGetN(pArray) + 1;
//buf = (char *)mxCalloc(buflen, sizeof(char));
//pyassert(buf, "Out of MATLAB(TM) memory");
//if (mxGetString(pArray, buf, buflen)) {
//PyErr_SetString(mlabraw_error, "Unable to extract MATLAB(TM) string");
//mxFree(buf);
//return NULL;
//}
buf = mxArrayToString(pArray);
if (!buf) {
PyErr_SetString(mlabraw_error, "Unable to extract MATLAB(TM) string");
mxFree(buf);
return NULL;
}
#ifdef PY3K
lRetval = PyUnicode_DecodeFSDefault(buf);
#else
lRetval = (PyStringObject *)PyString_FromString(buf);
#endif
mxFree(buf);
return lRetval;
error_return: return NULL;
}
示例9: if
// PyDoc_STRVAR(bpy_user_resource_doc[]= // now in bpy/utils.py
static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
char *type;
char *subdir= NULL;
int folder_id;
static const char *kwlist[]= {"type", "subdir", NULL};
char *path;
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|s:user_resource", (char **)kwlist, &type, &subdir))
return NULL;
/* stupid string compare */
if (!strcmp(type, "DATAFILES")) folder_id= BLENDER_USER_DATAFILES;
else if (!strcmp(type, "CONFIG")) folder_id= BLENDER_USER_CONFIG;
else if (!strcmp(type, "SCRIPTS")) folder_id= BLENDER_USER_SCRIPTS;
else if (!strcmp(type, "AUTOSAVE")) folder_id= BLENDER_USER_AUTOSAVE;
else {
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
return NULL;
}
/* same logic as BLI_get_folder_create(), but best leave it up to the script author to create */
path= BLI_get_folder(folder_id, subdir);
if (!path)
path= BLI_get_user_folder_notest(folder_id, subdir);
return PyUnicode_DecodeFSDefault(path ? path : "");
}
示例10: SplitFilename
PyObject* CGenethonDoc::setPythonPath(CString& fileName) {
CString filePath;
CString appName;
SplitFilename(fileName, &filePath, &appName);
PyObject* sysPath = PySys_GetObject("path");
PyObject* pyPath = PyUnicode_FromString(filePath);
PyList_Append(sysPath, pyPath);
Py_DECREF(pyPath);
pyPath = PyUnicode_FromString("c:/users/karl/Anaconda3");
PyList_Append(sysPath, pyPath);
Py_DECREF(pyPath);
pyPath = PyUnicode_FromString("c:/users/karl/Anaconda3/Lib");
PyList_Append(sysPath, pyPath);
Py_DECREF(pyPath);
pyPath = PyUnicode_FromString("c:/users/karl/Anaconda3/Dlls");
PyList_Append(sysPath, pyPath);
Py_DECREF(pyPath);
pyPath = PyUnicode_FromString("c:/users/karl/Anaconda3/Lib/site-packages");
PyList_Append(sysPath, pyPath);
Py_DECREF(pyPath);
PyObject*pName = PyUnicode_DecodeFSDefault(appName);
PyObject*pModule = PyImport_Import(pName);
Py_DECREF(pName);
return pModule;
}
示例11: pyalpm_package_get_files
static PyObject* pyalpm_package_get_files(AlpmPackage *self, void *closure) {
const alpm_filelist_t *flist = NULL;
PyObject *result = NULL;
CHECK_IF_INITIALIZED();
flist = alpm_pkg_get_files(self->c_data);
if (!flist)
Py_RETURN_NONE;
else {
ssize_t i;
result = PyList_New((Py_ssize_t)flist->count);
for (i = 0; i < (ssize_t)flist->count; i++) {
const alpm_file_t *file = flist->files + i;
PyObject *filename = PyUnicode_DecodeFSDefault(file->name);
PyObject *filesize = PyLong_FromLongLong(file->size);
PyObject *filemode = PyLong_FromUnsignedLong(file->mode);
PyObject *item = PyTuple_New(3);
if (item && filename && filesize && filemode) {
PyTuple_SET_ITEM(item, 0, filename);
PyTuple_SET_ITEM(item, 1, filesize);
PyTuple_SET_ITEM(item, 2, filemode);
PyList_SET_ITEM(result, i, item);
} else {
Py_CLEAR(item);
Py_CLEAR(filename);
Py_CLEAR(filesize);
Py_CLEAR(filemode);
return NULL;
}
}
}
return result;
}
示例12: PyErr_WarnExplicit
int
PyErr_WarnExplicit(PyObject *category, const char *text,
const char *filename_str, int lineno,
const char *module_str, PyObject *registry)
{
PyObject *message = PyUnicode_FromString(text);
PyObject *filename = PyUnicode_DecodeFSDefault(filename_str);
PyObject *module = NULL;
int ret = -1;
if (message == NULL || filename == NULL)
goto exit;
if (module_str != NULL) {
module = PyUnicode_FromString(module_str);
if (module == NULL)
goto exit;
}
ret = PyErr_WarnExplicitObject(category, message, filename, lineno,
module, registry);
exit:
Py_XDECREF(message);
Py_XDECREF(module);
Py_XDECREF(filename);
return ret;
}
示例13: PyRun_FileExFlags
PyObject *
PyRun_FileExFlags(FILE *fp, const char *filename_str, int start, PyObject *globals,
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
PyObject *ret = NULL;
mod_ty mod;
PyArena *arena = NULL;
PyObject *filename;
filename = PyUnicode_DecodeFSDefault(filename_str);
if (filename == NULL)
goto exit;
arena = PyArena_New();
if (arena == NULL)
goto exit;
mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, 0, 0,
flags, NULL, arena);
if (closeit)
fclose(fp);
if (mod == NULL) {
goto exit;
}
ret = run_mod(mod, filename, globals, locals, flags, arena);
exit:
Py_XDECREF(filename);
if (arena != NULL)
PyArena_Free(arena);
return ret;
}
示例14: psutil_get_cmdline
// returns the command line as a python list object
PyObject *
psutil_get_cmdline(long pid) {
static char **argv;
char **p;
PyObject *py_arg = NULL;
PyObject *py_retlist = Py_BuildValue("[]");
if (!py_retlist)
return NULL;
if (pid < 0)
return py_retlist;
if ((argv = _psutil_get_argv(pid)) == NULL)
goto error;
for (p = argv; *p != NULL; p++) {
#if PY_MAJOR_VERSION >= 3
py_arg = PyUnicode_DecodeFSDefault(*p);
#else
py_arg = Py_BuildValue("s", *p);
#endif
if (!py_arg)
goto error;
if (PyList_Append(py_retlist, py_arg))
goto error;
Py_DECREF(py_arg);
}
return py_retlist;
error:
Py_XDECREF(py_arg);
Py_DECREF(py_retlist);
return NULL;
}
示例15: set_main_loader
static int
set_main_loader(PyObject *d, const char *filename, const char *loader_name)
{
PyObject *filename_obj, *bootstrap, *loader_type = NULL, *loader;
int result = 0;
filename_obj = PyUnicode_DecodeFSDefault(filename);
if (filename_obj == NULL)
return -1;
PyInterpreterState *interp = _PyInterpreterState_Get();
bootstrap = PyObject_GetAttrString(interp->importlib,
"_bootstrap_external");
if (bootstrap != NULL) {
loader_type = PyObject_GetAttrString(bootstrap, loader_name);
Py_DECREF(bootstrap);
}
if (loader_type == NULL) {
Py_DECREF(filename_obj);
return -1;
}
loader = PyObject_CallFunction(loader_type, "sN", "__main__", filename_obj);
Py_DECREF(loader_type);
if (loader == NULL) {
return -1;
}
if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
result = -1;
}
Py_DECREF(loader);
return result;
}