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


C++ PyUnicode_FromString函数代码示例

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


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

示例1: PyThread_GetInfo

PyObject*
PyThread_GetInfo(void)
{
    PyObject *threadinfo, *value;
    int pos = 0;
#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
     && defined(_CS_GNU_LIBPTHREAD_VERSION))
    char buffer[255];
    int len;
#endif

    if (ThreadInfoType.tp_name == 0) {
        if (PyStructSequence_InitType2(&ThreadInfoType, &threadinfo_desc) < 0)
            return NULL;
    }

    threadinfo = PyStructSequence_New(&ThreadInfoType);
    if (threadinfo == NULL)
        return NULL;

    value = PyUnicode_FromString(PYTHREAD_NAME);
    if (value == NULL) {
        Py_DECREF(threadinfo);
        return NULL;
    }
    PyStructSequence_SET_ITEM(threadinfo, pos++, value);

#ifdef _POSIX_THREADS
#ifdef USE_SEMAPHORES
    value = PyUnicode_FromString("semaphore");
#else
    value = PyUnicode_FromString("mutex+cond");
#endif
    if (value == NULL) {
        Py_DECREF(threadinfo);
        return NULL;
    }
#else
    Py_INCREF(Py_None);
    value = Py_None;
#endif
    PyStructSequence_SET_ITEM(threadinfo, pos++, value);

#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \
     && defined(_CS_GNU_LIBPTHREAD_VERSION))
    value = NULL;
    len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
    if (1 < len && len < sizeof(buffer)) {
        value = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
        if (value == NULL)
            PyErr_Clear();
    }
    if (value == NULL)
#endif
    {
        Py_INCREF(Py_None);
        value = Py_None;
    }
    PyStructSequence_SET_ITEM(threadinfo, pos++, value);
    return threadinfo;
}
开发者ID:dougmassay,项目名称:cpython3.4.4,代码行数:61,代码来源:thread.c

示例2: pyfshfs_file_object_write_buffer

/* Writes a buffer to the file object
 * Make sure to hold the GIL state before calling this function
 * Returns the number of bytes written if successful, or -1 on error
 */
ssize_t pyfshfs_file_object_write_buffer(
         PyObject *file_object,
         const uint8_t *buffer,
         size_t size,
         libcerror_error_t **error )
{
	PyObject *argument_string = NULL;
	PyObject *method_name     = NULL;
	PyObject *method_result   = NULL;
	static char *function     = "pyfshfs_file_object_write_buffer";

	if( file_object == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid file object.",
		 function );

		return( -1 );
	}
	if( buffer == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid buffer.",
		 function );

		return( -1 );
	}
#if SIZEOF_SIZE_T > SIZEOF_INT
	if( size > (size_t) INT_MAX )
#else
	if( size > (size_t) SSIZE_MAX )
#endif
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid size value exceeds maximum.",
		 function );

		return( -1 );
	}
	if( size > 0 )
	{
#if PY_MAJOR_VERSION >= 3
		method_name = PyUnicode_FromString(
			       "write" );
#else
		method_name = PyString_FromString(
			       "write" );
#endif
#if PY_MAJOR_VERSION >= 3
		argument_string = PyBytes_FromStringAndSize(
		                   (char *) buffer,
		                   size );
#else
		argument_string = PyString_FromStringAndSize(
		                   (char *) buffer,
		                   size );
#endif
		PyErr_Clear();

		method_result = PyObject_CallMethodObjArgs(
				 file_object,
				 method_name,
				 argument_string,
				 NULL );

		if( PyErr_Occurred() )
		{
			pyfshfs_error_fetch(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_WRITE_FAILED,
			 "%s: unable to write to file object.",
			 function );

			goto on_error;
		}
		if( method_result == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing method result.",
			 function );

			goto on_error;
		}
//.........这里部分代码省略.........
开发者ID:roox,项目名称:libfshfs,代码行数:101,代码来源:pyfshfs_file_object_io_handle.c

