本文整理汇总了C++中PyObject_AsFileDescriptor函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_AsFileDescriptor函数的具体用法?C++ PyObject_AsFileDescriptor怎么用?C++ PyObject_AsFileDescriptor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_AsFileDescriptor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: strcaps_get_file
static PyObject *
strcaps_get_file(PyObject *self, PyObject *args) { // (int) fd / (str) path / (file) file
PyObject *file;
if (!PyArg_ParseTuple(args, "O", &file)) return NULL;
cap_t caps;
if (PyFile_Check(file)) caps = cap_get_fd(PyObject_AsFileDescriptor(file));
else if (PyInt_Check(file)) caps = cap_get_fd(PyInt_AsLong(file));
else if (PyString_Check(file)) caps = cap_get_file(PyString_AsString(file));
else if (PyUnicode_Check(file)) {
PyObject *file_dec = PyUnicode_AsEncodedString(
file, Py_FileSystemDefaultEncoding, "strict" );
if (file_dec == NULL) return NULL;
caps = cap_get_file(PyString_AsString(file_dec));
Py_DECREF(file_dec); }
else {
PyErr_SetString( PyExc_TypeError,
"Expecting file object, descriptor int or path string" );
return NULL; }
size_t strcaps_len; char *strcaps;
if (caps == NULL) {
if (errno == ENODATA) { strcaps = "\0"; strcaps_len = 0; }
else {
PyErr_SetFromErrno(PyExc_OSError);
return NULL; } }
else strcaps = cap_to_text(caps, &strcaps_len);
cap_free(caps);
return Py_BuildValue("s#", strcaps, strcaps_len); }; // (str) caps
开发者ID:mk-fg,项目名称:fgc,代码行数:27,代码来源:strcaps.c
示例2: on_write_sendfile
static write_state
on_write_sendfile(struct ev_loop* mainloop, Request* request)
{
/* A sendfile response is split into two phases:
* Phase A) sending HTTP headers
* Phase B) sending the actual file contents
*/
if(request->current_chunk) {
/* Phase A) -- current_chunk contains the HTTP headers */
if (do_send_chunk(request)) {
// data left to send in the current chunk
return not_yet_done;
} else {
assert(request->current_chunk == NULL);
assert(request->current_chunk_p == 0);
/* Transition to Phase B) -- abuse current_chunk_p to store the file fd */
request->current_chunk_p = PyObject_AsFileDescriptor(request->iterable);
// don't stop yet, Phase B is still missing
return not_yet_done;
}
} else {
/* Phase B) -- current_chunk_p contains file fd */
if (do_sendfile(request)) {
// Haven't reached the end of file yet
return not_yet_done;
} else {
// Done with the file
return done;
}
}
}
开发者ID:crudbug,项目名称:bjoern,代码行数:31,代码来源:server.c
示例3: run
static PyObject*
run(PyObject* self, PyObject* args)
{
ServerInfo info;
PyObject* socket;
if(!PyArg_ParseTuple(args, "OO:server_run", &socket, &info.wsgi_app)) {
return NULL;
}
info.sockfd = PyObject_AsFileDescriptor(socket);
if (info.sockfd < 0) {
return NULL;
}
info.host = NULL;
if (PyObject_HasAttrString(socket, "getsockname")) {
PyObject* sockname = PyObject_CallMethod(socket, "getsockname", NULL);
if (sockname == NULL) {
return NULL;
}
if (PyTuple_CheckExact(sockname) && PyTuple_GET_SIZE(sockname) == 2) {
/* Standard (ipaddress, port) case */
info.host = PyTuple_GET_ITEM(sockname, 0);
info.port = PyTuple_GET_ITEM(sockname, 1);
}
}
_initialize_request_module();
server_run(&info);
Py_RETURN_NONE;
}
开发者ID:oglu,项目名称:bjoern,代码行数:34,代码来源:_bjoernmodule.c
示例4: PyObject_AsFileDescriptor
static PyObject *PyScript_io_add_watch(PyScript *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"fd", "func", "data", "condition", NULL};
int fd = 0;
PyObject *pyfd = NULL;
PyObject *func = NULL;
PyObject *data = NULL;
int condition = G_IO_IN | G_IO_PRI;
int ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|Oi", kwlist,
&pyfd, &func, &data, &condition))
return NULL;
fd = PyObject_AsFileDescriptor(pyfd);
if (fd < 0)
return NULL;
if (!PyCallable_Check(func))
return PyErr_Format(PyExc_TypeError, "func not callable");
ret = pysource_io_add_watch_list(&self->sources, fd, condition, func, data);
return PyInt_FromLong(ret);
}
开发者ID:SteveClement,项目名称:irssi-python,代码行数:25,代码来源:pyscript-object.c
示例5: session_startup
static PyObject *
session_startup(SSH2_SessionObj *self, PyObject *args)
{
PyObject *sock;
int ret;
int fd;
if (!PyArg_ParseTuple(args, "O:startup", &sock))
return NULL;
if ((fd = PyObject_AsFileDescriptor(sock)) == -1) {
PyErr_SetString(PyExc_ValueError, "argument must be a file descriptor");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
ret=libssh2_session_startup(self->session, fd);
Py_END_ALLOW_THREADS
CHECK_RETURN_CODE(ret, self)
Py_DECREF(self->socket);
Py_INCREF(sock);
self->socket = sock;
self->opened = 1;
Py_RETURN_NONE;
}
开发者ID:vianney,项目名称:ssh4py,代码行数:29,代码来源:session.c
示例6: strcaps_set_file
static PyObject *
strcaps_set_file(PyObject *self, PyObject *args) { // (str) caps, (int) fd / (str) path / (file) file
char *strcaps; PyObject *file;
if (!PyArg_ParseTuple(args, "etO",
Py_FileSystemDefaultEncoding, &strcaps, &file)) return NULL;
cap_t caps;
if ((caps = cap_from_text(strcaps)) == NULL) {
PyErr_SetString(PyExc_ValueError, "Invalid capability specification");
PyMem_Free(strcaps);
return NULL; }
PyMem_Free(strcaps);
int err;
if (PyFile_Check(file)) err = cap_set_fd(PyObject_AsFileDescriptor(file), caps);
else if (PyInt_Check(file)) err = cap_set_fd(PyInt_AsLong(file), caps);
else if (PyString_Check(file)) err = cap_set_file(PyString_AsString(file), caps);
else if (PyUnicode_Check(file)) {
PyObject *file_dec = PyUnicode_AsEncodedString(
file, Py_FileSystemDefaultEncoding, "strict" );
if (file_dec == NULL) return NULL;
err = cap_set_file(PyString_AsString(file_dec), caps);
Py_DECREF(file_dec); }
else {
PyErr_SetString( PyExc_TypeError,
"Expecting file object, descriptor int or path string" );
cap_free(caps);
return NULL; }
cap_free(caps);
if (err) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL; }
Py_RETURN_NONE; };
开发者ID:mk-fg,项目名称:fgc,代码行数:31,代码来源:strcaps.c
示例7: start_response_file
static response_status
start_response_file(client_t *client)
{
PyObject *filelike;
FileWrapperObject *filewrap;
int ret,in_fd, size;
struct stat info;
filewrap = (FileWrapperObject *)client->response;
filelike = filewrap->filelike;
in_fd = PyObject_AsFileDescriptor(filelike);
if (in_fd == -1) {
PyErr_Clear();
DEBUG("can't get fd");
return STATUS_ERROR;
}
ret = write_headers(client, NULL, 0, 1);
if(!client->content_length_set){
if (fstat(in_fd, &info) == -1){
PyErr_SetFromErrno(PyExc_IOError);
/* write_error_log(__FILE__, __LINE__); */
call_error_logger();
return STATUS_ERROR;
}
size = info.st_size;
client->content_length_set = 1;
client->content_length = size;
}
return ret;
}
开发者ID:yosisa,项目名称:meinheld,代码行数:33,代码来源:response.c
示例8: poll_register
static PyObject *
poll_register(pollObject *self, PyObject *args)
{
PyObject *o, *key, *value;
int fd, events = POLLIN | POLLPRI | POLLOUT;
int err;
if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) {
return NULL;
}
fd = PyObject_AsFileDescriptor(o);
if (fd == -1) return NULL;
/* Add entry to the internal dictionary: the key is the
file descriptor, and the value is the event mask. */
key = PyInt_FromLong(fd);
if (key == NULL)
return NULL;
value = PyInt_FromLong(events);
if (value == NULL) {
Py_DECREF(key);
return NULL;
}
err = PyDict_SetItem(self->dict, key, value);
Py_DECREF(key);
Py_DECREF(value);
if (err < 0)
return NULL;
self->ufd_uptodate = 0;
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:35,代码来源:selectmodule.c
示例9: _librsync_new_patchmaker
/* Call with the basis file */
static PyObject*
_librsync_new_patchmaker(PyObject* self, PyObject* args)
{
_librsync_PatchMakerObject* pm;
PyObject *python_file;
int fd;
FILE *cfile;
if (!PyArg_ParseTuple(args, "O:new_patchmaker", &python_file))
return NULL;
fd = PyObject_AsFileDescriptor(python_file);
if (fd == -1) {
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->basis_file = python_file;
cfile = fdopen(fd, "rb");
pm->patch_job = rs_patch_begin(rs_file_copy_cb, cfile);
return (PyObject*)pm;
}
开发者ID:cmjonze,项目名称:duplicity,代码行数:27,代码来源:_librsyncmodule.c
示例10: poll_unregister
static PyObject *
poll_unregister(pollObject *self, PyObject *args)
{
PyObject *o, *key;
int fd;
if (!PyArg_ParseTuple(args, "O:unregister", &o)) {
return NULL;
}
fd = PyObject_AsFileDescriptor( o );
if (fd == -1)
return NULL;
/* Check whether the fd is already in the array */
key = PyInt_FromLong(fd);
if (key == NULL)
return NULL;
if (PyDict_DelItem(self->dict, key) == -1) {
Py_DECREF(key);
/* This will simply raise the KeyError set by PyDict_DelItem
if the file descriptor isn't registered. */
return NULL;
}
Py_DECREF(key);
self->ufd_uptodate = 0;
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:32,代码来源:selectmodule.c
示例11: set_Io
/* set the Io */
int
set_Io(Io *self, PyObject *fd, int events)
{
int fdnum;
#ifdef MS_WINDOWS
if (!PyObject_TypeCheck(fd, PySocketModule.Sock_Type)) {
PyErr_SetString(PyExc_TypeError, "only socket objects are supported "
"in this configuration");
return -1;
}
#endif
fdnum = PyObject_AsFileDescriptor(fd);
if (fdnum == -1) {
return -1;
}
#ifdef MS_WINDOWS
fdnum = EV_WIN32_HANDLE_TO_FD(fdnum);
if (fdnum == -1) {
PyErr_SetFromWindowsErr(0);
return -1;
}
#endif
if (events & ~(EV_READ | EV_WRITE)) {
PyErr_SetString(Error, "illegal event mask");
return -1;
}
ev_io_set(&self->io, fdnum, events);
return 0;
}
开发者ID:CZ-NIC,项目名称:dionaea,代码行数:31,代码来源:Io.c
示例12: igraphmodule_filehandle_init
/**
* \ingroup python_interface_filehandle
* \brief Constructs a new file handle object from a Python object.
*
* \return 0 if everything was OK, 1 otherwise. An appropriate Python
* exception is raised in this case.
*/
int igraphmodule_filehandle_init(igraphmodule_filehandle_t* handle,
PyObject* object, char* mode) {
#ifdef IGRAPH_PYTHON3
int fp;
if (object == 0 || PyLong_Check(object)) {
PyErr_SetString(PyExc_TypeError, "string or file-like object expected");
return 1;
}
#else
if (object == 0 ||
(!PyBaseString_Check(object) && !PyFile_Check(object))) {
PyErr_SetString(PyExc_TypeError, "string or file handle expected");
return 1;
}
#endif
if (PyBaseString_Check(object)) {
#ifdef IGRAPH_PYTHON3
handle->object = PyFile_FromObject(object, mode);
#else
handle->object = PyFile_FromString(PyString_AsString(object), mode);
#endif
if (handle->object == 0)
return 1;
} else {
handle->object = object;
Py_INCREF(handle->object);
}
/* At this stage, handle->object is something we can handle.
* In Python 2, we get here only if object is a file object. In
* Python 3, object can be anything, and PyFile_FromObject will
* complain if the object cannot be converted to a file handle.
*/
#ifdef IGRAPH_PYTHON3
fp = PyObject_AsFileDescriptor(handle->object);
if (fp == -1) {
Py_DECREF(handle->object);
return 1;
}
handle->fp = fdopen(fp, mode);
if (handle->fp == 0) {
Py_DECREF(handle->object);
PyErr_SetString(PyExc_RuntimeError, "fdopen() failed unexpectedly");
return 1;
}
#else
handle->fp = PyFile_AsFile(handle->object);
if (handle->fp == 0) {
Py_DECREF(handle->object);
PyErr_SetString(PyExc_RuntimeError, "PyFile_AsFile() failed unexpectedly");
return 1;
}
#endif
return 0;
}
开发者ID:CansenJIANG,项目名称:igraph,代码行数:64,代码来源:filehandle.c
示例13: manage_raw_response
static int manage_raw_response(struct wsgi_request *wsgi_req) {
int ret = 0;
if (!wsgi_req->async_force_again) {
ret = uwsgi_python_send_body(wsgi_req, (PyObject *) wsgi_req->async_result);
if (ret == 0) {
if (PyInt_Check((PyObject *) wsgi_req->async_result) || PyObject_HasAttrString((PyObject *) wsgi_req->async_result, "fileno")) {
// is it a file ?
int fd = PyObject_AsFileDescriptor((PyObject *) wsgi_req->async_result);
if (fd >= 0) {
wsgi_req->sendfile_fd = fd;
uwsgi_response_sendfile_do(wsgi_req, fd, 0, 0);
wsgi_req->sendfile_fd = -1;
return UWSGI_OK;
}
}
}
}
if (ret == 0) {
if (!wsgi_req->async_placeholder) {
wsgi_req->async_placeholder = PyObject_GetIter((PyObject *) wsgi_req->async_result);
if (!wsgi_req->async_placeholder)
return UWSGI_OK;
}
PyObject *pychunk = PyIter_Next((PyObject *) wsgi_req->async_placeholder);
if (!pychunk)
return UWSGI_OK;
ret = uwsgi_python_send_body(wsgi_req, pychunk);
if (ret == 0) {
if (PyInt_Check(pychunk) || PyObject_HasAttrString(pychunk, "fileno")) {
// is it a file ?
int fd = PyObject_AsFileDescriptor(pychunk);
if (fd >= 0) {
wsgi_req->sendfile_fd = fd;
uwsgi_response_sendfile_do(wsgi_req, fd, 0, 0);
wsgi_req->sendfile_fd = -1;
}
}
}
Py_DECREF(pychunk);
return UWSGI_AGAIN;
}
return UWSGI_OK;
}
开发者ID:CashStar,项目名称:uwsgi,代码行数:44,代码来源:raw.c
示例14: conv_descriptor
static int
conv_descriptor(PyObject *object, int *target)
{
int fd = PyObject_AsFileDescriptor(object);
if (fd < 0)
return 0;
*target = fd;
return 1;
}
开发者ID:davidbj,项目名称:cpython,代码行数:10,代码来源:fcntlmodule.c
示例15: file_conv
static int file_conv(PyObject *object, int *fdp)
{
int fd = PyObject_AsFileDescriptor(object);
if (fd < 0)
return 0;
*fdp = fd;
return 1;
}
开发者ID:dillonhicks,项目名称:ipymake,代码行数:10,代码来源:dskimodule.c
示例16: libxml_PyFileGet
FILE *
libxml_PyFileGet(PyObject *f) {
int fd, flags;
FILE *res;
const char *mode;
fd = PyObject_AsFileDescriptor(f);
if (!_PyVerify_fd(fd))
return(NULL);
/*
* Get the flags on the fd to understand how it was opened
*/
flags = fcntl(fd, F_GETFL, 0);
switch (flags & O_ACCMODE) {
case O_RDWR:
if (flags & O_APPEND)
mode = "a+";
else
mode = "rw";
break;
case O_RDONLY:
if (flags & O_APPEND)
mode = "r+";
else
mode = "r";
break;
case O_WRONLY:
if (flags & O_APPEND)
mode = "a";
else
mode = "w";
break;
default:
return(NULL);
}
/*
* the FILE struct gets a new fd, so that it can be closed
* independently of the file descriptor given. The risk though is
* lack of sync. So at the python level sync must be implemented
* before and after a conversion took place. No way around it
* in the Python3 infrastructure !
* The duplicated fd and FILE * will be released in the subsequent
* call to libxml_PyFileRelease() which must be genrated accodingly
*/
fd = dup(fd);
if (fd == -1)
return(NULL);
res = fdopen(fd, mode);
if (res == NULL) {
close(fd);
return(NULL);
}
return(res);
}
开发者ID:VikingDen,项目名称:android_external_Focal,代码行数:55,代码来源:types.c
示例17: fdconv
static int fdconv(PyObject* obj, void* p)
{
int fd;
fd = PyObject_AsFileDescriptor(obj);
if (fd >= 0) {
*(int*)p = fd;
return 1;
}
return 0;
}
开发者ID:CSC-IT-Center-for-Science,项目名称:scalable-python,代码行数:11,代码来源:termios.c
示例18: current_wsgi_req
PyObject *py_uwsgi_sendfile(PyObject * self, PyObject * args) {
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
if (!PyArg_ParseTuple(args, "Oi:uwsgi_sendfile", &wsgi_req->async_sendfile, &wsgi_req->sendfile_fd_chunk)) {
return NULL;
}
#ifdef PYTHREE
wsgi_req->sendfile_fd = PyObject_AsFileDescriptor(wsgi_req->async_sendfile);
#else
if (PyFile_Check((PyObject *)wsgi_req->async_sendfile)) {
Py_INCREF((PyObject *)wsgi_req->async_sendfile);
wsgi_req->sendfile_fd = PyObject_AsFileDescriptor(wsgi_req->async_sendfile);
}
#endif
return PyTuple_New(0);
}
开发者ID:mlzboy,项目名称:resys,代码行数:20,代码来源:sendfile.c
示例19: rpmfd_init
static int rpmfd_init(rpmfdObject *s, PyObject *args, PyObject *kwds)
{
char *kwlist[] = { "obj", "mode", "flags", NULL };
const char *mode = "r";
const char *flags = "ufdio";
char *rpmio_mode = NULL;
PyObject *fo = NULL;
FD_t fd = NULL;
int fdno;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist,
&fo, &mode, &flags))
return -1;
rpmio_mode = rstrscat(NULL, mode, ".", flags, NULL);
if (PyBytes_Check(fo)) {
fd = openPath(PyBytes_AsString(fo), rpmio_mode);
} else if (PyUnicode_Check(fo)) {
PyObject *enc = NULL;
int rc;
#if PY_MAJOR_VERSION >= 3
rc = PyUnicode_FSConverter(fo, &enc);
#else
rc = utf8FromPyObject(fo, &enc);
#endif
if (rc) {
fd = openPath(PyBytes_AsString(enc), rpmio_mode);
Py_DECREF(enc);
}
} else if (rpmfdObject_Check(fo)) {
rpmfdObject *fdo = (rpmfdObject *)fo;
fd = openFd(fdDup(Fileno(fdo->fd)), rpmio_mode);
} else if ((fdno = PyObject_AsFileDescriptor(fo)) >= 0) {
fd = openFd(fdDup(fdno), rpmio_mode);
} else {
PyErr_SetString(PyExc_TypeError, "path or file object expected");
}
if (fd != NULL) {
Fclose(s->fd); /* in case __init__ was called again */
free(s->mode);
free(s->flags);
s->fd = fd;
s->mode = rstrdup(mode);
s->flags = rstrdup(flags);
} else {
PyErr_SetString(PyExc_IOError, Fstrerror(fd));
}
free(rpmio_mode);
return (fd == NULL) ? -1 : 0;
}
开发者ID:Distrotech,项目名称:rpm,代码行数:53,代码来源:rpmfd-py.c
示例20: igraphmodule_i_filehandle_init_cpython_3
static int igraphmodule_i_filehandle_init_cpython_3(igraphmodule_filehandle_t* handle,
PyObject* object, char* mode) {
int fp;
if (object == 0 || PyLong_Check(object)) {
PyErr_SetString(PyExc_TypeError, "string or file-like object expected");
return 1;
}
handle->need_close = 0;
handle->object = 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_FromObject(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;
} else {
/* This is probably a file-like object; store a reference for it and
* we will handle it later */
handle->object = object;
Py_INCREF(handle->object);
}
/* At this stage, handle->object is something we can handle.
* We have to call PyObject_AsFileDescriptor instead
* and then fdopen() it to get the corresponding FILE* object.
*/
fp = PyObject_AsFileDescriptor(handle->object);
if (fp == -1) {
igraphmodule_filehandle_destroy(handle);
/* This already called Py_DECREF(handle->object), no need to call it */
return 1;
}
handle->fp = fdopen(fp, mode);
if (handle->fp == 0) {
igraphmodule_filehandle_destroy(handle);
/* This already called Py_DECREF(handle->object), no need to call it */
PyErr_SetString(PyExc_RuntimeError, "fdopen() failed unexpectedly");
return 1;
}
return 0;
}
开发者ID:Sarmentor,项目名称:python-igraph,代码行数:51,代码来源:filehandle.c
注:本文中的PyObject_AsFileDescriptor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论