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


C++ PyErr_GivenExceptionMatches函数代码示例

本文整理汇总了C++中PyErr_GivenExceptionMatches函数的典型用法代码示例。如果您正苦于以下问题:C++ PyErr_GivenExceptionMatches函数的具体用法?C++ PyErr_GivenExceptionMatches怎么用?C++ PyErr_GivenExceptionMatches使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: matches

    inline bool matches( PyObject *exception ) const
    {
#if PYTHON_VERSION >= 300
        if ( PyTuple_Check( exception ))
        {
            Py_ssize_t length = PyTuple_Size( exception );

            for ( Py_ssize_t i = 0; i < length; i += 1 )
            {
                PyObject *element = PyTuple_GET_ITEM( exception, i );

                if (unlikely( !PyExceptionClass_Check( element ) ))
                {
                    PyErr_Format( PyExc_TypeError, "catching classes that do not inherit from BaseException is not allowed" );
                    throw PythonException();
                }
            }
        }
        else if (unlikely( !PyExceptionClass_Check( exception ) ))
        {
            PyErr_Format( PyExc_TypeError, "catching classes that do not inherit from BaseException is not allowed" );
            throw PythonException();
        }
#endif

        return
            PyErr_GivenExceptionMatches( this->exception_type, exception ) ||
            PyErr_GivenExceptionMatches( this->exception_value, exception );
    }
开发者ID:linkerlin,项目名称:Nuitka,代码行数:29,代码来源:exceptions.hpp

示例2: PyArray_IntpFromIndexSequence

/*
 * PyArray_IntpFromIndexSequence
 * Returns the number of dimensions or -1 if an error occurred.
 * vals must be large enough to hold maxvals.
 * Opposed to PyArray_IntpFromSequence it uses and returns npy_intp
 * for the number of values.
 */
NPY_NO_EXPORT npy_intp
PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals)
{
    Py_ssize_t nd;
    npy_intp i;
    PyObject *op, *err;

    /*
     * Check to see if sequence is a single integer first.
     * or, can be made into one
     */
    nd = PySequence_Length(seq);
    if (nd == -1) {
        if (PyErr_Occurred()) {
            PyErr_Clear();
        }

        vals[0] = PyArray_PyIntAsIntp(seq);
        if(vals[0] == -1) {
            err = PyErr_Occurred();
            if (err &&
                    PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) {
                PyErr_SetString(PyExc_ValueError,
                        "Maximum allowed dimension exceeded");
            }
            if(err != NULL) {
                return -1;
            }
        }
        nd = 1;
    }
    else {
        for (i = 0; i < PyArray_MIN(nd,maxvals); i++) {
            op = PySequence_GetItem(seq, i);
            if (op == NULL) {
                return -1;
            }

            vals[i] = PyArray_PyIntAsIntp(op);
            Py_DECREF(op);
            if(vals[i] == -1) {
                err = PyErr_Occurred();
                if (err &&
                        PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) {
                    PyErr_SetString(PyExc_ValueError,
                            "Maximum allowed dimension exceeded");
                }
                if(err != NULL) {
                    return -1;
                }
            }
        }
    }
    return nd;
}
开发者ID:alphaitis,项目名称:numpy,代码行数:62,代码来源:conversion_utils.c

示例3: rpcError_Extract

bool
rpcError_Extract(PyObject *error, int *errorCode, char **errorString)
{
	PyObject	*pyErrorCode,
			*pyErrorString;

	assert(PyErr_GivenExceptionMatches(error, rpcError));
	pyErrorCode = PyObject_GetAttrString(error, "errorCode");
	if (errorCode && PyInt_Check(pyErrorCode))
		*errorCode = (int)PyInt_AS_LONG(pyErrorCode);
	else {
		fprintf(rpcLogger, "invalid error code... deerror to -1\n");
		*errorCode = -1;
	}
	pyErrorString = PyObject_GetAttrString(error, "errorString");
	if (errorString && PyString_Check(pyErrorString)) {
		*errorString = alloc(PyString_GET_SIZE(pyErrorString) + 1);
		if (*errorString == NULL)
			return false;
		strcpy(*errorString, PyString_AS_STRING(pyErrorString));
	} else {
		fprintf(rpcLogger, "invalid error string... deerror to 'unknown error'\n");
		*errorString = alloc(strlen("unknown error") + 1);
		if (*errorString == NULL)
			return false;
		strcpy(*errorString, "unknown error");
	}
	return true;
}
开发者ID:Zemanta,项目名称:py-xmlrpc,代码行数:29,代码来源:rpcError.c