示例3: PyUnicode_FromString

PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
	BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v);
	return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
}
开发者ID:jinjoh,项目名称:NOOR,代码行数:5,代码来源:BL_ShapeActionActuator.cpp

示例4: pyfshfs_file_object_get_offset

/* Retrieves the current offset within the file object
 * Make sure to hold the GIL state before calling this function
 * Returns 1 if successful or -1 on error
 */
int pyfshfs_file_object_get_offset(
     PyObject *file_object,
     off64_t *offset,
     libcerror_error_t **error )
{
	PyObject *method_name   = NULL;
	PyObject *method_result = NULL;
	static char *function   = "pyfshfs_file_object_get_offset";
	int result              = 0;

	if( file_object == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid file object.",
		 function );

		return( -1 );
	}
	if( offset == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid offset.",
		 function );

		return( -1 );
	}
#if PY_MAJOR_VERSION >= 3
	method_name = PyUnicode_FromString(
	               "get_offset" );
#else
	method_name = PyString_FromString(
	               "get_offset" );
#endif
	PyErr_Clear();

	/* Determine if the file object has the get_offset method
	 */
	result = PyObject_HasAttr(
	          file_object,
	          method_name );

	if( result == 0 )
	{
		Py_DecRef(
		 method_name );

		/* Fall back to the tell method
		 */
#if PY_MAJOR_VERSION >= 3
		method_name = PyUnicode_FromString(
		               "tell" );
#else
		method_name = PyString_FromString(
		               "tell" );
#endif
	}
	PyErr_Clear();

	method_result = PyObject_CallMethodObjArgs(
	                 file_object,
	                 method_name,
	                 NULL );

	if( PyErr_Occurred() )
	{
		pyfshfs_error_fetch(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve current offset in file object.",
		 function );

		goto on_error;
	}
	if( method_result == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: missing method result.",
		 function );

		goto on_error;
	}
	if( pyfshfs_integer_signed_copy_to_64bit(
	     method_result,
	     offset,
	     error ) != 1 )
	{
//.........这里部分代码省略.........
开发者ID:roox,项目名称:libfshfs,代码行数:101,代码来源:pyfshfs_file_object_io_handle.c

示例5: pyfshfs_file_object_io_handle_get_size

/* Retrieves the file size
 * Returns 1 if successful or -1 on error
 */
int pyfshfs_file_object_io_handle_get_size(
     pyfshfs_file_object_io_handle_t *file_object_io_handle,
     size64_t *size,
     libcerror_error_t **error )
{
	PyObject *method_name      = NULL;
	static char *function      = "pyfshfs_file_object_io_handle_get_size";
	off64_t current_offset     = 0;
	PyGILState_STATE gil_state = 0;
	int result                 = 0;

	if( file_object_io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid file object IO handle.",
		 function );

		return( -1 );
	}
	if( file_object_io_handle->file_object == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: invalid file object IO handle - missing file object.",
		 function );

		return( -1 );
	}
	gil_state = PyGILState_Ensure();

#if PY_MAJOR_VERSION >= 3
	method_name = PyUnicode_FromString(
	               "get_size" );
#else
	method_name = PyString_FromString(
	               "get_size" );
