本文整理汇总了C++中PyObject_GetAttr函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_GetAttr函数的具体用法?C++ PyObject_GetAttr怎么用?C++ PyObject_GetAttr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_GetAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: method_get_doc
static PyObject *
method_get_doc(PyMethodObject *im, void *context)
{
static PyObject *docstr;
if (docstr == NULL) {
docstr= PyUnicode_InternFromString("__doc__");
if (docstr == NULL)
return NULL;
}
return PyObject_GetAttr(im->im_func, docstr);
}
示例2: Py_INCREF
static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
__pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
PyObject *typ;
PyObject *tb = NULL;
PyObject *val = NULL;
PyObject *yf = gen->yieldfrom;
if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
return NULL;
if (unlikely(__Pyx_Generator_CheckRunning(gen)))
return NULL;
if (yf) {
PyObject *ret;
Py_INCREF(yf);
if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
int err = __Pyx_Generator_CloseIter(gen, yf);
Py_DECREF(yf);
__Pyx_Generator_Undelegate(gen);
if (err < 0)
return __Pyx_Generator_SendEx(gen, NULL);
goto throw_here;
}
gen->is_running = 1;
if (__Pyx_Generator_CheckExact(yf)) {
ret = __Pyx_Generator_Throw(yf, args);
} else {
PyObject *meth = PyObject_GetAttr(yf, PYIDENT("throw"));
if (unlikely(!meth)) {
Py_DECREF(yf);
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
gen->is_running = 0;
return NULL;
}
PyErr_Clear();
__Pyx_Generator_Undelegate(gen);
gen->is_running = 0;
goto throw_here;
}
ret = PyObject_CallObject(meth, args);
Py_DECREF(meth);
}
gen->is_running = 0;
Py_DECREF(yf);
if (!ret) {
ret = __Pyx_Generator_FinishDelegation(gen);
}
return ret;
}
throw_here:
__Pyx_Raise(typ, val, tb, NULL);
return __Pyx_Generator_SendEx(gen, NULL);
}
示例3: do_call_tc
static int
do_call_tc(pycbc_Connection *conn,
PyObject *obj,
PyObject *flags,
PyObject **result,
int mode)
{
PyObject *meth = NULL;
PyObject *args = NULL;
PyObject *strlookup = NULL;
int ret = -1;
switch (mode) {
case ENCODE_KEY:
strlookup = pycbc_helpers.tcname_encode_key;
args = PyTuple_Pack(1, obj);
break;
case DECODE_KEY:
strlookup = pycbc_helpers.tcname_decode_key;
args = PyTuple_Pack(1, obj);
break;
case ENCODE_VALUE:
strlookup = pycbc_helpers.tcname_encode_value;
args = PyTuple_Pack(2, obj, flags);
break;
case DECODE_VALUE:
strlookup = pycbc_helpers.tcname_decode_value;
args = PyTuple_Pack(2, obj, flags);
break;
}
if (args == NULL) {
PYCBC_EXC_WRAP(PYCBC_EXC_INTERNAL, 0, "Couldn't build arguments");
goto GT_DONE;
}
meth = PyObject_GetAttr(conn->tc, strlookup);
if (!meth) {
PYCBC_EXC_WRAP_OBJ(PYCBC_EXC_ENCODING, 0,
"Couldn't find transcoder method",
conn->tc);
goto GT_DONE;
}
*result = PyObject_Call(meth, args, NULL);
if (*result) {
ret = 0;
}
GT_DONE:
Py_XDECREF(meth);
Py_XDECREF(args);
return ret;
}
示例4: generic_flush
/* flush the write buffer */
static int
generic_flush(genericstreamobject *self, int passdown)
{
bufitem *current;
PyObject *joined, *result;
char *jptr;
Py_ssize_t size;
if (!self->write) {
PyErr_SetString(PyExc_AttributeError,
"This stream does not provide a write function"
);
return -1;
}
if (self->wbuf && self->wbuf_size > 0) {
joined = PyString_FromStringAndSize(NULL, self->wbuf_size);
jptr = PyString_AS_STRING(joined) + self->wbuf_size;
current = self->wbuf;
self->wbuf = NULL;
self->wbuf_size = 0;
while (current) {
size = PyString_GET_SIZE(current->load);
jptr -= size;
(void)memcpy(jptr, PyString_AS_STRING(current->load),
(size_t)size);
current = bufitem_del(current);
}
result = PyObject_CallFunction(self->write, "(O)", joined);
Py_DECREF(joined);
if (!result)
return -1;
Py_DECREF(result);
}
if (passdown) {
if (!self->flush) {
if (!(result = PyObject_GetAttr(self->ostream, flushproperty))) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1;
PyErr_Clear();
Py_INCREF(Py_None);
self->flush = Py_None;
}
else
self->flush = result;
}
if ( (self->flush != Py_None)
&& !(result = PyObject_CallObject(self->flush, NULL)))
return -1;
}
return 0;
}
示例5: instancemethod_get_doc
static PyObject *
instancemethod_get_doc(PyObject *self, void *context)
{
static PyObject *docstr;
if (docstr == NULL) {
docstr = PyUnicode_InternFromString("__doc__");
if (docstr == NULL)
return NULL;
}
return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr);
}
示例6: stop_event_loop
static void
stop_event_loop(lcb_io_opt_t io)
{
PyObject *fn;
pycbc_iops_t *pio = (pycbc_iops_t*)io;
pio->in_loop = 0;
fn = PyObject_GetAttr(pio->pyio, pycbc_helpers.ioname_stopwatch);
PyObject_CallFunctionObjArgs(fn, NULL);
Py_XDECREF(fn);
}
示例7: Checker_proxy
/* def proxy(self, value): */
static PyObject *
Checker_proxy(Checker *self, PyObject *value)
{
PyObject *checker, *r;
/* if type(value) is Proxy: */
/* return value */
if ((PyObject*)(value->ob_type) == Proxy)
{
Py_INCREF(value);
return value;
}
/* checker = getattr(value, '__Security_checker__', None) */
checker = PyObject_GetAttr(value, str___Security_checker__);
/* if checker is None: */
if (checker == NULL)
{
PyErr_Clear();
/* checker = selectChecker(value) */
checker = selectChecker(NULL, value);
if (checker == NULL)
return NULL;
/* if checker is None: */
/* return value */
if (checker == Py_None)
{
Py_DECREF(checker);
Py_INCREF(value);
return value;
}
}
else if (checker == Py_None)
{
PyObject *errv = Py_BuildValue("sO",
"Invalid value, None. "
"for security checker",
value);
if (errv != NULL)
{
PyErr_SetObject(PyExc_ValueError, errv);
Py_DECREF(errv);
}
return NULL;
}
r = PyObject_CallFunctionObjArgs(Proxy, value, checker, NULL);
Py_DECREF(checker);
return r;
}
示例8: default_owner_method
static PyObject*
default_owner_method( Member* member, PyObject* owner )
{
if( !PyString_Check( member->default_context ) )
return py_type_fail( "default owner method name must be a string" );
PyObjectPtr callable( PyObject_GetAttr( owner, member->default_context ) );
if( !callable )
return 0;
PyTuplePtr args( PyTuple_New( 0 ) );
if( !args )
return 0;
return callable( args ).release();
}
示例9: __Pyx_Globals
static PyObject* __Pyx_Globals(void) {
Py_ssize_t i;
//PyObject *d;
PyObject *names = NULL;
PyObject *globals = PyObject_GetAttrString($module_cname, "__dict__");
if (!globals) {
PyErr_SetString(PyExc_TypeError,
"current module must have __dict__ attribute");
goto bad;
}
names = PyObject_Dir($module_cname);
if (!names)
goto bad;
for (i = PyList_GET_SIZE(names)-1; i >= 0; i--) {
#if CYTHON_COMPILING_IN_PYPY
PyObject* name = PySequence_GetItem(names, i);
if (!name)
goto bad;
#else
PyObject* name = PyList_GET_ITEM(names, i);
#endif
if (!PyDict_Contains(globals, name)) {
PyObject* value = PyObject_GetAttr($module_cname, name);
if (!value) {
#if CYTHON_COMPILING_IN_PYPY
Py_DECREF(name);
#endif
goto bad;
}
if (PyDict_SetItem(globals, name, value) < 0) {
#if CYTHON_COMPILING_IN_PYPY
Py_DECREF(name);
#endif
Py_DECREF(value);
goto bad;
}
}
#if CYTHON_COMPILING_IN_PYPY
Py_DECREF(name);
#endif
}
Py_DECREF(names);
return globals;
// d = PyDictProxy_New(globals);
// Py_DECREF(globals);
// return d;
bad:
Py_XDECREF(names);
Py_XDECREF(globals);
return NULL;
}
示例10: Py_INCREF
/* "/home/sean/Projects/WorldMill/src/mill/workspace.pyx":42
* ograpi.OGR_DS_Destroy(cogr_ds)
*
* return collections # <<<<<<<<<<<<<<
*
* property collections:
*/
Py_INCREF(__pyx_v_collections);
__pyx_r = __pyx_v_collections;
goto __pyx_L0;
__pyx_r = Py_None; Py_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1:;
Py_XDECREF(__pyx_1);
Py_XDECREF(__pyx_4);
Py_XDECREF(__pyx_6);
Py_XDECREF(__pyx_7);
__Pyx_AddTraceback("mill.workspace.Workspace._read_collections");
__pyx_r = NULL;
__pyx_L0:;
Py_DECREF(__pyx_v_collections);
Py_DECREF(__pyx_v_n);
Py_DECREF(__pyx_v_i);
Py_DECREF(__pyx_v_layer_name);
Py_DECREF(__pyx_v_collection);
Py_DECREF(__pyx_v_self);
return __pyx_r;
}
static PyObject *__pyx_pf_4mill_9workspace_9Workspace_11collections___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_4mill_9workspace_9Workspace_11collections___get__(PyObject *__pyx_v_self) {
PyObject *__pyx_r;
int __pyx_1;
int __pyx_2;
PyObject *__pyx_3 = 0;
PyObject *__pyx_4 = 0;
Py_INCREF(__pyx_v_self);
/* "/home/sean/Projects/WorldMill/src/mill/workspace.pyx":47
* # A lazy property
* def __get__(self):
* if not self._collections: # <<<<<<<<<<<<<<
* self._collections = self._read_collections()
* return self._collections
*/
__pyx_1 = __Pyx_PyObject_IsTrue(((struct __pyx_obj_4mill_9workspace_Workspace *)__pyx_v_self)->_collections); if (unlikely(__pyx_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
__pyx_2 = (!__pyx_1);
if (__pyx_2) {
__pyx_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n__read_collections); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
__pyx_4 = PyObject_CallObject(__pyx_3, 0); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
Py_DECREF(((struct __pyx_obj_4mill_9workspace_Workspace *)__pyx_v_self)->_collections);
((struct __pyx_obj_4mill_9workspace_Workspace *)__pyx_v_self)->_collections = __pyx_4;
__pyx_4 = 0;
goto __pyx_L2;
}
__pyx_L2:;
/* "/home/sean/Projects/WorldMill/src/mill/workspace.pyx":49
* if not self._collections:
* self._collections = self._read_collections()
* return self._collections # <<<<<<<<<<<<<<
*
* def __getitem__(self, name):
*/
Py_INCREF(((struct __pyx_obj_4mill_9workspace_Workspace *)__pyx_v_self)->_collections);
__pyx_r = ((struct __pyx_obj_4mill_9workspace_Workspace *)__pyx_v_self)->_collections;
goto __pyx_L0;
__pyx_r = Py_None; Py_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1:;
Py_XDECREF(__pyx_3);
Py_XDECREF(__pyx_4);
__Pyx_AddTraceback("mill.workspace.Workspace.collections.__get__");
__pyx_r = NULL;
__pyx_L0:;
Py_DECREF(__pyx_v_self);
return __pyx_r;
}
示例11: OSD_descr_get
static PyObject *
OSD_descr_get(PyObject *self, PyObject *inst, PyObject *cls)
{
PyObject *provides;
if (inst == NULL)
return getObjectSpecification(NULL, cls);
provides = PyObject_GetAttr(inst, str__provides__);
if (provides != NULL)
return provides;
PyErr_Clear();
return implementedBy(NULL, cls);
}
示例12: iobase_closed
static int
iobase_closed(PyObject *self)
{
PyObject *res;
int closed;
/* This gets the derived attribute, which is *not* __IOBase_closed
in most cases! */
res = PyObject_GetAttr(self, _PyIO_str_closed);
if (res == NULL)
return 0;
closed = PyObject_IsTrue(res);
Py_DECREF(res);
return closed;
}
示例13: if
/*
* The descriptor's descriptor get slot.
*/
static PyObject *sipMethodDescr_descr_get(PyObject *self, PyObject *obj,
PyObject *type)
{
sipMethodDescr *md = (sipMethodDescr *)self;
(void)type;
if (obj == Py_None)
obj = NULL;
else if (md->mixin_name != NULL)
obj = PyObject_GetAttr(obj, md->mixin_name);
return PyCFunction_New(md->pmd, obj);
}
示例14: SWIG_Python_str_FromChar
/* VTable implementation */
PyObject *swig_get_method(size_t method_index, const char *method_name) const {
PyObject *method = vtable[method_index];
if (!method) {
swig::SwigVar_PyObject name = SWIG_Python_str_FromChar(method_name);
method = PyObject_GetAttr(swig_get_self(), name);
if (!method) {
std::string msg = "Method in class OTNameLookup doesn't exist, undefined ";
msg += method_name;
Swig::DirectorMethodException::raise(msg.c_str());
}
vtable[method_index] = method;
}
return method;
}
示例15: verifying_changed
static PyObject *
verifying_changed(verify *self, PyObject *ignored)
{
PyObject *t, *ro;
verifying_clear(self);
t = PyObject_GetAttr(OBJECT(self), str_registry);
if (t == NULL)
return NULL;
ro = PyObject_GetAttr(t, strro);
Py_DECREF(t);
if (ro == NULL)
return NULL;
t = PyObject_CallFunctionObjArgs(OBJECT(&PyTuple_Type), ro, NULL);
Py_DECREF(ro);
if (t == NULL)
return NULL;
ro = PyTuple_GetSlice(t, 1, PyTuple_GET_SIZE(t));
Py_DECREF(t);
if (ro == NULL)
return NULL;
self->_verify_generations = _generations_tuple(ro);
if (self->_verify_generations == NULL)
{
Py_DECREF(ro);
return NULL;
}
self->_verify_ro = ro;
Py_INCREF(Py_None);
return Py_None;
}