示例4: py_import

boost::python::object
EventIterator::next_nostop()
{
    boost::python::object stopIteration = py_import("exceptions").attr("StopIteration");
    boost::python::object result = boost::python::object();
    try
    {
        result = boost::python::object(next());
    }
    catch (const boost::python::error_already_set &)
    {
        PyObject *e, *v, *t;
        PyErr_Fetch(&e, &v, &t);
        if (!e) {throw;}
        if (PyErr_GivenExceptionMatches(stopIteration.ptr(), e))
        {
            boost::python::object pyE(boost::python::handle<>(boost::python::allow_null(e)));
            if (v) {boost::python::object pyV(boost::python::handle<>(boost::python::allow_null(v)));}
            if (t) {boost::python::object pyT(boost::python::handle<>(boost::python::allow_null(t)));}
        }
        else
        {
            PyErr_Restore(e, v, t);
            throw;
        }
    }
    return result;
}
开发者ID:epaulson,项目名称:htcondor,代码行数:28,代码来源:event.cpp

示例5: assert

PyObject *ERROR_GET_STOP_ITERATION_VALUE()
{
    assert ( PyErr_ExceptionMatches( PyExc_StopIteration ));

    PyObject *et, *ev, *tb;
    PyErr_Fetch( &et, &ev, &tb );

    Py_XDECREF(et);
    Py_XDECREF(tb);

    PyObject *value = NULL;

    if ( ev )
    {
        if ( PyErr_GivenExceptionMatches( ev, PyExc_StopIteration ) )
        {
            value = ((PyStopIterationObject *)ev)->value;
            Py_DECREF( ev );
        }
        else
        {
            value = ev;
        }
    }

    if ( value == NULL )
    {
        value = INCREASE_REFCOUNT( Py_None );
    }

    return value;
}
开发者ID:TheKK,项目名称:Nuitka,代码行数:32,代码来源:CompiledGeneratorType.cpp

示例6: assert

PyObject *ERROR_GET_STOP_ITERATION_VALUE()
{
    assert( PyErr_ExceptionMatches( PyExc_StopIteration ) );

    PyObject *exception_type, *exception_value, *exception_tb;
    PyErr_Fetch( &exception_type, &exception_value, &exception_tb );

    Py_DECREF( exception_type );
    Py_XDECREF( exception_tb );

    PyObject *value = NULL;

    if ( exception_value )
    {
        if ( PyErr_GivenExceptionMatches( exception_value, PyExc_StopIteration ) )
        {
            value = ((PyStopIterationObject *)exception_value)->value;
            Py_XINCREF( value );
            Py_DECREF( exception_value );
        }
        else
        {
            value = exception_value;
        }
    }

    if ( value == NULL )
    {
        value = INCREASE_REFCOUNT( Py_None );
    }

    return value;
}
开发者ID:jenshiller,项目名称:Nuitka,代码行数:33,代码来源:CompiledGeneratorType.cpp

示例7: pygi_gerror_exception_check

/**
 * pygi_gerror_exception_check:
 * @error: a standard GLib GError ** output parameter
 *
 * Checks to see if a GError exception has been raised, and if so
 * translates the python exception to a standard GLib GError.  If the
 * raised exception is not a GError then PyErr_Print() is called.
 *
 * Returns: 0 if no exception has been raised, -1 if it is a
 * valid glib.GError, -2 otherwise.
 */