#endif
	PyErr_Clear();

	/* Determine if the file object has the get_size method
	 */
	result = PyObject_HasAttr(
	          file_object_io_handle->file_object,
	          method_name );

	if( result != 0 )
	{
		if( pyfshfs_file_object_get_size(
		     file_object_io_handle->file_object,
		     size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve size of file object.",
			 function );

			goto on_error;
		}
	}
	else
	{
		if( pyfshfs_file_object_get_offset(
		     file_object_io_handle->file_object,
		     &current_offset,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve current offset in file object.",
			 function );

			goto on_error;
		}
		if( pyfshfs_file_object_seek_offset(
		     file_object_io_handle->file_object,
		     0,
		     SEEK_END,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_SEEK_FAILED,
			 "%s: unable to seek end of file object.",
			 function );

			goto on_error;
//.........这里部分代码省略.........
开发者ID:roox,项目名称:libfshfs,代码行数:101,代码来源:pyfshfs_file_object_io_handle.c

示例6: header


//.........这里部分代码省略.........
		HINSTANCE hDLL = NULL;
		char pathbuf[260];
		LPTSTR dummy;
		unsigned int old_mode;
		/* We use LoadLibraryEx so Windows looks for dependent DLLs 
		    in directory of pathname first.  However, Windows95
		    can sometimes not work correctly unless the absolute
		    path is used.  If GetFullPathName() fails, the LoadLibrary
		    will certainly fail too, so use its error code */

		/* Don't display a message box when Python can't load a DLL */
		old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);

		if (GetFullPathName(pathname,
				    sizeof(pathbuf),
				    pathbuf,
				    &dummy))
			/* XXX This call doesn't exist in Windows CE */
			hDLL = LoadLibraryEx(pathname, NULL,
					     LOAD_WITH_ALTERED_SEARCH_PATH);

		/* restore old error mode settings */
		SetErrorMode(old_mode);

		if (hDLL==NULL){
			PyObject *message;
			unsigned int errorCode;

			/* Get an error string from Win32 error code */
			wchar_t theInfo[256]; /* Pointer to error text
					      from system */
			int theLength; /* Length of error text */

			errorCode = GetLastError();

			theLength = FormatMessageW(
				FORMAT_MESSAGE_FROM_SYSTEM |
				FORMAT_MESSAGE_IGNORE_INSERTS, /* flags */
				NULL, /* message source */
				errorCode, /* the message (error) ID */
				MAKELANGID(LANG_NEUTRAL,
					   SUBLANG_DEFAULT),
				           /* Default language */
				theInfo, /* the buffer */
				sizeof(theInfo), /* the buffer size */
				NULL); /* no additional format args. */

			/* Problem: could not get the error message.
			   This should not happen if called correctly. */
			if (theLength == 0) {
				message = PyUnicode_FromFormat(
					"DLL load failed with error code %d",
					errorCode);
			} else {
				/* For some reason a \r\n
				   is appended to the text */
				if (theLength >= 2 &&
				    theInfo[theLength-2] == '\r' &&
				    theInfo[theLength-1] == '\n') {
					theLength -= 2;
					theInfo[theLength] = '\0';
				}
				message = PyUnicode_FromString(
					"DLL load failed: ");

				PyUnicode_AppendAndDel(&message, 
					PyUnicode_FromUnicode(
						theInfo, 
						theLength));
			}
			PyErr_SetObject(PyExc_ImportError, message);
			Py_XDECREF(message);
			return NULL;
		} else {
			char buffer[256];

#ifdef _DEBUG
			PyOS_snprintf(buffer, sizeof(buffer), "python%d%d_d.dll",
#else
			PyOS_snprintf(buffer, sizeof(buffer), "python%d%d.dll",
#endif
				      PY_MAJOR_VERSION,PY_MINOR_VERSION);
			import_python = GetPythonImport(hDLL);

			if (import_python &&
			    strcasecmp(buffer,import_python)) {
				PyOS_snprintf(buffer, sizeof(buffer),
					      "Module use of %.150s conflicts "
					      "with this version of Python.",
					      import_python);
				PyErr_SetString(PyExc_ImportError,buffer);
				FreeLibrary(hDLL);
				return NULL;
			}
		}
		p = GetProcAddress(hDLL, funcname);
	}

	return p;
}
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:101,代码来源:dynload_win.c

示例7: error

