本文整理汇总了C++中PyFile_AsFile函数的典型用法代码示例。如果您正苦于以下问题:C++ PyFile_AsFile函数的具体用法?C++ PyFile_AsFile怎么用?C++ PyFile_AsFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyFile_AsFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: skimage_write_ps_hex
PyObject *
skimage_write_ps_hex(PyObject * self, PyObject * args)
{
PyObject * pyfile;
ImagingObject * imobj;
int line_length = 80;
char * prefix = NULL;
if (!PyArg_ParseTuple(args, "OO!|is", &imobj, &PyFile_Type, &pyfile,
&line_length, &prefix))
return NULL;
line_length = line_length - 2;
if (line_length < 0)
line_length = 0;
if (imobj->image->pixelsize == 4)
write_ps_hex_rgb(PyFile_AsFile(pyfile), imobj->image->linesize,
imobj->image->ysize, imobj->image->image,
line_length, prefix);
else if (imobj->image->pixelsize == 1)
write_ps_hex_gray(PyFile_AsFile(pyfile), imobj->image->linesize,
imobj->image->ysize, imobj->image->image,
line_length, prefix);
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:Scrik,项目名称:sk1-wx,代码行数:28,代码来源:skimage.c
示例2: svc_writefile
static PyObject *
svc_writefile(captureobject *self, PyObject *args)
{
PyObject *file;
int size;
FILE* fp;
if (!PyArg_Parse(args, "O", &file))
return NULL;
if (!PyFile_Check(file)) {
PyErr_SetString(SvError, "not a file object");
return NULL;
}
if (!(fp = PyFile_AsFile(file)))
return NULL;
size = self->ob_info.width * self->ob_info.height;
if (fwrite(self->ob_capture, sizeof(long), size, fp) != size) {
PyErr_SetString(SvError, "writing failed");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:28,代码来源:svmodule.c
示例3: _update_files
bool _update_files(PyObject* list, FILE** target, uint64_t elements){
PyObject* item;
FILE* current;
uint64_t i = 0;
for (i = 0; i < elements; i++) {
item = PySequence_Fast_GET_ITEM(list, i);
if(Py_None == item){
target[i] = NULL;
}else{
if(PyString_Check(item)){
current = fopen(PyString_AsString(item), i==0 ? "r": "w");
if(current == NULL){
fprintf(stderr, "ERROR WHILE OPENING FILE!\n");
// unable to open file
PyErr_SetFromErrno(PyExc_OSError);
return false;
}
}else{
current = PyFile_AsFile(item);
}
target[i] = current;
}
}
return true;
}
开发者ID:Arhodes-CGRB-OSU,项目名称:pyjip,代码行数:25,代码来源:jip_binding.c
示例4: PyEval_RestoreThread
bool PythonInterpreter::runScript(const char* filename, const char* shortName) {
PyEval_RestoreThread(state);
PyObject* script = PyFile_FromString(const_cast<char*>(filename),
const_cast<char*>("r"));
if (script) {
PyObject* ans = PyRun_File(PyFile_AsFile(script),
const_cast<char*>(shortName),
Py_file_input, mainNamespace, mainNamespace);
Py_DECREF(script);
if (ans) {
Py_DECREF(ans);
state = PyEval_SaveThread();
return true;
} else {
PyErr_Print();
state = PyEval_SaveThread();
return false;
}
} else {
state = PyEval_SaveThread();
return false;
}
}
开发者ID:WPettersson,项目名称:regina,代码行数:25,代码来源:pythoninterpreter.cpp
示例5: hashsplit_read_chunk
static PyObject * hashsplit_read_chunk(PyObject *self, PyObject *args) {
PyObject *source_file = NULL; //gcc complains if these aren't initialized
PyObject *max_chunk_size = NULL;
long MAX_CHUNK_SIZE;
PyObject *result = NULL;
Chunk *chunk;
FILE *source;
if (!PyArg_UnpackTuple(args, "read_chunk", 1, 2, &source_file, &max_chunk_size))
return NULL;
if (!(source = PyFile_AsFile(source_file))) {
PyErr_SetString(PyExc_TypeError, "Expected file or file descriptor");
return NULL;
}
if (!max_chunk_size || max_chunk_size == Py_None) {
MAX_CHUNK_SIZE = DEFAULT_MAX_CHUNK_SIZE;
} else if ((MAX_CHUNK_SIZE = PyInt_AsLong(max_chunk_size))==-1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "max_chunk_size should be an integer");
return NULL;
}
if (MAX_CHUNK_SIZE < MIN_CHUNK_SIZE) {
PyErr_SetString(PyExc_ValueError, "max_chunk_size must be larger than MIN_CHUNK_SIZE");
return NULL;
}
if (!(chunk = chunk_new(MAX_CHUNK_SIZE))) return PyErr_NoMemory();
if (!read_chunk(source, chunk, MAX_CHUNK_SIZE)) {
PyErr_SetString(PyExc_EOFError, "");
} else {
result = PyString_FromStringAndSize((char*)chunk->data, chunk->length);
}
chunk_delete(chunk);
return result;
}
开发者ID:orbnauticus,项目名称:CloneServer,代码行数:33,代码来源:hashsplitmodule.c
示例6: main
int main(int argc, char *argv[]) {
// Set the python interpreter.
setup_python(argc, argv);
std::string filepath(argv[0]);
// Get the path to the helper script.
std::string helper_path;
size_t path_end = filepath.find_last_of('\\');
if (path_end != std::string::npos)
helper_path = filepath.substr(0, path_end + 1);
helper_path += "wbadminhelper.py";
// Configures the execution of the script to take the same
// parameters as this helper tool.
Py_SetProgramName(argv[0]);
PySys_SetArgv(argc, argv);
// Executes the helper script.
PyObject *pFileObject = PyFile_FromString(const_cast<char *>(helper_path.c_str()), "r");
PyRun_SimpleFileEx(PyFile_AsFile(pFileObject), "wbadminhelper.py", 1);
finalize_python();
return 0;
}
开发者ID:pk-codebox-evo,项目名称:mysql-workbench,代码行数:29,代码来源:admin_helper.cpp
示例7: cdb_py_print_records
static PyObject* cdb_py_print_records(PyObject *self, PyObject *args, PyObject *kwdict) {
static char *kwlist[] = {
"start", "end", "count", "cooked", "step", "file_obj", "date_format", NULL,
};
cdb_time_t start = 0;
cdb_time_t end = 0;
int cooked = 1;
long step = 0;
int64_t count = 0;
cdb_t *cdb;
PyObject *file_obj, *date_format;
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|LLLOzil:print_records", kwlist, &start, &end, &count, &file_obj, &date_format, &cooked, &step)) {
return NULL;
}
cdb_request_t request = _parse_cdb_request(start, end, count, cooked, step);
if (Py_None == date_format) {
date_format = PyString_FromString("");
}
if (Py_None == file_obj || !PyFile_Check(file_obj)) {
file_obj = PyString_FromString("stderr");
}
cdb = ((StorageObject*)self)->cdb;
cdb_print_records(cdb, &request, PyFile_AsFile(file_obj), PyString_AsString(date_format));
return self;
}
开发者ID:dsully,项目名称:circulardb,代码行数:33,代码来源:circulardb.c
示例8: _librsync_new_patchmaker
/* Call with the basis file */
static PyObject*
_librsync_new_patchmaker(PyObject* self, PyObject* args)
{
_librsync_PatchMakerObject* pm;
PyObject *python_file;
FILE *cfile;
if (!PyArg_ParseTuple(args, "O:new_patchmaker", &python_file))
return NULL;
if (!PyFile_Check(python_file)) {
PyErr_SetString(PyExc_TypeError, "Need true file object");
return NULL;
}
Py_INCREF(python_file);
pm = PyObject_New(_librsync_PatchMakerObject, &_librsync_PatchMakerType);
if (pm == NULL) return NULL;
pm->x_attr = NULL;
pm->basis_file = python_file;
cfile = PyFile_AsFile(python_file);
pm->patch_job = rs_patch_begin(rs_file_copy_cb, cfile);
return (PyObject*)pm;
}
开发者ID:Christoph-D,项目名称:rdiff-backup,代码行数:26,代码来源:_librsyncmodule.c
示例9: PyLoadparmService_AsLoadparmService
static PyObject *py_lp_service_dump(PyObject *self, PyObject *args)
{
PyObject *py_stream;
bool show_defaults = false;
FILE *f;
struct loadparm_service *service = PyLoadparmService_AsLoadparmService(self);
struct loadparm_service *default_service;
PyObject *py_default_service;
if (!PyArg_ParseTuple(args, "OO|b", &py_stream, &py_default_service,
&show_defaults))
return NULL;
f = PyFile_AsFile(py_stream);
if (f == NULL) {
PyErr_SetString(PyExc_TypeError, "Not a file stream");
return NULL;
}
if (!PyObject_TypeCheck(py_default_service, &PyLoadparmService)) {
PyErr_SetNone(PyExc_TypeError);
return NULL;
}
default_service = PyLoadparmService_AsLoadparmService(py_default_service);
lpcfg_dump_one(f, show_defaults, service, default_service);
Py_RETURN_NONE;
}
开发者ID:Arkhont,项目名称:samba,代码行数:30,代码来源:pyparam.c
示例10: image_surface_create_from_png
/* METH_O | METH_CLASS */
static PyObject *
image_surface_create_from_png (PyTypeObject *type, PyObject *o)
{
FILE *fp;
cairo_surface_t *surface;
if (PyObject_TypeCheck (o, &PyBaseString_Type)) {
fp = fopen (PyString_AsString(o), "rb");
if (fp == NULL) {
PyErr_SetString(PyExc_IOError, "unable to open file for reading");
return NULL;
}
} else if (PyObject_TypeCheck (o, &PyFile_Type)) {
fp = PyFile_AsFile(o);
} else {
PyErr_SetString(PyExc_TypeError,
"ImageSurface.create_from_png takes one argument "
"which must be a filename (str) or file object");
return NULL;
}
surface = cairo_image_surface_create_from_png_stream (_read_func, fp);
if (PyObject_TypeCheck (o, &PyBaseString_Type))
fclose (fp);
return PycairoSurface_FromSurface (surface, &PycairoImageSurface_Type,
NULL);
}
开发者ID:curaloucura,项目名称:enso,代码行数:31,代码来源:pycairo-surface.c
示例11: dsn_app_bridge
DSN_PY_API dsn_error_t dsn_app_bridge(int argc, const char** argv)
{
std::vector< std::string> args;
for (int i = 0; i < argc; i++)
{
std::string ag(*argv++);
args.push_back(ag);
}
new std::thread([=](){
Py_Initialize();
char* PyFileName = (char *)args[0].c_str();
char** PyParameterList = new char* [args.size()];
for (int i = 0;i < args.size(); ++i)
{
PyParameterList[i] = new char[args[i].size()+1];
strcpy(PyParameterList[i], args[i].c_str());
}
PySys_SetArgv((int)args.size(), PyParameterList);
PyObject* PyFileObject = PyFile_FromString(PyFileName, "r");
PyRun_SimpleFile(PyFile_AsFile(PyFileObject), PyFileName);
Py_Finalize();
for (int i = 0; i < args.size(); ++i)
{
delete [] PyParameterList[i];
}
delete [] PyParameterList;
});
dsn_app_loader_wait();
return dsn::ERR_OK;
}
开发者ID:goksyli,项目名称:rDSN.Python,代码行数:33,代码来源:python_helper.cpp
示例12: dummy_decode_command
/*
dummy.decode_command_n(stream, N) -> ((cmd_code, args), .... (cmd_code_N, args_N))
*/
static PyObject *
dummy_decode_command(PyObject *self, PyObject *args) {
int N = 1;
PyObject *po = PyTuple_GetItem(args, 0);
if (!PyFile_Check(po)) {
PyErr_SetString(DummyError, "First argument should be a file object.");
return NULL;
}
if (PyTuple_Size(args) == 2) {
PyObject *pn = PyTuple_GetItem(args, 1);
N = PyInt_AS_LONG(pn);
}
hu::FileInStream stream;
FILE *handle = PyFile_AsFile(po);
stream.open(handle);
PyObject* res = PyTuple_New(N);
for(int i = 0; i < N ; ++i) {
PyObject* cmd = decoder.decode_cmd_from_stream(stream);
if (cmd == NULL) {
return NULL;
}
PyTuple_SET_ITEM(res, i, cmd);
if (PyInt_AS_LONG(PyTuple_GetItem(cmd, 0)) == CLOSE) {
_PyTuple_Resize(&res, i + 1);
return res;
}
}
return res;
}
开发者ID:gitter-badger,项目名称:pydoop,代码行数:36,代码来源:dummy.cpp
示例13: freopen
Pyramid::Pyramid(const char* script)
{
freopen("pyramid.log", "w", stdout);
freopen("pyramid.log", "a", stderr);
Py_SetProgramName(".\\pyramid");
Py_Initialize();
init_pyramid();
PyRun_SimpleString(
"import sys\n"
"sys.path.append('./')\n"
"sys.stderr = open('python_errors.log', 'w', 0)\n"
"sys.stdout = open('pyramid.log', 'a', 0)\n"
"import pyramid\n");
char* fn_local = new char[strlen(script)+1];
strcpy(fn_local, script);
PyObject* fp = PyFile_FromString(fn_local, "r");
if(!fp)
{
printf("Could not load mapping script '%s' for reading.\n", script);
Py_Finalize();
exit(1);
}
FILE* sfp = PyFile_AsFile(fp);
PyRun_AnyFileEx(sfp, script, 1);
delete[] fn_local;
}
开发者ID:m4burns,项目名称:pyramid,代码行数:31,代码来源:Pyramid.cpp
示例14: FlowLog_write_flow
Writes a flow record to the flow log\n\
");
static PyObject *
FlowLog_write_flow(FlowLogObject *self, PyObject *args, PyObject *kw_args)
{
struct store_flow_complete flow;
static char *keywords[] = { "flow", "fieldmask", NULL };
char ebuf[512];
FlowObject *flowobj = NULL;
u_int32_t mask = STORE_DISPLAY_ALL;
if (!PyArg_ParseTupleAndKeywords(args, kw_args, "O!|k:write_flow",
keywords, &Flow_Type, (PyObject *)&flowobj, &mask))
return NULL;
if (flowobj_normalise(flowobj) == -1)
return (NULL);
memcpy(&flow, &flowobj->flow, sizeof(flow));
store_swab_flow(&flow, 1);
if (store_write_flow(PyFile_AsFile(self->flowlog), &flow, mask,
ebuf, sizeof(ebuf)) != STORE_ERR_OK) {
PyErr_SetString(PyExc_ValueError, ebuf);
return (NULL);
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:amirkrifa,项目名称:Network-Monitoring-Emulation-Framework,代码行数:32,代码来源:flowd_python.c
示例15: PyFile_AsFile
static PyObject *bits_disk_read(PyObject *self, PyObject *args)
{
PyObject *pyfile, *pystr;
grub_file_t file;
grub_disk_addr_t sector;
unsigned offset, length;
if (!PyArg_ParseTuple(args, "O!KII:disk_read", &PyFile_Type, &pyfile, §or, &offset, &length))
return NULL;
file = PyFile_AsFile(pyfile);
if (!file->device->disk)
return PyErr_Format(PyExc_RuntimeError, "Can't get disk device from non-disk-backed file");
pystr = PyString_FromStringAndSize(NULL, length);
if (!pystr)
return PyErr_NoMemory();
if (grub_disk_read(file->device->disk, sector, offset, length, PyString_AsString(pystr)) != GRUB_ERR_NONE) {
Py_DECREF(pystr);
return PyErr_SetFromErrno(PyExc_IOError);
}
return pystr;
}
开发者ID:mfleming,项目名称:bits,代码行数:25,代码来源:bitsmodule.c
示例16: exec_file
// Execute python source code from file filename.
// global and local are the global and local scopes respectively,
// used during execution.
object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
{
// Set suitable default values for global and local dicts.
object none;
if (global.ptr() == none.ptr())
{
if (PyObject *g = PyEval_GetGlobals())
global = object(detail::borrowed_reference(g));
else
global = dict();
}
if (local.ptr() == none.ptr()) local = global;
// should be 'char const *' but older python versions don't use 'const' yet.
char *f = python::extract<char *>(filename);
// Let python open the file to avoid potential binary incompatibilities.
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
python::handle<> file(pyfile);
PyObject* result = PyRun_File(PyFile_AsFile(file.get()),
f,
Py_file_input,
global.ptr(), local.ptr());
if (!result) throw_error_already_set();
return object(detail::new_reference(result));
}
开发者ID:coxlab,项目名称:boost_patched_for_objcplusplus,代码行数:28,代码来源:exec.cpp
示例17: print
PyObject *ekg_cmd_watch_add(PyObject * self, PyObject * args)
{
PyObject *callback = NULL;
PyObject *module = NULL;
PyObject *fileobj = NULL;
script_t * scr;
int type;
FILE * fd;
if (!PyArg_ParseTuple(args, "O!iiO", &PyFile_Type, &fileobj, &type, &callback)) {
return NULL;
}
if (!PyCallable_Check(callback)) {
print("generic_error", _("Second parameter to watch_add is not callable"));
PyErr_SetString(PyExc_TypeError, _("Parameter must be callable"));
return NULL;
}
Py_XINCREF(callback);
fd = PyFile_AsFile(fileobj);
Py_INCREF(fileobj);
module = PyObject_GetAttrString(callback, "__module__");
scr = python_find_script(module);
script_watch_add(&python_lang, scr, fileno(fd), type, callback, fileobj);
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:dmilith,项目名称:ekg2-bsd,代码行数:31,代码来源:python-ekg.c
示例18: FileScanner_FileScanN
static PyObject * FileScanner_FileScanN(PyObject *self, PyObject *args)
{
PyFileObject *File;
PyArrayObject *Array;
npy_intp length;
double *Data;
int i;
//printf("Starting\n");
if (!PyArg_ParseTuple(args, "O!i", &PyFile_Type, &File, &length) ) {
return NULL;
}
Data = calloc(length, sizeof(double) );
if ((i = filescan(PyFile_AsFile( (PyObject*)File ), length, Data)) < length){
PyErr_SetString (PyExc_ValueError,
"End of File reached before all numbers found");
free(Data);
return NULL;
}
Array = (PyArrayObject *) PyArray_SimpleNew(1, &length, PyArray_DOUBLE);
for (i = 0; i< length ; i++){
*(double *)(Array->data + (i * Array->strides[0] ) ) = Data[i];
}
free(Data);
return PyArray_Return(Array);
}
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:35,代码来源:FileScan_module.c
示例19: py_load_module
/* Loads a file into a module; it is not inserted into sys.modules */
static int py_load_module(PyObject *module, const char *path)
{
PyObject *dict, *ret, *fp;
if (PyModule_AddStringConstant(module, "__file__", (char *)path) < 0)
return 0;
dict = PyModule_GetDict(module);
if (PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins()) < 0)
return 0;
/* Dont use the standard library to avoid incompatabilities with
the FILE structure and Python */
fp = PyFile_FromString((char *)path, "r");
if (!fp)
return 0;
ret = PyRun_File(PyFile_AsFile(fp), path, Py_file_input, dict, dict);
Py_DECREF(fp); /* XXX: I assume that the file is closed when refs drop to zero? */
if (!ret)
return 0;
Py_DECREF(ret);
return 1;
}
开发者ID:SteveClement,项目名称:irssi-python,代码行数:28,代码来源:pyloader.c
示例20: defined
static PyObject *cdrom_leadout(PyObject *self, PyObject *args)
{
struct CDDB_TOC_ENTRY_STRUCT entry;
PyObject *cdrom_fileobj;
int cdrom_fd;
#if defined(__OpenBSD__)
struct cd_toc_entry data;
#endif
if (!PyArg_ParseTuple(args, "O!", &PyFile_Type, &cdrom_fileobj))
return NULL;
cdrom_fd = fileno(PyFile_AsFile(cdrom_fileobj));
entry.CDDB_TRACK_FIELD = CDDB_CDROM_LEADOUT;
entry.CDDB_FORMAT_FIELD = CDDB_MSF_FORMAT;
#if defined(__OpenBSD__)
entry.data = &data;
entry.data_len = sizeof(data);
#endif
if (ioctl(cdrom_fd, CDDB_READ_TOC_ENTRY_FLAG, &entry) < 0) {
PyErr_SetFromErrno(cdrom_error);
return NULL;
}
return Py_BuildValue("bbb", entry.CDDB_ADDR_FIELD.msf.minute,
entry.CDDB_ADDR_FIELD.msf.second,
entry.CDDB_ADDR_FIELD.msf.frame);
}
开发者ID:jtackaberry,项目名称:stagehand,代码行数:32,代码来源:cdrommodule.c
注:本文中的PyFile_AsFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论