gboolean
pygi_gerror_exception_check (GError **error)
{
    int res = -1;
    PyObject *type, *value, *traceback;
    PyErr_Fetch(&type, &value, &traceback);
    if (type == NULL)
        return 0;
    PyErr_NormalizeException(&type, &value, &traceback);
    if (value == NULL) {
        PyErr_Restore(type, value, traceback);
        PyErr_Print();
        return -2;
    }
    if (!value ||
        !PyErr_GivenExceptionMatches(type,
                                     (PyObject *) PyGError)) {
        PyErr_Restore(type, value, traceback);
        PyErr_Print();
        return -2;
    }
    Py_DECREF(type);
    Py_XDECREF(traceback);

    if (!pygi_error_marshal_from_py (value, error)) {
        PyErr_Print();
        res = -2;
    }

    Py_DECREF(value);
    return res;

}
开发者ID:RIFTIO,项目名称:pygobject,代码行数:44,代码来源:pygi-error.c

示例8: PyErr_GivenExceptionMatches

int
PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
{
    if (err == NULL || exc == NULL) {
        /* maybe caused by "import exceptions" that failed early on */
        return 0;
    }
    if (PyTuple_Check(exc)) {
        Py_ssize_t i, n;
        n = PyTuple_Size(exc);
        for (i = 0; i < n; i++) {
            /* Test recursively */
             if (PyErr_GivenExceptionMatches(
                 err, PyTuple_GET_ITEM(exc, i)))
             {
                 return 1;
             }
        }
        return 0;
    }
    /* err might be an instance, so check its class. */
    if (PyExceptionInstance_Check(err))
        err = PyExceptionInstance_Class(err);

    if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
        return PyType_IsSubtype((PyTypeObject *)err, (PyTypeObject *)exc);
    }

    return err == exc;
}
开发者ID:DinoV,项目名称:cpython,代码行数:30,代码来源:errors.c

示例9: EXCEPTION_MATCH_BOOL

// This is for the actual comparison operation that is being done in the
// node tree, no other code should use it. TODO: Then it's probably not
// properly located here, and it could still in-line the code of
// "PyErr_GivenExceptionMatches" to save on Python3 doing two tuple checks
// and iterations.
NUITKA_MAY_BE_UNUSED static inline int EXCEPTION_MATCH_BOOL( PyObject *exception_value, PyObject *exception_checked )
{
    CHECK_OBJECT( exception_value );
    CHECK_OBJECT( exception_checked );

#if PYTHON_VERSION >= 300
    if ( PyTuple_Check( exception_checked ))
    {
        Py_ssize_t length = PyTuple_Size( exception_checked );

        for ( Py_ssize_t i = 0; i < length; i += 1 )
        {
            PyObject *element = PyTuple_GET_ITEM( exception_checked, i );

            if (unlikely( !PyExceptionClass_Check( element ) ))
            {
                PyErr_Format( PyExc_TypeError, "catching classes that do not inherit from BaseException is not allowed" );
                return -1;
            }
        }
    }
    else if (unlikely( !PyExceptionClass_Check( exception_checked ) ))
    {
        PyErr_Format( PyExc_TypeError, "catching classes that do not inherit from BaseException is not allowed" );
        return -1;
    }
#endif

    return PyErr_GivenExceptionMatches( exception_value, exception_checked );
}
开发者ID:justus922,项目名称:Nuitka,代码行数:35,代码来源:exceptions.hpp

示例10: python_script_error_jump