bool PythonTransform::loadModuleAttributes()
{
    if (pModule == NULL) {
        Q_EMIT error(tr("The module object is NULL for %1, could not (re)load the configuration").arg(moduleFileName),id);
        return false;
    }

    qDebug() << "Loading module attributes" << moduleName;

    bool ret = true;
    bool oldtwoWays = twoWays;
    twoWays = false; // setting default

    PyGILState_STATE lgstate;
    lgstate = PyGILState_Ensure();

    // checking if the two ways attribute is there
    PyObject * twoWayAttr = PyUnicode_FromString(ISTWOWAY_ATTR_NAME); // New ref
    if (pythonmgm->checkPyError()) {
        if (PyObject_HasAttr(pModule,twoWayAttr) == 1) {  // does the module has the attribute?
            PyObject * pyTwoWay = PyObject_GetAttr(pModule,twoWayAttr); // New ref
            if (pythonmgm->checkPyError()) {
                twoWays =  pyTwoWay == Py_True;
            } else {
                logError(tr("T_T Error while getting attribute value ISTWOWAY_ATTR_NAME for %1:\n%2").arg(moduleFileName).arg(pythonmgm->getLastError()),id);
            }
            Py_XDECREF(pyTwoWay);
        } else {
            qDebug() << moduleFileName << "has no attribute" << ISTWOWAY_ATTR_NAME;
        }
    } else {
        logError(tr("T_T Error while converting to Unicode string:\n%1").arg(pythonmgm->getLastError()),id);
    }
    Py_XDECREF(twoWayAttr);

    bool parametersChanged = false;
    // checking if some default parameters names were defined
    PyObject * paramsNamesAttr = PyUnicode_FromString(PARAMS_NAMES_ATTR_NAME); // New ref
    if (pythonmgm->checkPyError()) {
        if (PyObject_HasAttr(pModule,paramsNamesAttr) == 1) { // does the module has the attribute?
            PyObject * pyNamesList = PyObject_GetAttr(pModule,paramsNamesAttr); // New ref
            if (pythonmgm->checkPyError()) {
                if (PyList_Check(pyNamesList)) {
                    Py_ssize_t listSize = PyList_Size(pyNamesList);
                    if (listSize > 0) { // if list size is null then nothing to do
                        for (int i = 0; i < listSize; i++) {
                            QByteArray val;
                            PyObject *pyName = PyList_GetItem(pyNamesList, i); // borrowed ref
                            if (pythonmgm->checkPyError()) { // error or invalid?
#ifdef BUILD_PYTHON_3
                                if (PyUnicode_Check(pyName)) { // is this a unicode string?
                                    PyObject * nameutf8 = PyUnicode_AsUTF8String(pyName); // new ref
                                    if (pythonmgm->checkPyError() && nameutf8 != NULL) {
                                        val = QByteArray(PyBytes_AsString(nameutf8), PyBytes_Size(nameutf8));
                                    } else {
                                        logError(tr("Error while encoding a parameter to UTF-8:%1").arg(pythonmgm->getLastError()),id);
                                    }
                                    Py_XDECREF(nameutf8);
#else
                                if (PyString_Check(pyName)) { // is this a string?
                                    val = QByteArray(PyString_AsString(pyName), PyString_Size(pyName));
#endif
                                    if (val.isEmpty()) { // if the parameter name is empty, we skip
                                        logWarning(tr("The Python object %1[%2] is an empty string, ignoring.").arg(PARAMS_NAMES_ATTR_NAME).arg(i),id);
                                    } else if (!parameters.contains(val)) { // we don't want to erase any pre-existing configuration
                                        parameters.insert(val, QByteArray());
                                        parametersChanged = true;
                                    }
                                } else {
                                    logWarning(tr("The Python object %1[%2] is not a string, ignoring.").arg(PARAMS_NAMES_ATTR_NAME).arg(i),id);
                                }
                            } else {
                                logError(tr("T_T Error while getting the item from attribute list:\n%1").arg(pythonmgm->getLastError()),id);
                            }
                        }
                    } else {
                        logWarning(tr("The Python object for attribute names (%1) is empty, ignoring.").arg(PARAMS_NAMES_ATTR_NAME),id);
                    }
                } else {
                    logWarning(tr("The Python object for attribute names (%1) is not a list, ignoring.").arg(PARAMS_NAMES_ATTR_NAME),id);
                }

            } else {
开发者ID:nccgroup,项目名称:pip3line,代码行数:83,代码来源:pythontransform.cpp

示例8: String_toPyObject

static KMETHOD String_toPyObject(KonohaContext *kctx, KonohaStack *sfp)
{
	KReturnPyObject(PyUnicode_FromString(kString_text(sfp[0].asString)));
}
开发者ID:myoan,项目名称:minikonoha,代码行数:4,代码来源:python_glue.c

示例9: PyCOMPSPack_strget_

PyObject* PyCOMPSPack_strget_(PyCOMPS_Package *self, void *closure) {
    char *tmp = GET_FROM(self->package, (size_t)closure);
    return PyUnicode_FromString(tmp);
}
开发者ID:dmach,项目名称:libcomps,代码行数:4,代码来源:pycomps_groups.c

示例10: get_mode

static PyObject *
get_mode(PyStdPrinter_Object *self, void *closure)
{
    return PyUnicode_FromString("w");
}
开发者ID:jadore,项目名称:cpython,代码行数:5,代码来源:fileobject.c

示例11: setup_context

/* Returns 0 on error (no new refs), 1 on success */
static int
setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
              PyObject **module, PyObject **registry)
{
    PyObject *globals;

    /* Setup globals and lineno. */
    PyFrameObject *f = PyThreadState_GET()->frame;
    while (--stack_level > 0 && f != NULL)
        f = f->f_back;

    if (f == NULL) {
        globals = PyThreadState_Get()->interp->sysdict;
        *lineno = 1;
    }
    else {
        globals = f->f_globals;
        *lineno = PyFrame_GetLineNumber(f);
    }

    *module = NULL;

    /* Setup registry. */
    assert(globals != NULL);
    assert(PyDict_Check(globals));
    *registry = PyDict_GetItemString(globals, "__warningregistry__");
    if (*registry == NULL) {
        int rc;

        *registry = PyDict_New();
        if (*registry == NULL)
            return 0;

         rc = PyDict_SetItemString(globals, "__warningregistry__", *registry);
         if (rc < 0)
            goto handle_error;
    }
    else
        Py_INCREF(*registry);

    /* Setup module. */
    *module = PyDict_GetItemString(globals, "__name__");
    if (*module == NULL) {
        *module = PyUnicode_FromString("<string>");
        if (*module == NULL)
            goto handle_error;
    }
    else
        Py_INCREF(*module);

    /* Setup filename. */
    *filename = PyDict_GetItemString(globals, "__file__");
    if (*filename != NULL && PyUnicode_Check(*filename)) {
        Py_ssize_t len;
        int kind;
        void *data;

        if (PyUnicode_READY(*filename))
            goto handle_error;

        len = PyUnicode_GetLength(*filename);
        kind = PyUnicode_KIND(*filename);
        data = PyUnicode_DATA(*filename);

#define ascii_lower(c) ((c <= 127) ? Py_TOLOWER(c) : 0)
        /* if filename.lower().endswith((".pyc", ".pyo")): */
        if (len >= 4 &&
            PyUnicode_READ(kind, data, len-4) == '.' &&
            ascii_lower(PyUnicode_READ(kind, data, len-3)) == 'p' &&
            ascii_lower(PyUnicode_READ(kind, data, len-2)) == 'y' &&
            (ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c' ||
                ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'o'))
        {
            *filename = PyUnicode_Substring(*filename, 0,
                                            PyUnicode_GET_LENGTH(*filename)-1);
            if (*filename == NULL)
                goto handle_error;
        }
        else
            Py_INCREF(*filename);
    }
    else {
        *filename = NULL;
        if (*module != Py_None && PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) {
            PyObject *argv = _PySys_GetObjectId(&PyId_argv);
            /* PyList_Check() is needed because sys.argv is set to None during
               Python finalization */
            if (argv != NULL && PyList_Check(argv) && PyList_Size(argv) > 0) {
                int is_true;
                *filename = PyList_GetItem(argv, 0);
                Py_INCREF(*filename);
                /* If sys.argv[0] is false, then use '__main__'. */
                is_true = PyObject_IsTrue(*filename);
                if (is_true < 0) {
                    Py_DECREF(*filename);
                    goto handle_error;
                }
                else if (!is_true) {
                    Py_DECREF(*filename);
//.........这里部分代码省略.........
开发者ID:1564143452,项目名称:kbengine,代码行数:101,代码来源:_warnings.c

示例12: PyInit__rpy_device

PyInit__rpy_device(void)
#endif
{
#if (PY_VERSION_HEX < 0x03010000)
  GrDev_close_name = PyString_FromString("close");
  GrDev_activate_name = PyString_FromString("activate");
  GrDev_deactivate_name = PyString_FromString("deactivate");
  GrDev_size_name = PyString_FromString("size");
  GrDev_newpage_name = PyString_FromString("newpage");
  GrDev_clip_name = PyString_FromString("clip");
  GrDev_strwidth_name = PyString_FromString("strwidth");
  GrDev_text_name = PyString_FromString("text");
  GrDev_rect_name = PyString_FromString("rect");
  GrDev_circle_name = PyString_FromString("circle");
  GrDev_line_name = PyString_FromString("line");
  GrDev_polyline_name = PyString_FromString("polyline");
  GrDev_polygon_name = PyString_FromString("polygon");
  GrDev_locator_name = PyString_FromString("locator");
  GrDev_mode_name = PyString_FromString("mode");
  GrDev_metricinfo_name = PyString_FromString("metricinfo");
  GrDev_getevent_name = PyString_FromString("getevent");
#else
  GrDev_close_name = PyUnicode_FromString("close");
  GrDev_activate_name = PyUnicode_FromString("activate");
  GrDev_deactivate_name = PyUnicode_FromString("deactivate");
  GrDev_size_name = PyUnicode_FromString("size");
  GrDev_newpage_name = PyUnicode_FromString("newpage");
  GrDev_clip_name = PyUnicode_FromString("clip");
  GrDev_strwidth_name = PyUnicode_FromString("strwidth");
  GrDev_text_name = PyUnicode_FromString("text");
  GrDev_rect_name = PyUnicode_FromString("rect");
  GrDev_circle_name = PyUnicode_FromString("circle");
  GrDev_line_name = PyUnicode_FromString("line");
  GrDev_polyline_name = PyUnicode_FromString("polyline");
  GrDev_polygon_name = PyUnicode_FromString("polygon");
  GrDev_locator_name = PyUnicode_FromString("locator");
  GrDev_mode_name = PyUnicode_FromString("mode");
  GrDev_metricinfo_name = PyUnicode_FromString("metricinfo");
  GrDev_getevent_name = PyUnicode_FromString("getevent");
#endif
  if (PyType_Ready(&GrDev_Type) < 0) {
#if (PY_VERSION_HEX < 0x03010000)
    return;
#else
    return NULL;
#endif
  }
  
  PyObject *m, *d;
#if (PY_VERSION_HEX < 0x03010000)
  m = Py_InitModule3("_rpy_device", rpydevice_methods, module_doc);
#else
  m = PyModule_Create(&rpydevicemodule);
#endif
  if (m == NULL) {
#if (PY_VERSION_HEX < 0x03010000)
    return;
#else
    return NULL;
#endif
  }

  if (import_rinterface() < 0)
#if (PY_VERSION_HEX < 0x03010000)
    return;
#else
    return NULL;
#endif

  d = PyModule_GetDict(m);
  PyModule_AddObject(m, "GraphicalDevice", (PyObject *)&GrDev_Type);  
#if (PY_VERSION_HEX < 0x03010000)
#else
  return m;
#endif
}
开发者ID:ktargows,项目名称:rpy2,代码行数:76,代码来源:_rpy_device.c

示例13: get_line_buffer

static PyObject *
get_line_buffer(PyObject *self, PyObject *noarg)
{
    return PyUnicode_FromString(rl_line_buffer);
}
开发者ID:JeevaMunusamy,项目名称:cpython,代码行数:5,代码来源:readline.c

示例14: ejdb_version

static PyObject* ejdb_version(PyObject *module) {
    return PyUnicode_FromString(tcversion);
}
开发者ID:JoakimSoderberg,项目名称:ejdb,代码行数:3,代码来源:pyejdb.c

示例15: registerPyObjectToScript

bool EntityApp<E>::installPyModules()
{
	Entities<E>::installScript(NULL);
	//Entity::installScript(g_script.getModule());

	pEntities_ = new Entities<E>();
	registerPyObjectToScript("entities", pEntities_);

	// 安装入口模块
	PyObject *entryScriptFileName = NULL;
	if(componentType() == BASEAPP_TYPE)
	{
		ENGINE_COMPONENT_INFO& info = g_kbeSrvConfig.getBaseApp();
		entryScriptFileName = PyUnicode_FromString(info.entryScriptFile);
	}
	else if(componentType() == CELLAPP_TYPE)
	{
		ENGINE_COMPONENT_INFO& info = g_kbeSrvConfig.getCellApp();
		entryScriptFileName = PyUnicode_FromString(info.entryScriptFile);
	}

	if(entryScriptFileName != NULL)
	{
		entryScript_ = PyImport_Import(entryScriptFileName);
		SCRIPT_ERROR_CHECK();
		S_RELEASE(entryScriptFileName);

		if(entryScript_.get() == NULL)
		{
			return false;
		}
	}

	// 添加pywatcher支持
	if(!initializePyWatcher(&this->getScript()))
		return false;

	// 添加globalData, globalBases支持
	pGlobalData_ = new GlobalDataClient(DBMGR_TYPE, GlobalDataServer::GLOBAL_DATA);
	registerPyObjectToScript("globalData", pGlobalData_);

	// 注册创建entity的方法到py
	// 向脚本注册app发布状态
	APPEND_SCRIPT_MODULE_METHOD(getScript().getModule(),	publish,			__py_getAppPublish,		METH_VARARGS,	0);

	// 注册设置脚本输出类型
	APPEND_SCRIPT_MODULE_METHOD(getScript().getModule(),	scriptLogType,		__py_setScriptLogType,	METH_VARARGS,	0);
	
	// 获得资源全路径
	APPEND_SCRIPT_MODULE_METHOD(getScript().getModule(),	getResFullPath,		__py_getResFullPath,	METH_VARARGS,	0);

	// 文件操作
	APPEND_SCRIPT_MODULE_METHOD(getScript().getModule(),	open,				__py_kbeOpen,			METH_VARARGS,	0);

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_NORMAL", log4cxx::ScriptLevel::SCRIPT_INT))
	{
		ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.LOG_TYPE_NORMAL.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_INFO", log4cxx::ScriptLevel::SCRIPT_INFO))
	{
		ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.LOG_TYPE_INFO.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_ERR", log4cxx::ScriptLevel::SCRIPT_ERR))
	{
		ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.LOG_TYPE_ERR.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_DBG", log4cxx::ScriptLevel::SCRIPT_DBG))
	{
		ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.LOG_TYPE_DBG.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_WAR", log4cxx::ScriptLevel::SCRIPT_WAR))
	{
		ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.LOG_TYPE_WAR.\n");
	}


	if(PyModule_AddIntConstant(this->getScript().getModule(), "NEXT_ONLY", KBE_NEXT_ONLY))
	{
		ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.NEXT_ONLY.\n");
	}
	
	onInstallPyModules();
	return true;
}
开发者ID:KerwinMa,项目名称:kbengine-1,代码行数:88,代码来源:entity_app.hpp


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