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


C++ PyInt_FromLong函数代码示例

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


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

示例1: spyceRequest

	int spyceRequest(webs_t wp, char_t *lpath)
	{
		// initialize python first
		if(!spyInitialized)
		{
			g_pythonParser.Initialize();

			PyEval_AcquireLock();
			PyInterpreterState * mainInterpreterState = g_pythonParser.getMainThreadState()->interp;
			spyThreadState = PyThreadState_New(mainInterpreterState);
			PyThreadState_Swap(spyThreadState);

			PyObject* pName = PyString_FromString("spyceXbmc");
			PyObject* pModule = PyImport_Import(pName);
			Py_XDECREF(pName);

			if(!pModule) websError(wp, 500, (char*)"%s", (char*)"Corrupted Spyce installation");
			else
			{
				PyObject* pDict = PyModule_GetDict(pModule);
				Py_XDECREF(pModule);
				spyFunc = PyDict_GetItemString(pDict, "ParseFile");
				if(!spyFunc) websError(wp, 500, (char*)"%s", (char*)"Corrupted Spyce installation");
				
				else spyInitialized = true;
			}

			PyThreadState_Swap(NULL);
			PyEval_ReleaseLock();
			if(!spyInitialized)
			{
				PyThreadState_Clear(spyThreadState);
				PyThreadState_Delete(spyThreadState);
				g_pythonParser.Finalize();
				return -1;		
			}
			
		}

		PyEval_AcquireLock();
		PyThreadState_Swap(spyThreadState);

		std::string strRequestMethod;
		std::string strQuery = wp->query;
		std::string strCookie;
		int iContentLength = 0;
		
		if (strlen(wp->query) > 0)
		{
			if(wp->flags & WEBS_POST_REQUEST)	strRequestMethod = "POST";
			else if (wp->flags & WEBS_HEAD_REQUEST) strRequestMethod = "HEAD";
			else strRequestMethod = "GET";
		}

		if (wp->flags & WEBS_COOKIE) strCookie = wp->cookie;
		iContentLength = strQuery.length();

		// create enviroment and parse file
		PyObject* pEnv = PyDict_New();
		PyObject* pREQUEST_METHOD = PyString_FromString(strRequestMethod.c_str());
		PyObject* pCONTENT_LENGTH = PyInt_FromLong(iContentLength);
		PyObject* pQUERY_STRING = PyString_FromString(strQuery.c_str());
		PyObject* pHTTP_COOKIE = PyString_FromString(strCookie.c_str());
		PyObject* pCONTENT_TYPE = PyString_FromString(wp->type);
		PyObject* pHTTP_HOST = PyString_FromString(wp->host);
		PyObject* pHTTP_USER_AGENT = PyString_FromString(wp->userAgent ? wp->userAgent : "");
		PyObject* pHTTP_CONNECTION = PyString_FromString((wp->flags & WEBS_KEEP_ALIVE)? "Keep-Alive" : "");

		PyDict_SetItemString(pEnv, "REQUEST_METHOD", pREQUEST_METHOD);
		PyDict_SetItemString(pEnv, "CONTENT_LENGTH", pCONTENT_LENGTH);
		PyDict_SetItemString(pEnv, "QUERY_STRING", pQUERY_STRING);
		PyDict_SetItemString(pEnv, "HTTP_COOKIE", pHTTP_COOKIE);
		//PyDict_SetItemString(pEnv, "CONTENT_TYPE", pCONTENT_TYPE);
		PyDict_SetItemString(pEnv, "HTTP_HOST", pHTTP_HOST);
		PyDict_SetItemString(pEnv, "HTTP_USER_AGENT", pHTTP_USER_AGENT);
		PyDict_SetItemString(pEnv, "HTTP_CONNECTION", pHTTP_CONNECTION);

		PyObject* pResult = PyObject_CallFunction(spyFunc, (char*)"sO", lpath, pEnv);

		Py_XDECREF(pREQUEST_METHOD);
		Py_XDECREF(pCONTENT_LENGTH);
		Py_XDECREF(pQUERY_STRING);
		Py_XDECREF(pHTTP_COOKIE);
		Py_XDECREF(pCONTENT_TYPE);
		Py_XDECREF(pHTTP_HOST);
		Py_XDECREF(pHTTP_USER_AGENT);
		Py_XDECREF(pHTTP_CONNECTION);

		Py_XDECREF(pEnv);

		if(!pResult) websError(wp, 500, (char*)"%s", (char*)"Corrupted Spyce installation");
		else
		{
			char* cResult = PyString_AsString(pResult);
			websWriteBlock(wp, cResult, strlen(cResult));
			Py_XDECREF(pResult);
		}

		PyThreadState_Swap(NULL);
		PyEval_ReleaseLock();
//.........这里部分代码省略.........
开发者ID:flyingtime,项目名称:boxee,代码行数:101,代码来源:SpyceModule.cpp

示例2: PyInt_FromLong

static PyObject *t_resourcebundle_getType(t_resourcebundle *self)
{
    return PyInt_FromLong((long) self->object->getType());
}
开发者ID:kluge-iitk,项目名称:pyicu,代码行数:4,代码来源:locale.cpp

示例3: Snmp_updatereactor

static int
Snmp_updatereactor(void)
{
	int maxfd = 0, block = 0, fd, result, i;
	PyObject *keys, *key, *tmp;
	SnmpReaderObject *reader;
	fd_set fdset;
	struct timeval timeout;
	double to;

	FD_ZERO(&fdset);
	block = 1;		/* This means we don't have a timeout
				   planned. block will be reset to 0
				   if we need to setup a timeout. */
	snmp_select_info(&maxfd, &fdset, &timeout, &block);
	for (fd = 0; fd < maxfd; fd++) {
		if (FD_ISSET(fd, &fdset)) {
			result = PyDict_Contains(SnmpFds, PyInt_FromLong(fd));
			if (result == -1)
				return -1;
			if (!result) {
				/* Add this fd to the reactor */
				if ((reader = (SnmpReaderObject *)
					PyObject_CallObject((PyObject *)&SnmpReaderType,
					    NULL)) == NULL)
					return -1;
				reader->fd = fd;
				if ((key =
					PyInt_FromLong(fd)) == NULL) {
					Py_DECREF(reader);
					return -1;
				}
				if (PyDict_SetItem(SnmpFds, key, (PyObject*)reader) != 0) {
					Py_DECREF(reader);
					Py_DECREF(key);
					return -1;
				}
				Py_DECREF(key);
				if ((tmp = PyObject_CallMethod(reactor,
					    "addReader", "O", (PyObject*)reader)) ==
				    NULL) {
					Py_DECREF(reader);
					return -1;
				}
				Py_DECREF(tmp);
				Py_DECREF(reader);
			}
		}
	}
	if ((keys = PyDict_Keys(SnmpFds)) == NULL)
		return -1;
	for (i = 0; i < PyList_Size(keys); i++) {
		if ((key = PyList_GetItem(keys, i)) == NULL) {
			Py_DECREF(keys);
			return -1;
		}
		fd = PyInt_AsLong(key);
		if (PyErr_Occurred()) {
			Py_DECREF(keys);
			return -1;
		}
		if ((fd >= maxfd) || (!FD_ISSET(fd, &fdset))) {
			/* Delete this fd from the reactor */
			if ((reader = (SnmpReaderObject*)PyDict_GetItem(SnmpFds,
				    key)) == NULL) {
				Py_DECREF(keys);
				return -1;
			}
			if ((tmp = PyObject_CallMethod(reactor,
				    "removeReader", "O", (PyObject*)reader)) == NULL) {
				Py_DECREF(keys);
				return -1;
			}
			Py_DECREF(tmp);
			if (PyDict_DelItem(SnmpFds, key) == -1) {
				Py_DECREF(keys);
				return -1;
			}
		}
	}
	Py_DECREF(keys);
	/* Setup timeout */
	if (timeoutId) {
		if ((tmp = PyObject_CallMethod(timeoutId, "cancel", NULL)) == NULL) {
			/* Don't really know what to do. It seems better to
			 * raise an exception at this point. */
			Py_CLEAR(timeoutId);
			return -1;
		}
		Py_DECREF(tmp);
		Py_CLEAR(timeoutId);
	}
	if (!block) {
		to = (double)timeout.tv_sec +
		    (double)timeout.tv_usec/(double)1000000;
		if ((timeoutId = PyObject_CallMethod(reactor, "callLater", "dO",
			    to, timeoutFunction)) == NULL) {
			return -1;
		}
	}
//.........这里部分代码省略.........
开发者ID:arielsalvo,项目名称:wiremaps,代码行数:101,代码来源:snmp.c

示例4: archpy_disassemble


//.........这里部分代码省略.........

          return NULL;
        }

      if (end < start)
        {
          Py_DECREF (end_obj);
          Py_XDECREF (count_obj);
          PyErr_SetString (PyExc_ValueError,
                           _("Argument 'end_pc' should be greater than or "
                             "equal to the argument 'start_pc'."));

          return NULL;
        }
    }
  if (count_obj)
    {
      count = PyInt_AsLong (count_obj);
      if (PyErr_Occurred () || count < 0)
        {
          Py_DECREF (count_obj);
          Py_XDECREF (end_obj);
          PyErr_SetString (PyExc_TypeError,
                           _("Argument 'count' should be an non-negative "
                             "integer."));

          return NULL;
        }
    }

  result_list = PyList_New (0);
  if (result_list == NULL)
    return NULL;

  for (pc = start, i = 0;
       /* All args are specified.  */
       (end_obj && count_obj && pc <= end && i < count)
       /* end_pc is specified, but no count.  */
       || (end_obj && count_obj == NULL && pc <= end)
       /* end_pc is not specified, but a count is.  */
       || (end_obj == NULL && count_obj && i < count)
       /* Both end_pc and count are not specified.  */
       || (end_obj == NULL && count_obj == NULL && pc == start);)
    {
      int insn_len = 0;
      char *as = NULL;
      struct ui_file *memfile = mem_fileopen ();
      PyObject *insn_dict = PyDict_New ();
      volatile struct gdb_exception except;

      if (insn_dict == NULL)
        {
          Py_DECREF (result_list);
          ui_file_delete (memfile);

          return NULL;
        }
      if (PyList_Append (result_list, insn_dict))
        {
          Py_DECREF (result_list);
          Py_DECREF (insn_dict);
          ui_file_delete (memfile);

          return NULL;  /* PyList_Append Sets the exception.  */
        }

      TRY_CATCH (except, RETURN_MASK_ALL)
        {
          insn_len = gdb_print_insn (gdbarch, pc, memfile, NULL);
        }
      if (except.reason < 0)
        {
          Py_DECREF (result_list);
          ui_file_delete (memfile);

	  gdbpy_convert_exception (except);
	  return NULL;
        }

      as = ui_file_xstrdup (memfile, NULL);
      if (PyDict_SetItemString (insn_dict, "addr",
                                gdb_py_long_from_ulongest (pc))
          || PyDict_SetItemString (insn_dict, "asm",
                                   PyString_FromString (*as ? as : "<unknown>"))
          || PyDict_SetItemString (insn_dict, "length",
                                   PyInt_FromLong (insn_len)))
        {
          Py_DECREF (result_list);

          ui_file_delete (memfile);
          xfree (as);

          return NULL;
        }

      pc += insn_len;
      i++;
      ui_file_delete (memfile);
      xfree (as);
    }