void python_script_error_jump(const char *filepath, int *lineno, int *offset)
{
  PyObject *exception, *value;
  PyTracebackObject *tb;

  *lineno = -1;
  *offset = 0;

  PyErr_Fetch(&exception, &value, (PyObject **)&tb);

  if (exception && PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
    /* no traceback available when SyntaxError.
     * python has no api's to this. reference parse_syntax_error() from pythonrun.c */
    PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
    PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */

    if (value) { /* should always be true */
      PyObject *message;
      PyObject *filename_py, *text_py;

      if (parse_syntax_error(value, &message, &filename_py, lineno, offset, &text_py)) {
        const char *filename = _PyUnicode_AsString(filename_py);
        /* python adds a '/', prefix, so check for both */
        if ((BLI_path_cmp(filename, filepath) == 0) ||
            ((filename[0] == '\\' || filename[0] == '/') &&
             BLI_path_cmp(filename + 1, filepath) == 0)) {
          /* good */
        }
        else {
          *lineno = -1;
        }
      }
      else {
        *lineno = -1;
      }
    }
  }
  else {
    PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
    PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */
    PyErr_Print();

    for (tb = (PyTracebackObject *)PySys_GetObject("last_traceback");
         tb && (PyObject *)tb != Py_None;
         tb = tb->tb_next) {
      PyObject *coerce;
      const char *tb_filepath = traceback_filepath(tb, &coerce);
      const int match = ((BLI_path_cmp(tb_filepath, filepath) == 0) ||
                         ((tb_filepath[0] == '\\' || tb_filepath[0] == '/') &&
                          BLI_path_cmp(tb_filepath + 1, filepath) == 0));
      Py_DECREF(coerce);

      if (match) {
        *lineno = tb->tb_lineno;
        /* used to break here, but better find the inner most line */
      }
    }
  }
}
开发者ID:dfelinto,项目名称:blender,代码行数:59,代码来源:bpy_traceback.c

示例11: formatPythonException

std::string formatPythonException( bool withStacktrace, int *lineNumber )
{
	PyObject *exceptionPyObject, *valuePyObject, *tracebackPyObject;
	PyErr_Fetch( &exceptionPyObject, &valuePyObject, &tracebackPyObject );

	if( !exceptionPyObject )
	{
		throw IECore::Exception( "No Python exception set" );
	}

	PyErr_NormalizeException( &exceptionPyObject, &valuePyObject, &tracebackPyObject );

	object exception( ( handle<>( exceptionPyObject ) ) );

	// valuePyObject and tracebackPyObject may be NULL.
	object value;
	if( valuePyObject )
	{
		value = object( handle<>( valuePyObject ) );
	}

	object traceback;
	if( tracebackPyObject )
	{
		traceback = object( handle<>( tracebackPyObject ) );
	}

	if( lineNumber )
	{
		if( PyErr_GivenExceptionMatches( value.ptr(), PyExc_SyntaxError ) )
		{
			*lineNumber = extract<int>( value.attr( "lineno" ) );
		}
		else if( traceback )
		{
			*lineNumber = extract<int>( traceback.attr( "tb_lineno" ) );
		}
	}

	object tracebackModule( import( "traceback" ) );

	object formattedList;
	if( withStacktrace )
	{
		formattedList = tracebackModule.attr( "format_exception" )( exception, value, traceback );
	}
	else
	{
		formattedList = tracebackModule.attr( "format_exception_only" )( exception, value );
	}

	object formatted = str( "" ).join( formattedList );
	std::string s = extract<std::string>( formatted );

	return s;
}
开发者ID:boberfly,项目名称:gaffer,代码行数:56,代码来源:ExceptionAlgo.cpp

示例12: 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 PY_VERSION_HEX >= 0x02050000
        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;
        }
