本文整理汇总了C++中PyFile_AsFile函数的典型用法代码示例。如果您正苦于以下问题:C++ PyFile_AsFile函数的具体用法?C++ PyFile_AsFile怎么用?C++ PyFile_AsFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyFile_AsFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}