开发者ID:Xilinx,项目名称:gdb,代码行数:101,代码来源:py-arch.c

示例5: PyInt_FromLong

PyObject *scribus_pagecount(PyObject* /* self */)
{
	if(!checkHaveDocument())
		return NULL;
	return PyInt_FromLong(static_cast<long>(ScCore->primaryMainWindow()->doc->Pages->count()));
}
开发者ID:moceap,项目名称:scribus,代码行数:6,代码来源:cmdpage.cpp

示例6: Snmp_handle

static int
Snmp_handle(int operation, netsnmp_session *session, int reqid,
    netsnmp_pdu *response, void *magic)
{
	PyObject *key, *defer, *results = NULL, *resultvalue = NULL,
	    *resultoid = NULL, *tmp;
	struct ErrorException *e;
	struct variable_list *vars;
	int i;
	long long counter64;
	SnmpObject *self;

	if ((key = PyInt_FromLong(reqid)) == NULL)
		/* Unknown session, don't know what to do... */
		return 1;
	self = (SnmpObject *)magic;
	if ((defer = PyDict_GetItem(self->defers, key)) == NULL)
		return 1;
	Py_INCREF(defer);
	PyDict_DelItem(self->defers, key);
	Py_DECREF(key);
	/* We have our deferred object. We will be able to trigger callbacks and
	 * errbacks */
	if (operation == NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) {
		if (response->errstat != SNMP_ERR_NOERROR) {
			for (e = SnmpErrorToException; e->name; e++) {
				if (e->error == response->errstat) {
					PyErr_SetString(e->exception, snmp_errstring(e->error));
					goto fireexception;
				}
			}
			PyErr_Format(SnmpException, "unknown error %ld", response->errstat);
			goto fireexception;
		}
	} else {
		PyErr_SetString(SnmpException, "Timeout");
		goto fireexception;
	}
	if ((results = PyDict_New()) == NULL)
		goto fireexception;
	for (vars = response->variables; vars;
	     vars = vars->next_variable) {
	/* Let's handle the value */
		switch (vars->type) {
		case SNMP_NOSUCHOBJECT:
			PyErr_SetString(SnmpNoSuchObject, "No such object was found");
			goto fireexception;
		case SNMP_NOSUCHINSTANCE:
			PyErr_SetString(SnmpNoSuchInstance, "No such instance exists");
			goto fireexception;
		case SNMP_ENDOFMIBVIEW:
			if (PyDict_Size(results) == 0) {
				PyErr_SetString(SnmpEndOfMibView,
				    "End of MIB was reached");
				goto fireexception;
			} else
				continue;
		case ASN_INTEGER:
			resultvalue = PyLong_FromLong(*vars->val.integer);
			break;
		case ASN_UINTEGER:
		case ASN_TIMETICKS:
		case ASN_GAUGE:
		case ASN_COUNTER:
			resultvalue = PyLong_FromUnsignedLong(
				(unsigned long)*vars->val.integer);
			break;
		case ASN_OCTET_STR:
			resultvalue = PyString_FromStringAndSize(
				(char*)vars->val.string, vars->val_len);
			break;
		case ASN_BIT_STR:
			resultvalue = PyString_FromStringAndSize(
				(char*)vars->val.bitstring, vars->val_len);
			break;
		case ASN_OBJECT_ID:
			if ((resultvalue = PyTuple_New(
					vars->val_len/sizeof(oid))) == NULL)
				goto fireexception;
			for (i = 0; i < vars->val_len/sizeof(oid); i++) {
				if ((tmp = PyLong_FromLong(
						vars->val.objid[i])) == NULL)
					goto fireexception;
				PyTuple_SetItem(resultvalue, i, tmp);
			}
			if ((resultvalue = Snmp_oid2string(resultvalue)) == NULL)
				goto fireexception;
			break;
		case ASN_IPADDRESS:
			if (vars->val_len < 4) {
				PyErr_Format(SnmpException, "IP address is too short (%zd < 4)",
				    vars->val_len);
				goto fireexception;
			}
			resultvalue = PyString_FromFormat("%d.%d.%d.%d",
			    vars->val.string[0],
			    vars->val.string[1],
			    vars->val.string[2],
			    vars->val.string[3]);
			break;
//.........这里部分代码省略.........
开发者ID:arielsalvo,项目名称:wiremaps,代码行数:101,代码来源:snmp.c

示例7: _cd_getnumtracks

static PyObject*
_cd_getnumtracks (PyObject *self, void *closure)
{
    ASSERT_CDROM_OPEN(self, NULL);
    return PyInt_FromLong (((PyCD*)self)->cd->numtracks);
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:6,代码来源:cdrom.c

示例8: _cd_getcurframe

static PyObject*
_cd_getcurframe (PyObject *self, void *closure)
{
    ASSERT_CDROM_OPEN(self, NULL);
    return PyInt_FromLong (((PyCD*)self)->cd->cur_frame);
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:6,代码来源:cdrom.c

示例9: _cd_getindex

static PyObject*
_cd_getindex (PyObject *self, void *closure)
{
    ASSERT_CDROM_INIT(NULL);
    return PyInt_FromLong (((PyCD*)self)->index);
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:6,代码来源:cdrom.c

示例10: _cd_getstatus

static PyObject*
_cd_getstatus (PyObject *self, void *closure)
{
    ASSERT_CDROM_OPEN(self, NULL);
    return PyInt_FromLong (SDL_CDStatus (((PyCD*)self)->cd));
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:6,代码来源:cdrom.c

示例11: Py_INCREF

/* Implementation of baas2 */

static PyObject *__pyx_f_5baas2_bar(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_5baas2_bar(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_a;
  int __pyx_v_b;
  PyObject *__pyx_v_values;
  PyObject *__pyx_v_dummy;
  PyObject *__pyx_v_tup;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_4;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  __pyx_v_values = Py_None; Py_INCREF(Py_None);
  __pyx_v_dummy = Py_None; Py_INCREF(Py_None);
  __pyx_v_tup = Py_None; Py_INCREF(Py_None);

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/baas/baas2.pyx":4 */
  __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;}
  __pyx_2 = PyInt_FromLong(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_1);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
  __pyx_1 = 0;
  __pyx_2 = 0;
  Py_DECREF(__pyx_v_values);
  __pyx_v_values = __pyx_3;
  __pyx_3 = 0;

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/baas/baas2.pyx":5 */
  __pyx_1 = PyFloat_FromDouble(1.0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}
  Py_DECREF(__pyx_v_dummy);
  __pyx_v_dummy = __pyx_1;
  __pyx_1 = 0;

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/baas/baas2.pyx":7 */
  __pyx_2 = PyInt_FromLong(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  __pyx_3 = PyObject_GetItem(__pyx_v_values, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_4 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_v_a = __pyx_4;

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/baas/baas2.pyx":8 */
  __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  __pyx_2 = PyObject_GetItem(__pyx_v_values, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_v_b = __pyx_4;

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/baas/baas2.pyx":10 */
  __pyx_1 = PyInt_FromLong(__pyx_v_a); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  __pyx_2 = PyInt_FromLong(__pyx_v_b); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_1);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
  __pyx_1 = 0;
  __pyx_2 = 0;
  Py_DECREF(__pyx_v_tup);
  __pyx_v_tup = __pyx_3;
  __pyx_3 = 0;

  /* "/Local/Projects/D/Pyrex/Source/Tests/Bugs/baas/baas2.pyx":11 */
  if (__Pyx_PrintItem(__pyx_v_tup) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;}
  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; goto __pyx_L1;}

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("baas2.bar");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_values);
  Py_DECREF(__pyx_v_dummy);
  Py_DECREF(__pyx_v_tup);
  return __pyx_r;
}
开发者ID:jwilk,项目名称:Pyrex,代码行数:84,代码来源:baas2.c

示例12: switch

// @object PyADSVALUE|A tuple:
// @tupleitem 0|object|value|The value as a Python object.
// @tupleitem 1|int|type|The AD type of the value.
PyObject *PyADSIObject_FromADSVALUE(ADSVALUE &v)
{
	PyObject *ob = NULL;
	switch (v.dwType) {
		case ADSTYPE_DN_STRING:
			ob = PyWinObject_FromWCHAR(v.DNString);
			break;
		case ADSTYPE_CASE_EXACT_STRING:
			ob = PyWinObject_FromWCHAR(v.CaseExactString);
			break;
		case ADSTYPE_CASE_IGNORE_STRING:
			ob = PyWinObject_FromWCHAR(v.CaseIgnoreString);
			break;
		case ADSTYPE_PRINTABLE_STRING:
			ob = PyWinObject_FromWCHAR(v.PrintableString);
			break;
		case ADSTYPE_NUMERIC_STRING:
			ob = PyWinObject_FromWCHAR(v.NumericString);
			break;
		case ADSTYPE_BOOLEAN:
			ob = v.Boolean ? Py_True : Py_False;
			Py_INCREF(ob);
			break;
		case ADSTYPE_INTEGER:
			ob = PyInt_FromLong(v.Integer);
			break;
		case ADSTYPE_OCTET_STRING:
			{
			void *buf;
			DWORD bufSize = v.OctetString.dwLength;
			if (!(ob=PyBuffer_New(bufSize)))
				return NULL;
			if (!PyWinObject_AsWriteBuffer(ob, &buf, &bufSize)){
				Py_DECREF(ob);
				return NULL;
				}
			memcpy(buf, v.OctetString.lpValue, bufSize);
			}
			break;
		case ADSTYPE_UTC_TIME:
			ob = PyWinObject_FromSYSTEMTIME(v.UTCTime);
			break;
		case ADSTYPE_LARGE_INTEGER:
			ob = PyWinObject_FromLARGE_INTEGER(v.LargeInteger);
			break;
		case ADSTYPE_OBJECT_CLASS:
			ob = PyWinObject_FromWCHAR(v.ClassName);
			break;
		case ADSTYPE_PROV_SPECIFIC:
			{
			void *buf;
			DWORD bufSize = v.ProviderSpecific.dwLength;
			if (!(ob=PyBuffer_New(bufSize)))
				return NULL;
			if (!PyWinObject_AsWriteBuffer(ob, &buf, &bufSize)){
				Py_DECREF(ob);
				return NULL;
			}
			memcpy(buf, v.ProviderSpecific.lpValue, bufSize);
			break;
			}
		case ADSTYPE_NT_SECURITY_DESCRIPTOR:
			{
			// Get a pointer to the security descriptor.
			PSECURITY_DESCRIPTOR pSD = (PSECURITY_DESCRIPTOR)(v.SecurityDescriptor.lpValue);
			DWORD SDSize = v.SecurityDescriptor.dwLength;
			// eeek - we don't pass the length - pywintypes relies on
			// GetSecurityDescriptorLength - make noise if this may bite us.
			if (SDSize != GetSecurityDescriptorLength(pSD))
				PyErr_Warn(PyExc_RuntimeWarning, "Security-descriptor size mis-match");
			ob = PyWinObject_FromSECURITY_DESCRIPTOR(pSD);
			break;
			}
		default:
			{
			char msg[100];
			sprintf(msg, "Unknown ADS type code 0x%x - None will be returned", v.dwType);
			PyErr_Warn(PyExc_RuntimeWarning, msg);
			ob = Py_None;
			Py_INCREF(ob);
		}
	}
	if (ob==NULL)
		return NULL;
	PyObject *ret = Py_BuildValue("Oi", ob, (int)v.dwType);
	Py_DECREF(ob);
	return ret;
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:91,代码来源:PyADSIUtil.cpp

示例13: initkerberos

PyMODINIT_FUNC initkerberos(void)
{
    PyObject *m,*d;

    m = Py_InitModule("kerberos", KerberosMethods);

    d = PyModule_GetDict(m);

    /* create the base exception class */
    if (!(KrbException_class = PyErr_NewException("kerberos.KrbError", NULL, NULL)))
        goto error;
    PyDict_SetItemString(d, "KrbError", KrbException_class);
    Py_INCREF(KrbException_class);

    /* ...and the derived exceptions */
    if (!(BasicAuthException_class = PyErr_NewException("kerberos.BasicAuthError", KrbException_class, NULL)))
        goto error;
    Py_INCREF(BasicAuthException_class);
    PyDict_SetItemString(d, "BasicAuthError", BasicAuthException_class);

    if (!(PwdChangeException_class = PyErr_NewException("kerberos.PwdChangeError", KrbException_class, NULL)))
        goto error;
    Py_INCREF(PwdChangeException_class);
    PyDict_SetItemString(d, "PwdChangeError", PwdChangeException_class);

    if (!(GssException_class = PyErr_NewException("kerberos.GSSError", KrbException_class, NULL)))
        goto error;
    Py_INCREF(GssException_class);
    PyDict_SetItemString(d, "GSSError", GssException_class);

    PyDict_SetItemString(d, "AUTH_GSS_COMPLETE", PyInt_FromLong(AUTH_GSS_COMPLETE));
    PyDict_SetItemString(d, "AUTH_GSS_CONTINUE", PyInt_FromLong(AUTH_GSS_CONTINUE));

    PyDict_SetItemString(d, "GSS_C_DELEG_FLAG", PyInt_FromLong(GSS_C_DELEG_FLAG));
    PyDict_SetItemString(d, "GSS_C_MUTUAL_FLAG", PyInt_FromLong(GSS_C_MUTUAL_FLAG));
    PyDict_SetItemString(d, "GSS_C_REPLAY_FLAG", PyInt_FromLong(GSS_C_REPLAY_FLAG));
    PyDict_SetItemString(d, "GSS_C_SEQUENCE_FLAG", PyInt_FromLong(GSS_C_SEQUENCE_FLAG));
    PyDict_SetItemString(d, "GSS_C_CONF_FLAG", PyInt_FromLong(GSS_C_CONF_FLAG));
    PyDict_SetItemString(d, "GSS_C_INTEG_FLAG", PyInt_FromLong(GSS_C_INTEG_FLAG));
    PyDict_SetItemString(d, "GSS_C_ANON_FLAG", PyInt_FromLong(GSS_C_ANON_FLAG));
    PyDict_SetItemString(d, "GSS_C_PROT_READY_FLAG", PyInt_FromLong(GSS_C_PROT_READY_FLAG));
    PyDict_SetItemString(d, "GSS_C_TRANS_FLAG", PyInt_FromLong(GSS_C_TRANS_FLAG));

error:
    if (PyErr_Occurred())
        PyErr_SetString(PyExc_ImportError, "kerberos: init failed");
}
开发者ID:prashanthpai,项目名称:PyKerberos,代码行数:47,代码来源:kerberos.c

示例14: conn_notifies_process

void
conn_notifies_process(connectionObject *self)
{
    PGnotify *pgn = NULL;
    PyObject *notify = NULL;
    PyObject *pid = NULL, *channel = NULL, *payload = NULL;
    PyObject *tmp = NULL;

    static PyObject *append;

    if (!append) {
        if (!(append = Text_FromUTF8("append"))) {
            goto error;
        }
    }

    while ((pgn = PQnotifies(self->pgconn)) != NULL) {

        Dprintf("conn_notifies_process: got NOTIFY from pid %d, msg = %s",
                (int) pgn->be_pid, pgn->relname);

        if (!(pid = PyInt_FromLong((long)pgn->be_pid))) {
            goto error;
        }
        if (!(channel = conn_text_from_chars(self, pgn->relname))) {
            goto error;
        }
        if (!(payload = conn_text_from_chars(self, pgn->extra))) {
            goto error;
        }

        if (!(notify = PyObject_CallFunctionObjArgs((PyObject *)&notifyType,
                       pid, channel, payload, NULL))) {
            goto error;
        }

        Py_DECREF(pid);
        pid = NULL;
        Py_DECREF(channel);
        channel = NULL;
        Py_DECREF(payload);
        payload = NULL;

        if (!(tmp = PyObject_CallMethodObjArgs(
                        self->notifies, append, notify, NULL))) {
            goto error;
        }
        Py_DECREF(tmp);
        tmp = NULL;

        Py_DECREF(notify);
        notify = NULL;
        PQfreemem(pgn);
        pgn = NULL;
    }
    return;  /* no error */

error:
    if (pgn) {
        PQfreemem(pgn);
    }
    Py_XDECREF(tmp);
    Py_XDECREF(notify);
    Py_XDECREF(pid);
    Py_XDECREF(channel);
    Py_XDECREF(payload);

    /* TODO: callers currently don't expect an error from us */
    PyErr_Clear();

}
开发者ID:alfiesyukur,项目名称:psycopg2,代码行数:71,代码来源:connection_int.c

示例15: make_public_browseable

static PyObject *
make_public_browseable (WCSdpServicePyObject *self)
{
    SDP_RETURN_CODE result = self->sdpservice->MakePublicBrowseable ();
    return PyInt_FromLong (result);
}
开发者ID:AldwinP,项目名称:pybluez,代码行数:6,代码来源:sdpservice.cpp


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