#endif
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Throw(yf, args);
        } else {
            PyObject *meth = PyObject_GetAttrString(yf, "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);
}
开发者ID:dhirschfeld,项目名称:cython,代码行数:56,代码来源:Generator.c

示例13: IsServerErrorCurrent

// Is the current exception a "server" exception? - ie, one explicitly
// thrown by Python code to indicate an error.  This is defined as
// any exception whose type is a subclass of com_error (a plain
// com_error probably means an unhandled exception from someone
// calling an interface)
BOOL IsServerErrorCurrent() {
	BOOL rc = FALSE;
	PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
	PyErr_Fetch( &exc_typ, &exc_val, &exc_tb);
	assert(exc_typ); // we should only be called with an exception current.
	if (exc_typ) {
		PyErr_NormalizeException( &exc_typ, &exc_val, &exc_tb);
		// so it must "match" a com_error, but not be *exactly* a COM error.
		rc = PyErr_GivenExceptionMatches(exc_val, PyWinExc_COMError) && exc_typ != PyWinExc_COMError;
	}
	PyErr_Restore(exc_typ, exc_val, exc_tb);
	return rc;
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:18,代码来源:ErrorUtils.cpp

示例14: PyErr_Fetch

QString PythonScripting::errorMsg()
{
  PyObject *exception=0, *value=0, *traceback=0;
  PyTracebackObject *excit=0;
  PyFrameObject *frame;
  char *fname;
  QString msg;
  if (!PyErr_Occurred()) return "";

  PyErr_Fetch(&exception, &value, &traceback);
  PyErr_NormalizeException(&exception, &value, &traceback);
  if(PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError))
  {
    msg.append(toString(PyObject_GetAttrString(value, "text"), true) + "\n");
    PyObject *offset = PyObject_GetAttrString(value, "offset");
    for (int i=1; i<PyInt_AsLong(offset); i++)
      msg.append(" ");
    msg.append("^\n");
    Py_DECREF(offset);
    msg.append("SyntaxError: ");
    msg.append(toString(PyObject_GetAttrString(value, "msg"), true) + "\n");
    msg.append("at ").append(toString(PyObject_GetAttrString(value, "filename"), true));
    msg.append(":").append(toString(PyObject_GetAttrString(value, "lineno"), true));
    msg.append("\n");
    Py_DECREF(exception);
    Py_DECREF(value);
  } else {
    msg.append(toString(exception,true)).remove("exceptions.").append(": ");
    msg.append(toString(value,true));
    msg.append("\n");
  }

  if (traceback) {
    excit = (PyTracebackObject*)traceback;
    while (excit && (PyObject*)excit != Py_None)
    {
      frame = excit->tb_frame;
      msg.append("at ").append(PyString_AsString(frame->f_code->co_filename));
      msg.append(":").append(QString::number(excit->tb_lineno));
      if (frame->f_code->co_name && *(fname = PyString_AsString(frame->f_code->co_name)) != '?')
	msg.append(" in ").append(fname);
      msg.append("\n");
      excit = excit->tb_next;
    }
    Py_DECREF(traceback);
  }

  return msg;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:49,代码来源:PythonScripting.cpp

示例15: python_script_error_jump

void python_script_error_jump(const char *filepath, int *lineno, int *offset)
{
	PyObject *exception, *value;
	PyTracebackObject *tb;

	*lineno= -1;
	*offset= 0;

	PyErr_Fetch(&exception, &value, (PyObject **)&tb);

	if(exception && PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
		/* no traceback available when SyntaxError.
		 * python has no api's to this. reference parse_syntax_error() from pythonrun.c */
		PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
		PyErr_Restore(exception, value, (PyObject *)tb);	/* takes away reference! */

		if(value) { /* should always be true */
			PyObject *message;
			const char *filename, *text;

			if(parse_syntax_error(value, &message, &filename, lineno, offset, &text)) {
				/* python adds a '/', prefix, so check for both */
				if(	(strcmp(filename, filepath) == 0) || 
					((filename[0] == '\\' || filename[0] == '/') && strcmp(filename + 1, filepath) == 0)
				) {
					/* good */
				}
				else {
					*lineno= -1;
				}
			}
			else {
				*lineno= -1;
			}
		}
	}
	else {
		PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
		PyErr_Restore(exception, value, (PyObject *)tb);	/* takes away reference! */
		PyErr_Print();

		for(tb= (PyTracebackObject *)PySys_GetObject("last_traceback"); tb && (PyObject *)tb != Py_None; tb= tb->tb_next) {
			if(strcmp(traceback_filepath(tb), filepath) != 0) {
				*lineno= tb->tb_lineno;
				break;
			}
		}
	}
}
开发者ID:OldBrunet,项目名称:BGERTPS,代码行数:49,代码来源:bpy_traceback.c


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