本文整理汇总了C++中PyObject_Repr函数的典型用法代码示例。如果您正苦于以下问题:C++ PyObject_Repr函数的具体用法?C++ PyObject_Repr怎么用?C++ PyObject_Repr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyObject_Repr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Snmp_repr
static PyObject*
Snmp_repr(SnmpObject *self)
{
PyObject *peer = NULL, *community = NULL, *rpeer = NULL,
*rcommunity = NULL, *result;
if ((peer = PyString_FromString(self->ss->peername)) == NULL)
return NULL;
if ((community = PyString_FromString((char*)self->ss->community)) == NULL)
goto reprerror;
if ((rpeer = PyObject_Repr(peer)) == NULL)
goto reprerror;
if ((rcommunity = PyObject_Repr(community)) == NULL)
goto reprerror;
result = PyString_FromFormat("%s(host=%s, community=%s, version=%d)",
self->ob_type->tp_name,
PyString_AsString(rpeer),
PyString_AsString(rcommunity),
(self->ss->version == SNMP_VERSION_1)?1:2);
Py_DECREF(rpeer);
Py_DECREF(peer);
Py_DECREF(rcommunity);
Py_DECREF(community);
return result;
reprerror:
Py_XDECREF(rpeer);
Py_XDECREF(peer);
Py_XDECREF(rcommunity);
Py_XDECREF(community);
return NULL;
}
示例2: igraphmodule_Edge_repr
/** \ingroup python_interface_edge
* \brief Formats an \c igraph.Edge object as a string
*
* \return the formatted textual representation as a \c PyObject
*/
PyObject* igraphmodule_Edge_repr(igraphmodule_EdgeObject *self) {
PyObject *s;
PyObject *attrs;
#ifndef IGRAPH_PYTHON3
PyObject *grepr, *drepr;
#endif
attrs = igraphmodule_Edge_attributes(self);
if (attrs == 0)
return NULL;
#ifdef IGRAPH_PYTHON3
s = PyUnicode_FromFormat("igraph.Edge(%R, %ld, %R)",
(PyObject*)self->gref, (long int)self->idx, attrs);
Py_DECREF(attrs);
#else
grepr=PyObject_Repr((PyObject*)self->gref);
drepr=PyObject_Repr(attrs);
Py_DECREF(attrs);
if (!grepr || !drepr) {
Py_XDECREF(grepr);
Py_XDECREF(drepr);
return NULL;
}
s=PyString_FromFormat("igraph.Edge(%s, %ld, %s)", PyString_AsString(grepr),
(long int)self->idx, PyString_AsString(drepr));
Py_DECREF(grepr);
Py_DECREF(drepr);
#endif
return s;
}
示例3: html_State_repr
static PyObject *
html_State_repr(html_State *self) {
PyObject *bold = NULL, *italic = NULL, *lang = NULL, *ans = NULL;
bold = PyObject_Repr(self->is_bold); italic = PyObject_Repr(self->is_italic); lang = PyObject_Repr(self->current_lang);
if (bold && italic && lang)
ans = PyString_FromFormat("State(bold=%s, italic=%s, lang=%s)", PyString_AS_STRING(bold), PyString_AS_STRING(italic), PyString_AS_STRING(lang));
Py_XDECREF(bold); Py_XDECREF(italic); Py_XDECREF(lang);
return ans;
}
示例4: html_Tag_repr
static PyObject *
html_Tag_repr(html_Tag *self) {
PyObject *name = NULL, *bold = NULL, *italic = NULL, *lang = NULL, *ans = NULL;
name = PyObject_Repr(self->name); bold = PyObject_Repr(self->bold); italic = PyObject_Repr(self->italic); lang = PyObject_Repr(self->lang);
if (name && bold && italic && lang)
ans = PyString_FromFormat("Tag(%s, bold=%s, italic=%s, lang=%s)", PyString_AS_STRING(name), PyString_AS_STRING(bold), PyString_AS_STRING(italic), PyString_AS_STRING(lang));
Py_XDECREF(name); Py_XDECREF(bold); Py_XDECREF(italic); Py_XDECREF(lang);
return ans;
}
示例5: PyList_New
static PyObject *pair_repr(PyObject *self) {
PyObject *tmp = NULL;
PyObject *col = PyList_New(0);
PyObject *found = PyDict_New();
size_t index = 0;
PyObject *rest = self;
PyObject *rest_id;
PyList_Append(col, _str_cons_paren);
while (rest->ob_type == &SibPairType) {
rest_id = PyLong_FromVoidPtr(rest);
if (PyDict_Contains(found, rest_id)) {
/* recursive pair detected */
PyList_Append(col, _str_recursive_true);
if (rest != self) {
tmp = PyDict_GetItem(found, rest_id);
PyList_Insert(col, PyLong_AsSize_t(tmp) - 1, _str_cons_paren);
PyList_Append(col, _str_close_paren);
}
Py_DECREF(rest_id);
rest = NULL;
break;
} else {
index += 2;
tmp = PyLong_FromSize_t(index);
PyDict_SetItem(found, rest_id, tmp);
Py_DECREF(tmp);
tmp = PyObject_Repr(SibPair_CAR(rest));
PyList_Append(col, tmp);
PyList_Append(col, _str_comma_space);
Py_DECREF(tmp);
rest = SibPair_CDR(rest);
Py_DECREF(rest_id);
}
}
if (rest) {
PyList_Append(col, PyObject_Repr(rest));
}
PyList_Append(col, _str_close_paren);
tmp = PyUnicode_Join(_str_empty, col);
Py_DECREF(col);
Py_DECREF(found);
return tmp;
}
示例6: contextvar_tp_repr
static PyObject *
contextvar_tp_repr(PyContextVar *self)
{
_PyUnicodeWriter writer;
_PyUnicodeWriter_Init(&writer);
if (_PyUnicodeWriter_WriteASCIIString(
&writer, "<ContextVar name=", 17) < 0)
{
goto error;
}
PyObject *name = PyObject_Repr(self->var_name);
if (name == NULL) {
goto error;
}
if (_PyUnicodeWriter_WriteStr(&writer, name) < 0) {
Py_DECREF(name);
goto error;
}
Py_DECREF(name);
if (self->var_default != NULL) {
if (_PyUnicodeWriter_WriteASCIIString(&writer, " default=", 9) < 0) {
goto error;
}
PyObject *def = PyObject_Repr(self->var_default);
if (def == NULL) {
goto error;
}
if (_PyUnicodeWriter_WriteStr(&writer, def) < 0) {
Py_DECREF(def);
goto error;
}
Py_DECREF(def);
}
PyObject *addr = PyUnicode_FromFormat(" at %p>", self);
if (addr == NULL) {
goto error;
}
if (_PyUnicodeWriter_WriteStr(&writer, addr) < 0) {
Py_DECREF(addr);
goto error;
}
Py_DECREF(addr);
return _PyUnicodeWriter_Finish(&writer);
error:
_PyUnicodeWriter_Dealloc(&writer);
return NULL;
}
示例7: PLyObject_AsString
/*
* Convert Python object to C string in server encoding.
*/
char *
PLyObject_AsString(PyObject *plrv)
{
PyObject *plrv_bo;
char *plrv_sc;
size_t plen;
size_t slen;
if (PyUnicode_Check(plrv))
plrv_bo = PLyUnicode_Bytes(plrv);
else if (PyFloat_Check(plrv))
{
/* use repr() for floats, str() is lossy */
#if PY_MAJOR_VERSION >= 3
PyObject *s = PyObject_Repr(plrv);
plrv_bo = PLyUnicode_Bytes(s);
Py_XDECREF(s);
#else
plrv_bo = PyObject_Repr(plrv);
#endif
}
else
{
#if PY_MAJOR_VERSION >= 3
PyObject *s = PyObject_Str(plrv);
plrv_bo = PLyUnicode_Bytes(s);
Py_XDECREF(s);
#else
plrv_bo = PyObject_Str(plrv);
#endif
}
if (!plrv_bo)
PLy_elog(ERROR, "could not create string representation of Python object");
plrv_sc = pstrdup(PyBytes_AsString(plrv_bo));
plen = PyBytes_Size(plrv_bo);
slen = strlen(plrv_sc);
Py_XDECREF(plrv_bo);
if (slen < plen)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("could not convert Python object into cstring: Python string representation appears to contain null bytes")));
else if (slen > plen)
elog(ERROR, "could not convert Python object into cstring: Python string longer than reported length");
pg_verifymbstr(plrv_sc, slen, false);
return plrv_sc;
}
示例8: pystring_concat_repr
void
pystring_concat_repr(PyObject **pystr, PyObject *obj)
{
#if PY_MAJOR_VERSION >= 3
PyObject *repr = PyObject_Repr(obj);
PyObject *newstr = PyUnicode_Concat(*pystr, repr);
Py_DECREF(repr);
Py_DECREF(*pystr);
*pystr = newstr;
#else
PyString_ConcatAndDel(pystr, PyObject_Repr(obj));
#endif
}
示例9: print_dict
void print_dict(PyObject *dict)
{
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &key, &value)) {
PyObject* k_str_exc_type = PyObject_Repr(key);
PyObject* k_pyStr = PyUnicode_AsEncodedString(k_str_exc_type, "utf-8", "Error ~");
printf("key:%s ---> ", (const char *)PyBytes_AS_STRING(k_pyStr));
PyObject* v_str_exc_type = PyObject_Repr(value);
PyObject* v_pyStr = PyUnicode_AsEncodedString(v_str_exc_type, "utf-8", "Error ~");
printf("value:%s\n", PyBytes_AsString(v_pyStr));
}
}
示例10: PyUnicode_FromString
static PyObject *slot_QSizeF___repr__(PyObject *sipSelf)
{
QSizeF *sipCpp = reinterpret_cast<QSizeF *>(sipGetCppPtr((sipSimpleWrapper *)sipSelf,sipType_QSizeF));
if (!sipCpp)
return 0;
{
{
PyObject * sipRes = 0;
#line 116 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\sip/QtCore/qsize.sip"
if (sipCpp->isNull())
{
#if PY_MAJOR_VERSION >= 3
sipRes = PyUnicode_FromString("PyQt5.QtCore.QSizeF()");
#else
sipRes = PyString_FromString("PyQt5.QtCore.QSizeF()");
#endif
}
else
{
PyObject *w = PyFloat_FromDouble(sipCpp->width());
PyObject *h = PyFloat_FromDouble(sipCpp->height());
if (w && h)
{
#if PY_MAJOR_VERSION >= 3
sipRes = PyUnicode_FromFormat("PyQt5.QtCore.QSizeF(%R, %R)", w, h);
#else
sipRes = PyString_FromString("PyQt5.QtCore.QSizeF(");
PyString_ConcatAndDel(&sipRes, PyObject_Repr(w));
PyString_ConcatAndDel(&sipRes, PyString_FromString(", "));
PyString_ConcatAndDel(&sipRes, PyObject_Repr(h));
PyString_ConcatAndDel(&sipRes, PyString_FromString(")"));
#endif
}
Py_XDECREF(w);
Py_XDECREF(h);
}
#line 872 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\QtCore/sipQtCoreQSizeF.cpp"
return sipRes;
}
}
return 0;
}
示例11: rpObjectectGetName
/*
Returns the name of the Python object which this instance wraps.
If it cannot determine a reasonable name it just gives up.
*/
static
VALUE rpObjectectGetName(VALUE self)
{
//It only makes sense to query a python object if the interpreter is running.
if(Py_IsInitialized())
{
PyObject *pObject,*pName,*pRepr;
VALUE rName;
pObject = rpObjectGetPyObject(self);
pName = PyObject_GetAttrString(pObject,"__name__");
if(!pName)
{
PyErr_Clear();
pName = PyObject_GetAttrString(pObject,"__class__");
pRepr = PyObject_Repr(pName);
rName = ptorString(pRepr);
Py_XDECREF(pRepr);
return rb_str_concat(rb_str_new2("An instance of "), rName);
if(!pName)
{
PyErr_Clear();
pName = PyObject_Repr(pObject);
if(!pName)
{
PyErr_Clear();
return rb_str_new2("__Unnameable__");
}
}
}
rName = ptorString(pName);
Py_XDECREF(pName);
return rName;
}
return rb_str_new2("__FREED__");
}
示例12: PyFloat_FromDouble
static PyObject *slot_QQuaternion___repr__(PyObject *sipSelf)
{
QQuaternion *sipCpp = reinterpret_cast<QQuaternion *>(sipGetCppPtr((sipSimpleWrapper *)sipSelf,sipType_QQuaternion));
if (!sipCpp)
return 0;
{
{
PyObject * sipRes = 0;
#line 45 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\sip/QtGui/qquaternion.sip"
PyObject *scalar = PyFloat_FromDouble(sipCpp->scalar());
PyObject *x = PyFloat_FromDouble(sipCpp->x());
PyObject *y = PyFloat_FromDouble(sipCpp->y());
PyObject *z = PyFloat_FromDouble(sipCpp->z());
if (scalar && x && y && z)
{
#if PY_MAJOR_VERSION >= 3
sipRes = PyUnicode_FromFormat("PyQt5.QtGui.QQuaternion(%R, %R, %R, %R)",
scalar, x, y, z);
#else
sipRes = PyString_FromString("PyQt5.QtGui.QQuaternion(");
PyString_ConcatAndDel(&sipRes, PyObject_Repr(scalar));
PyString_ConcatAndDel(&sipRes, PyString_FromString(", "));
PyString_ConcatAndDel(&sipRes, PyObject_Repr(x));
PyString_ConcatAndDel(&sipRes, PyString_FromString(", "));
PyString_ConcatAndDel(&sipRes, PyObject_Repr(y));
PyString_ConcatAndDel(&sipRes, PyString_FromString(", "));
PyString_ConcatAndDel(&sipRes, PyObject_Repr(z));
PyString_ConcatAndDel(&sipRes, PyString_FromString(")"));
#endif
}
Py_XDECREF(scalar);
Py_XDECREF(x);
Py_XDECREF(y);
Py_XDECREF(z);
#line 1111 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\QtGui/sipQtGuiQQuaternion.cpp"
return sipRes;
}
}
return 0;
}
示例13: ax25_address_repr
static PyObject *
ax25_address_repr(ax25_address_object* self)
{
PyObject *b, *r, *f;
b = PyBytes_FromStringAndSize(self->field.ax25_call, 7);
if (b == NULL)
return NULL;
r = PyObject_Repr(b);
if (r == NULL) {
Py_DECREF(b);
return NULL;
}
f = PyUnicode_FromFormat("<ax25_address %U>", r);
if (f == NULL) {
Py_DECREF(r);
Py_DECREF(b);
return NULL;
}
Py_DECREF(r);
Py_DECREF(b);
return f;
}
示例14: PyObject_Repr
void OutputHook::call(std::string name, boost::python::object obj)
{
Hooks::checkName(name);
auto repr_ = PyObject_Repr(obj.ptr());
if (PyErr_Occurred())
{
PyErr_Clear();
throw Hooks::Exception("Failed to get __repr__ of argument");
}
auto repr = std::string(PyUnicode_AsUTF8(repr_));
Py_DECREF(repr_);
PyObject* g = Py_BuildValue(
"{sO}", "__builtins__", PyEval_GetBuiltins());
node->parent->loadDatumHooks(g);
auto out = PyRun_String(repr.c_str(), Py_eval_input, g, g);
Py_DECREF(g);
Py_XDECREF(out);
if (PyErr_Occurred())
{
PyErr_Clear();
throw Hooks::Exception("Could not evaluate __repr__ of output");
}
const bool result = node->makeDatum(
name, obj.ptr()->ob_type, Datum::SIGIL_OUTPUT + repr, true);
if (!result)
throw Hooks::Exception("Datum was already defined in this script.");
}
示例15: castToPyObject
configParserStruct::pythonParser::containerForVariables configParserStruct::pythonParser::listOfVariables( void *Object )
{
containerForVariables Result;
if ( Object == NULL )
return Result;
PyObject *Dict = castToPyObject(Object);
if ( ! PyDict_Check( Dict ) )
return Result;
PyObject *KeysList = PyDict_Keys( Dict );
Py_ssize_t KeysListSize = PyList_Size( KeysList );
for ( ptrdiff_t Index = 0; Index < static_cast<ptrdiff_t>(KeysListSize); Index++ )
{
PyObject *Key = PyList_GetItem( KeysList, Index );
PyObject *KeyRepr = PyObject_Repr( Key );
std::string KeyString = dequoteString( PyString_AsString( KeyRepr ), "'" );
PyObject *Item = PyDict_GetItem( Dict, Key );
if ( PyDict_Check(Item) )
{
containerForVariables ListOfItemsinSubDict = listOfVariables( Item );
for ( containerForVariables::const_iterator i = ListOfItemsinSubDict.begin(); i != ListOfItemsinSubDict.end(); ++i )
Result.insert( KeyString + structSeparator() + *i );
} else {
Result.insert( KeyString );
}
}
return Result;
}