当前位置: 首页>>代码示例>>C++>>正文


C++ PyObjectHandle::get方法代码示例

本文整理汇总了C++中PyObjectHandle::get方法的典型用法代码示例。如果您正苦于以下问题:C++ PyObjectHandle::get方法的具体用法?C++ PyObjectHandle::get怎么用?C++ PyObjectHandle::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyObjectHandle的用法示例。


在下文中一共展示了PyObjectHandle::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getAttr

void
IcePy::handleSystemExit(PyObject* ex)
{
    //
    // This code is similar to handle_system_exit in pythonrun.c.
    //
    PyObjectHandle code;
    if(PyExceptionInstance_Check(ex))
    {
        code = getAttr(ex, "code", true);
    }
    else
    {
        code = ex;
        Py_INCREF(ex);
    }

    int status;
    if(PyLong_Check(code.get()))
    {
        status = static_cast<int>(PyLong_AsLong(code.get()));
    }
    else
    {
        PyObject_Print(code.get(), stderr, Py_PRINT_RAW);
        PySys_WriteStderr(STRCAST("\n"));
        status = 1;
    }

    code = 0;
    Py_Exit(status);
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:32,代码来源:Util.cpp

示例2: lookupType

static PyObject*
communicatorFlushBatchRequests(CommunicatorObject* self, PyObject* args)
{
    PyObject* compressBatchType = lookupType("Ice.CompressBatch");
    PyObject* compressBatch;
    if(!PyArg_ParseTuple(args, STRCAST("O!"), compressBatchType, &compressBatch))
    {
        return 0;
    }

    PyObjectHandle v = getAttr(compressBatch, "_value", false);
    assert(v.get());
    Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(PyLong_AsLong(v.get()));

    assert(self->communicator);
    try
    {
        AllowThreads allowThreads; // Release Python's global interpreter lock to avoid a potential deadlock.
        (*self->communicator)->flushBatchRequests(cb);
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return 0;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:29,代码来源:Communicator.cpp

示例3: AbortMarshaling

Ice::ValuePtr
IcePy::FactoryWrapper::create(const string& id)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    //
    // Get the type information.
    //
    ValueInfoPtr info = getValueInfo(id);

    if(!info)
    {
        return 0;
    }

    PyObjectHandle obj = PyObject_CallFunction(_valueFactory, STRCAST("s"), id.c_str());

    if(!obj.get())
    {
        assert(PyErr_Occurred());
        throw AbortMarshaling();
    }

    if(obj.get() == Py_None)
    {
        return 0;
    }

    return new ObjectReader(obj.get(), info);
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:30,代码来源:ValueFactoryManager.cpp

示例4: assert

static PyObject*
adapterGetPublishedEndpoints(ObjectAdapterObject* self)
{
    assert(self->adapter);
        
    Ice::EndpointSeq endpoints;
    try
    { 
        endpoints = (*self->adapter)->getPublishedEndpoints();
    } 
    catch(const Ice::Exception& ex)
    { 
        setPythonException(ex);
        return 0;
    }

    int count = static_cast<int>(endpoints.size());
    PyObjectHandle result = PyTuple_New(count);
    int i = 0;
    for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p, ++i)
    {
        PyObjectHandle endp = createEndpoint(*p);
        if(!endp.get())
        {
            return 0;
        }
        PyTuple_SET_ITEM(result.get(), i, endp.release()); // PyTuple_SET_ITEM steals a reference.
    }

    return result.release();
}
开发者ID:BlackHoleJet,项目名称:ice,代码行数:31,代码来源:ObjectAdapter.cpp

示例5: convertException

void
IcePy::setPythonException(const Ice::Exception& ex)
{
    PyObjectHandle p = convertException(ex);
    if(p.get())
    {
        setPythonException(p.get());
    }
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:9,代码来源:Util.cpp

示例6: callMethod

PyObject*
IcePy::callMethod(PyObject* obj, const string& name, PyObject* arg1, PyObject* arg2)
{
    PyObjectHandle method = PyObject_GetAttrString(obj, const_cast<char*>(name.c_str()));
    if(!method.get())
    {
        return 0;
    }
    return callMethod(method.get(), arg1, arg2);
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:10,代码来源:Util.cpp

示例7: getString

string
IcePy::LoggerWrapper::getPrefix()
{
    AdoptThread adoptThread;

    PyObjectHandle tmp = PyObject_CallMethod(_logger.get(), STRCAST("getPrefix"), 0);
    if(!tmp.get())
    {
        throwPythonException();
    }
    return getString(tmp.get());
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:12,代码来源:Logger.cpp

示例8: getObjectAdapter

Ice::ObjectAdapterPtr
IcePy::unwrapObjectAdapter(PyObject* obj)
{
#ifndef NDEBUG
    PyObject* wrapperType = lookupType("Ice.ObjectAdapterI");
#endif
    assert(wrapperType);
    assert(PyObject_IsInstance(obj, wrapperType));
    PyObjectHandle impl = PyObject_GetAttrString(obj, STRCAST("_impl"));
    assert(impl.get());
    return getObjectAdapter(impl.get());
}
开发者ID:BlackHoleJet,项目名称:ice,代码行数:12,代码来源:ObjectAdapter.cpp

示例9: assert

static PyObject*
communicatorFindAllAdminFacets(CommunicatorObject* self)
{
    assert(self->communicator);
    Ice::FacetMap facetMap;
    try
    {
        facetMap = (*self->communicator)->findAllAdminFacets();
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return 0;
    }

    PyObjectHandle result = PyDict_New();
    if(!result.get())
    {
        return 0;
    }

    PyTypeObject* objectType = reinterpret_cast<PyTypeObject*>(lookupType("Ice.Object"));
    PyObjectHandle plainObject = objectType->tp_alloc(objectType, 0);


    for(Ice::FacetMap::const_iterator p = facetMap.begin(); p != facetMap.end(); ++p)
    {

        PyObjectHandle obj = plainObject;

        ServantWrapperPtr wrapper = ServantWrapperPtr::dynamicCast(p->second);
        if(wrapper)
        {
            obj = wrapper->getObject();
        }
        else
        {
            Ice::NativePropertiesAdminPtr props = Ice::NativePropertiesAdminPtr::dynamicCast(p->second);
            if(props)
            {
                obj = createNativePropertiesAdmin(props);
            }
        }

        if(PyDict_SetItemString(result.get(), const_cast<char*>(p->first.c_str()), obj.get()) < 0)
        {
            return 0;
        }
    }

    return result.release();
}
开发者ID:chenbk85,项目名称:ice,代码行数:52,代码来源:Communicator.cpp

示例10: getString

string
IcePy::getFunction()
{
    //
    // Get name of current function.
    //
    PyFrameObject *f = PyThreadState_GET()->frame;
    PyObjectHandle code = getAttr(reinterpret_cast<PyObject*>(f), "f_code", false);
    assert(code.get());
    PyObjectHandle func = getAttr(code.get(), "co_name", false);
    assert(func.get());
    return getString(func.get());
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:13,代码来源:Util.cpp

示例11: LoggerWrapper

Ice::LoggerPtr
IcePy::LoggerWrapper::cloneWithPrefix(const string& prefix)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    PyObjectHandle tmp = PyObject_CallMethod(_logger.get(), STRCAST("cloneWithPrefix"), STRCAST("s"), prefix.c_str());
    if(!tmp.get())
    {
        throwPythonException();
    }

    return new LoggerWrapper(tmp.get());
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:13,代码来源:Logger.cpp

示例12: string

string
IcePy::PyException::getTraceback()
{
    if(!_tb.get())
    {
        return string();
    }

    //
    // We need the equivalent of the following Python code:
    //
    // import traceback
    // list = traceback.format_exception(type, ex, tb)
    //
    PyObjectHandle str = createString("traceback");
    PyObjectHandle mod = PyImport_Import(str.get());
    assert(mod.get()); // Unable to import traceback module - Python installation error?
    PyObject* func = PyDict_GetItemString(PyModule_GetDict(mod.get()), "format_exception");
    assert(func); // traceback.format_exception must be present.
    PyObjectHandle args = Py_BuildValue("(OOO)", _type.get(), ex.get(), _tb.get());
    assert(args.get());
    PyObjectHandle list = PyObject_CallObject(func, args.get());
    assert(list.get());

    string result;
    for(Py_ssize_t i = 0; i < PyList_GET_SIZE(list.get()); ++i)
    {
        string s = getString(PyList_GetItem(list.get(), i));
        result += s;
    }

    return result;
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:33,代码来源:Util.cpp

示例13: getProxy

static PyObject*
communicatorProxyToProperty(CommunicatorObject* self, PyObject* args)
{
    //
    // We don't want to accept None here, so we can specify ProxyType and force
    // the caller to supply a proxy object.
    //
    PyObject* proxyObj;
    PyObject* strObj;
    if(!PyArg_ParseTuple(args, STRCAST("O!O"), &ProxyType, &proxyObj, &strObj))
    {
        return 0;
    }

    Ice::ObjectPrx proxy = getProxy(proxyObj);
    string str;
    if(!getStringArg(strObj, "property", str))
    {
        return 0;
    }

    assert(self->communicator);
    Ice::PropertyDict dict;
    try
    {
        dict = (*self->communicator)->proxyToProperty(proxy, str);
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return 0;
    }

    PyObjectHandle result = PyDict_New();
    if(result.get())
    {
        for(Ice::PropertyDict::iterator p = dict.begin(); p != dict.end(); ++p)
        {
            PyObjectHandle key = createString(p->first);
            PyObjectHandle val = createString(p->second);
            if(!val.get() || PyDict_SetItem(result.get(), key.get(), val.get()) < 0)
            {
                return 0;
            }
        }
    }

    return result.release();
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:49,代码来源:Communicator.cpp

示例14: ExceptionWriter

void
IcePy::ServantLocatorWrapper::finished(const Ice::Current& current, const Ice::ObjectPtr&,
                                       const Ice::LocalObjectPtr& cookie)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    CookiePtr c = CookiePtr::dynamicCast(cookie);
    assert(c);

    ServantWrapperPtr wrapper = ServantWrapperPtr::dynamicCast(c->servant);
    PyObjectHandle servantObj = wrapper->getObject();

    PyObjectHandle res = PyObject_CallMethod(_locator, STRCAST("finished"), STRCAST("OOO"), c->current,
                                             servantObj.get(), c->cookie);
    if(PyErr_Occurred())
    {
        PyException ex; // Retrieve the exception before another Python API call clears it.

        //
        // A locator that calls sys.exit() will raise the SystemExit exception.
        // This is normally caught by the interpreter, causing it to exit.
        // However, we have no way to pass this exception to the interpreter,
        // so we act on it directly.
        //
        ex.checkSystemExit();

        PyObject* userExceptionType = lookupType("Ice.UserException");
        if(PyObject_IsInstance(ex.ex.get(), userExceptionType))
        {
            throw ExceptionWriter(ex.ex);
        }

        ex.raise();
    }
}
开发者ID:BlackHoleJet,项目名称:ice,代码行数:35,代码来源:ObjectAdapter.cpp

示例15: invoke

    void invoke(const Ice::ConnectionPtr& con)
    {
        AdoptThread adoptThread; // Ensure the current thread is able to call into Python.
#ifndef NDEBUG
        ConnectionObject* c = reinterpret_cast<ConnectionObject*>(_con);
        assert(con == *(c->connection));
#endif

        PyObjectHandle args = Py_BuildValue(STRCAST("(O)"), _con);
        assert(_cb);
        PyObjectHandle tmp = PyObject_Call(_cb, args.get(), 0);
        if(PyErr_Occurred())
        {
            PyException ex; // Retrieve it before another Python API call clears it.

            //
            // A callback that calls sys.exit() will raise the SystemExit exception.
            // This is normally caught by the interpreter, causing it to exit.
            // However, we have no way to pass this exception to the interpreter,
            // so we act on it directly.
            //
            ex.checkSystemExit();

            ex.raise();
        }
    }
开发者ID:chenbk85,项目名称:ice,代码行数:26,代码来源:Connection.cpp


注:本文中的PyObjectHandle::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。