本文整理汇总了C++中PyUnicode_InternFromString函数的典型用法代码示例。如果您正苦于以下问题:C++ PyUnicode_InternFromString函数的具体用法?C++ PyUnicode_InternFromString怎么用?C++ PyUnicode_InternFromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyUnicode_InternFromString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: create_filter
static PyObject *
create_filter(PyObject *category, const char *action)
{
static PyObject *ignore_str = NULL;
static PyObject *error_str = NULL;
static PyObject *default_str = NULL;
static PyObject *always_str = NULL;
PyObject *action_obj = NULL;
PyObject *lineno, *result;
if (!strcmp(action, "ignore")) {
if (ignore_str == NULL) {
ignore_str = PyUnicode_InternFromString("ignore");
if (ignore_str == NULL)
return NULL;
}
action_obj = ignore_str;
}
else if (!strcmp(action, "error")) {
if (error_str == NULL) {
error_str = PyUnicode_InternFromString("error");
if (error_str == NULL)
return NULL;
}
action_obj = error_str;
}
else if (!strcmp(action, "default")) {
if (default_str == NULL) {
default_str = PyUnicode_InternFromString("default");
if (default_str == NULL)
return NULL;
}
action_obj = default_str;
}
else if (!strcmp(action, "always")) {
if (always_str == NULL) {
always_str = PyUnicode_InternFromString("always");
if (always_str == NULL)
return NULL;
}
action_obj = always_str;
}
else {
Py_FatalError("unknown action");
}
/* This assumes the line number is zero for now. */
lineno = PyLong_FromLong(0);
if (lineno == NULL)
return NULL;
result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno);
Py_DECREF(lineno);
return result;
}
开发者ID:PiJoules,项目名称:cpython-modified,代码行数:54,代码来源:_warnings.c
示例2: bool_repr
static PyObject *
bool_repr(PyObject *self)
{
PyObject *s;
if (self == Py_True)
s = true_str ? true_str :
(true_str = PyUnicode_InternFromString("True"));
else
s = false_str ? false_str :
(false_str = PyUnicode_InternFromString("False"));
Py_XINCREF(s);
return s;
}
开发者ID:1st1,项目名称:cpython,代码行数:14,代码来源:boolobject.c
示例3: math_trunc
static PyObject *
math_trunc(PyObject *self, PyObject *number)
{
static PyObject *trunc_str = NULL;
PyObject *trunc;
if (Py_TYPE(number)->tp_dict == NULL) {
if (PyType_Ready(Py_TYPE(number)) < 0)
return NULL;
}
if (trunc_str == NULL) {
trunc_str = PyUnicode_InternFromString("__trunc__");
if (trunc_str == NULL)
return NULL;
}
trunc = _PyType_Lookup(Py_TYPE(number), trunc_str);
if (trunc == NULL) {
PyErr_Format(PyExc_TypeError,
"type %.100s doesn't define __trunc__ method",
Py_TYPE(number)->tp_name);
return NULL;
}
return PyObject_CallFunctionObjArgs(trunc, number, NULL);
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:26,代码来源:mathmodule.c
示例4: PyDescr_NewAdaMethod
PyObject *
PyDescr_NewAdaMethod(PyTypeObject *type, PyObject* cfunc, const char* name)
{
if (!adamethod_descr_initialized) {
adamethod_descr_initialized = 1;
memcpy (&PyAdaMethodDescr_Type, &PyMethodDescr_Type, sizeof (PyTypeObject));
PyAdaMethodDescr_Type.tp_basicsize = sizeof(PyAdaMethodDescrObject);
PyAdaMethodDescr_Type.tp_descr_get = (descrgetfunc)adamethod_descr_get;
}
PyAdaMethodDescrObject *descr = (PyAdaMethodDescrObject*) PyType_GenericAlloc
(&PyAdaMethodDescr_Type, 0);
if (descr != NULL) {
Py_XINCREF(type);
PyDescr_TYPE(descr) = type;
PyDescr_NAME(descr) = PyUnicode_InternFromString(name);
if (PyDescr_NAME(descr) == NULL) {
Py_DECREF(descr);
descr = NULL;
}
}
if (descr != NULL) {
descr->cfunc = cfunc;
}
return (PyObject *)descr;
}
开发者ID:cbourgeois,项目名称:gnatcoll,代码行数:29,代码来源:python_support.c
示例5: PyObject_GenericGetAttr
static PyObject *Proxy_getattro(
ProxyObject *self, PyObject *name)
{
PyObject *object = NULL;
PyObject *result = NULL;
static PyObject *getattr_str = NULL;
object = PyObject_GenericGetAttr((PyObject *)self, name);
if (object)
return object;
PyErr_Clear();
if (!getattr_str) {
#if PY_MAJOR_VERSION >= 3
getattr_str = PyUnicode_InternFromString("__getattr__");
#else
getattr_str = PyString_InternFromString("__getattr__");
#endif
}
object = PyObject_GenericGetAttr((PyObject *)self, getattr_str);
if (!object)
return NULL;
result = PyObject_CallFunctionObjArgs(object, name, NULL);
Py_DECREF(object);
return result;
}
开发者ID:FeodorFitsner,项目名称:python-lazy-object-proxy,代码行数:34,代码来源:cext.c
示例6: __Pyx_InitStrings
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
while (t->p) {
#if PY_MAJOR_VERSION < 3
if (t->is_unicode) {
*t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
} else if (t->intern) {
*t->p = PyString_InternFromString(t->s);
} else {
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
}
#else /* Python 3+ has unicode identifiers */
if (t->is_unicode | t->is_str) {
if (t->intern) {
*t->p = PyUnicode_InternFromString(t->s);
} else if (t->encoding) {
*t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
} else {
*t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
}
} else {
*t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
}
#endif
if (!*t->p)
return -1;
++t;
}
return 0;
}
开发者ID:skipperkongen,项目名称:the_education_of,代码行数:29,代码来源:hello.c
示例7: _PyFrame_Init
int _PyFrame_Init()
{
builtin_object = PyUnicode_InternFromString("__builtins__");
if (builtin_object == NULL)
return 0;
return 1;
}
开发者ID:Jimlan,项目名称:kbengine,代码行数:7,代码来源:frameobject.c
示例8: Call_GetClassObject
long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
PyObject *mod, *func, *result;
long retval;
static PyObject *context;
if (context == NULL)
context = PyUnicode_InternFromString("_ctypes.DllGetClassObject");
mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) {
PyErr_WriteUnraisable(context ? context : Py_None);
/* There has been a warning before about this already */
return E_FAIL;
}
func = PyObject_GetAttrString(mod, "DllGetClassObject");
Py_DECREF(mod);
if (!func) {
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;
}
{
PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid);
PyObject *py_riid = PyLong_FromVoidPtr((void *)riid);
PyObject *py_ppv = PyLong_FromVoidPtr(ppv);
if (!py_rclsid || !py_riid || !py_ppv) {
Py_XDECREF(py_rclsid);
Py_XDECREF(py_riid);
Py_XDECREF(py_ppv);
Py_DECREF(func);
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;
}
result = PyObject_CallFunctionObjArgs(func,
py_rclsid,
py_riid,
py_ppv,
NULL);
Py_DECREF(py_rclsid);
Py_DECREF(py_riid);
Py_DECREF(py_ppv);
}
Py_DECREF(func);
if (!result) {
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;
}
retval = PyLong_AsLong(result);
if (PyErr_Occurred()) {
PyErr_WriteUnraisable(context ? context : Py_None);
retval = E_FAIL;
}
Py_DECREF(result);
return retval;
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:58,代码来源:callbacks.c
示例9: 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);
}
开发者ID:Illirgway,项目名称:cpython,代码行数:11,代码来源:classobject.c
示例10: function_get_name
static PyObject* function_get_name(PyObject* op, void*)
{
function* f = downcast<function>(op);
if (f->name().is_none())
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_InternFromString("<unnamed Boost.Python function>");
#else
return PyString_InternFromString("<unnamed Boost.Python function>");
#endif
else
return python::incref(f->name().ptr());
开发者ID:Alexander--,项目名称:Wesnoth-1.8-for-Android,代码行数:11,代码来源:function.cpp
示例11: PyUnicode_InternFromString
//-------------------------------------------------------------------------------------
PyObject* PropertyDescription::onSetValue(PyObject* parentObj, PyObject* value)
{
PyObject* pyName = PyUnicode_InternFromString(getName());
int result = PyObject_GenericSetAttr(parentObj, pyName, value);
Py_DECREF(pyName);
if(result == -1)
return NULL;
return value;
}
开发者ID:Anehta,项目名称:kbengine,代码行数:12,代码来源:property.cpp
示例12: 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);
}
开发者ID:Illirgway,项目名称:cpython,代码行数:11,代码来源:classobject.c
示例13: init_fibers
/* Module */
PyObject *
init_fibers(void)
{
PyObject *fibers;
/* Main module */
#if PY_MAJOR_VERSION >= 3
fibers = PyModule_Create(&fibers_module);
#else
fibers = Py_InitModule("fibers._cfibers", fibers_methods);
#endif
/* keys for per-thread dictionary */
#if PY_MAJOR_VERSION >= 3
main_fiber_key = PyUnicode_InternFromString("__fibers_main");
current_fiber_key = PyUnicode_InternFromString("__fibers_current");
#else
main_fiber_key = PyString_InternFromString("__fibers_main");
current_fiber_key = PyString_InternFromString("__fibers_current");
#endif
if ((current_fiber_key == NULL) || (main_fiber_key == NULL)) {
goto fail;
}
/* Exceptions */
PyExc_FiberError = PyErr_NewException("fibers._cfibers.error", NULL, NULL);
MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError);
/* Types */
MyPyModule_AddType(fibers, "Fiber", &FiberType);
return fibers;
fail:
#if PY_MAJOR_VERSION >= 3
Py_DECREF(fibers);
#endif
return NULL;
}
开发者ID:eugene-eeo,项目名称:python-fibers,代码行数:41,代码来源:fibers.c
示例14: __Pyx_CyFunction_get_name
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
{
if (op->func_name == NULL) {
#if PY_MAJOR_VERSION >= 3
op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
}
Py_INCREF(op->func_name);
return op->func_name;
}
开发者ID:dynamicgl,项目名称:CythonCTypesBackend,代码行数:13,代码来源:CythonFunction.c
示例15: optional
FunctionParameter::FunctionParameter(const std::string& fmt, bool keyword_only)
: optional(false)
, allow_none(false)
, keyword_only(keyword_only)
, size(0)
, default_scalar(0)
{
auto space = fmt.find(' ');
if (space == std::string::npos) {
throw std::runtime_error("FunctionParameter(): missing type: " + fmt);
}
auto type_str = fmt.substr(0, space);
auto question = type_str.find('?');
if (question != std::string::npos) {
allow_none = true;
type_str = type_str.substr(0, question);
}
// Parse and remove brackets from type_str
auto bracket = type_str.find('[');
if (bracket != std::string::npos) {
auto size_str = type_str.substr(bracket + 1, type_str.length() - bracket - 2);
size = atoi(size_str.c_str());
type_str = type_str.substr(0, bracket);
}
auto name_str = fmt.substr(space + 1);
auto it = type_map.find(type_str);
if (it == type_map.end()) {
throw std::runtime_error("FunctionParameter(): invalid type string: " + type_str);
}
type_ = it->second;
auto eq = name_str.find('=');
if (eq != std::string::npos) {
name = name_str.substr(0, eq);
optional = true;
set_default_str(name_str.substr(eq + 1));
} else {
name = name_str;
}
#if PY_MAJOR_VERSION == 2
python_name = PyString_InternFromString(name.c_str());
#else
python_name = PyUnicode_InternFromString(name.c_str());
#endif
}
开发者ID:xiongyw,项目名称:pytorch,代码行数:49,代码来源:python_arg_parser.cpp
示例16: math_floor
static PyObject * math_floor(PyObject *self, PyObject *number) {
static PyObject *floor_str = NULL;
PyObject *method;
if (floor_str == NULL) {
floor_str = PyUnicode_InternFromString("__floor__");
if (floor_str == NULL)
return NULL;
}
method = _PyType_Lookup(Py_TYPE(number), floor_str);
if (method == NULL)
return math_1_to_int(number, floor, 0);
else
return PyObject_CallFunction(method, "O", number);
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:16,代码来源:mathmodule.c
示例17: PyArray_GetAttrString_SuppressException
/*
* PyArray_GetAttrString_SuppressException:
*
* Stripped down version of PyObject_GetAttrString,
* avoids lookups for None, tuple, and List objects,
* and doesn't create a PyErr since this code ignores it.
*
* This can be much faster then PyObject_GetAttrString where
* exceptions are not used by caller.
*
* 'obj' is the object to search for attribute.
*
* 'name' is the attribute to search for.
*
* Returns attribute value on success, 0 on failure.
*/
PyObject *
PyArray_GetAttrString_SuppressException(PyObject *obj, char *name)
{
PyTypeObject *tp = Py_TYPE(obj);
PyObject *res = (PyObject *)NULL;
/* We do not need to check for special attributes on trivial types */
if (obj == Py_None ||
/* Basic number types */
#if !defined(NPY_PY3K)
PyInt_CheckExact(obj) ||
#endif
PyLong_CheckExact(obj) ||
PyFloat_CheckExact(obj) ||
/* Basic sequence types */
PyList_CheckExact(obj) ||
PyTuple_CheckExact(obj)) {
return NULL;
}
/* Attribute referenced by (char *)name */
if (tp->tp_getattr != NULL) {
res = (*tp->tp_getattr)(obj, name);
if (res == NULL) {
PyErr_Clear();
}
}
/* Attribute referenced by (PyObject *)name */
else if (tp->tp_getattro != NULL) {
#if defined(NPY_PY3K)
PyObject *w = PyUnicode_InternFromString(name);
#else
PyObject *w = PyString_InternFromString(name);
#endif
if (w == NULL) {
return (PyObject *)NULL;
}
res = (*tp->tp_getattro)(obj, w);
Py_DECREF(w);
if (res == NULL) {
PyErr_Clear();
}
}
return res;
}
开发者ID:JStech,项目名称:numpy,代码行数:61,代码来源:common.c
示例18: get_warnings_attr
/*
Returns a new reference.
A NULL return value can mean false or an error.
*/
static PyObject *
get_warnings_attr(const char *attr, int try_import)
{
static PyObject *warnings_str = NULL;
PyObject *all_modules;
PyObject *warnings_module, *obj;
if (warnings_str == NULL) {
warnings_str = PyUnicode_InternFromString("warnings");
if (warnings_str == NULL)
return NULL;
}
/* don't try to import after the start of the Python finallization */
if (try_import && _Py_Finalizing == NULL) {
warnings_module = PyImport_Import(warnings_str);
if (warnings_module == NULL) {
/* Fallback to the C implementation if we cannot get
the Python implementation */
PyErr_Clear();
return NULL;
}
}
else {
all_modules = PyImport_GetModuleDict();
warnings_module = PyDict_GetItem(all_modules, warnings_str);
if (warnings_module == NULL)
return NULL;
Py_INCREF(warnings_module);
}
if (!PyObject_HasAttrString(warnings_module, attr)) {
Py_DECREF(warnings_module);
return NULL;
}
obj = PyObject_GetAttrString(warnings_module, attr);
Py_DECREF(warnings_module);
return obj;
}
开发者ID:PiJoules,项目名称:cpython-modified,代码行数:46,代码来源:_warnings.c
示例19: init_fibers
/* Module */
PyObject *
init_fibers(void)
{
PyObject *fibers;
/* Main module */
#if PY_MAJOR_VERSION >= 3
fibers = PyModule_Create(&fibers_module);
#else
fibers = Py_InitModule("fibers", fibers_methods);
#endif
/* keys for per-thread dictionary */
#if PY_MAJOR_VERSION >= 3
current_fiber_key = PyUnicode_InternFromString("__fibers_current");
#else
current_fiber_key = PyString_InternFromString("__fibers_current");
#endif
if (current_fiber_key == NULL) {
goto fail;
}
/* Exceptions */
PyExc_FiberError = PyErr_NewException("fibers.error", NULL, NULL);
MyPyModule_AddType(fibers, "error", (PyTypeObject *)PyExc_FiberError);
/* Types */
MyPyModule_AddType(fibers, "Fiber", &FiberType);
/* Module version (the MODULE_VERSION macro is defined by setup.py) */
PyModule_AddStringConstant(fibers, "__version__", STRINGIFY(MODULE_VERSION));
return fibers;
fail:
#if PY_MAJOR_VERSION >= 3
Py_DECREF(fibers);
#endif
return NULL;
}
开发者ID:Dmdv,项目名称:python-fibers,代码行数:42,代码来源:fibers.c
示例20: get_bounding_box
static PlanarBBoxObject *
get_bounding_box(PyObject *shape)
{
PlanarBBoxObject *bbox;
static PyObject *bounding_box_str = NULL;
if (bounding_box_str == NULL) {
bounding_box_str = PyUnicode_InternFromString("bounding_box");
if (bounding_box_str == NULL) {
return NULL;
}
}
bbox = (PlanarBBoxObject *)PyObject_GetAttr(shape, bounding_box_str);
if (bbox != NULL && !PlanarBBox_Check(bbox)) {
PyErr_SetString(PyExc_TypeError,
"Shape returned incompatible object "
"for attribute bounding_box.");
Py_CLEAR(bbox);
}
return bbox;
}
开发者ID:Jacobmose,项目名称:ITROB,代码行数:21,代码来源:cbox.c
注:本文中的PyUnicode_InternFromString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论