• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyString_Size函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: PyTokenizer_RestoreEncoding

char *
PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int *offset)
{
	char *text = NULL;
	if (tok->encoding) {
		/* convert source to original encondig */
		PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);
		if (lineobj != NULL) {
			int linelen = PyString_Size(lineobj);
			const char *line = PyString_AsString(lineobj);
			text = PyObject_MALLOC(linelen + 1);
			if (text != NULL && line != NULL) {
				if (linelen)
					strncpy(text, line, linelen);
				text[linelen] = '\0';
			}
			Py_DECREF(lineobj);
					
			/* adjust error offset */
			if (*offset > 1) {
				PyObject *offsetobj = dec_utf8(tok->encoding, 
							       tok->buf, *offset-1);
				if (offsetobj) {
					*offset = PyString_Size(offsetobj) + 1;
					Py_DECREF(offsetobj);
				}
			}
			
		}
	}
	return text;

}
开发者ID:CRYPTOlab,项目名称:python-resin,代码行数:33,代码来源:tokenizer.c


示例2: pycalcsims16

/* pycalcsims16(window, data1, offset1, data2, offset2); */
static PyObject* pycalcsims16(PyObject* self, PyObject* args)
{
    int window;
    PyObject* data1;
    PyObject* data2;
    int offset1;
    int offset2;

    if (!PyArg_ParseTuple(args, "iOiOi", &window, 
			  &data1, &offset1, &data2, &offset2)) {
	return NULL;
    }

    if (!PyString_CheckExact(data1) ||
	!PyString_CheckExact(data2)) {
	PyErr_SetString(PyExc_TypeError, "Must be string");
	return NULL;
    }

    int length1 = PyString_Size(data1) / sizeof(short);
    int length2 = PyString_Size(data2) / sizeof(short);
    if (window < 0 ||
	offset1 < 0 || length1 < offset1+window ||
	offset2 < 0 || length2 < offset2+window) {
	PyErr_SetString(PyExc_ValueError, "Invalid offset/window");
	return NULL;
    }

    short* seq1 = (short*)PyString_AsString(data1);
    short* seq2 = (short*)PyString_AsString(data2);
    double sim = calcsims16(window, &seq1[offset1], &seq2[offset2]);

    return PyFloat_FromDouble(sim);
}
开发者ID:euske,项目名称:hum2midi,代码行数:35,代码来源:wavcorr.c


示例3: ctrlp_comp_alpha

// comparison function for use with qsort
int ctrlp_comp_alpha(const void *a, const void *b) {
    matchobj_t a_val = *(matchobj_t *)a;
    matchobj_t b_val = *(matchobj_t *)b;

    char *a_p = PyString_AsString(a_val.str);
    long a_len = PyString_Size(a_val.str);
    char *b_p = PyString_AsString(b_val.str);
    long b_len = PyString_Size(b_val.str);

    int order = 0;
    if (a_len > b_len) {
        order = strncmp(a_p, b_p, b_len);
        if (order == 0)
            order = 1; // shorter string (b) wins
    }
    else if (a_len < b_len) {
        order = strncmp(a_p, b_p, a_len);
        if (order == 0)
            order = -1; // shorter string (a) wins
    }
    else {
        order = strncmp(a_p, b_p, a_len);
    }

    return order;
}
开发者ID:JazzCore,项目名称:ctrlp-cmatcher,代码行数:27,代码来源:fuzzycomt.c


示例4: SetExtraData

// ---------------------------------------------------------------------------------
int SetExtraData( AVCodecContext *cCodec, PyObject* cObj )
{
	PyObject* obj =PyDict_GetItemString(cObj,EXTRA_DATA);
	if (!obj || !PyString_Check(obj))
	  return 0;

	cCodec->extradata= av_malloc( PyString_Size( obj ));
	if( !cCodec->extradata )
		return -1;
	cCodec->extradata_size= PyString_Size( obj );
	memcpy( cCodec->extradata, PyString_AsString( obj ), cCodec->extradata_size );
	return 1;
}
开发者ID:gromaudio,项目名称:dashtest,代码行数:14,代码来源:acodec.c


示例5: PyMAPIObject_AsSBinaryArray

// @object PySBinaryArray|A sequence of strings containing binary data.
BOOL PyMAPIObject_AsSBinaryArray(PyObject *ob, SBinaryArray *pba)
{
    BOOL bSeq = TRUE;
    int seqLen;
    if (PyString_Check(ob)) {
        seqLen = 1;
        bSeq = FALSE;
    } else if (PySequence_Check(ob)) {
        seqLen = PySequence_Length(ob);
    } else {
        PyErr_SetString(PyExc_TypeError, "SBinaryArray must be a sequence of strings");
        return FALSE;
    }
    DWORD cBytes = (seqLen * sizeof(SBinary));
    SBinary *pBin;
    HRESULT hr = MAPIAllocateBuffer(cBytes, (void **)&pBin);
    pba->lpbin = pBin;
    if (FAILED(hr)) {
        OleSetOleError(hr);
        return FALSE;
    }
    pba->cValues = seqLen;
    if (bSeq) {
        for (ULONG i=0; i<(ULONG)seqLen; i++) {
            PyObject *obItem = PySequence_GetItem(ob, i);
            if (obItem==NULL) {
                MAPIFreeBuffer(pba);
                return FALSE;
            }
            if (!PyString_Check(obItem)) {
                PyErr_SetString(PyExc_TypeError, "SBinary must be a string");
                Py_DECREF(obItem);
                MAPIFreeBuffer(pba);
                return FALSE;
            }
            pBin[i].cb = PyString_Size(obItem);
            pBin[i].lpb = (LPBYTE )PyString_AsString(obItem);
            Py_DECREF(obItem);
        }
    } else {
        if (!PyString_Check(ob)) {
            PyErr_SetString(PyExc_TypeError, "SBinary must be a string");
            MAPIFreeBuffer(pba);
            return FALSE;
        }
        // Simple string
        pBin[0].cb = PyString_Size(ob);
        pBin[0].lpb = (LPBYTE)PyString_AsString(ob);
    }
    return TRUE;
}
开发者ID:mcg1969,项目名称:pywin32,代码行数:52,代码来源:mapiutil.cpp


示例6: PyErr_SetString

static PyObject *secure_compare(PyObject *self, PyObject *args)
{
    PyObject *temp_string_one;
    PyObject *temp_string_two;
    Py_ssize_t string_size;
    volatile const unsigned char *left;
    volatile const unsigned char *right;
    volatile unsigned char sentinel = 0;

    int i; /* for use in loops */

    /* How many arguments were provided to the function */
    if (PyTuple_Size(args) != 2)
    {
        PyErr_SetString(PyExc_ValueError, "You must only supply 2 arguments");
        return NULL;
    }
    /* Can we parse them? */
    if (!PyArg_ParseTuple(args, "OO", &temp_string_one, &temp_string_two)) 
    {
        PyErr_SetString(PyExc_TypeError, "Unable To Parse Function Arguments");
        return NULL;
    }

    /* Are they Python Strings */
    if (!(PyString_CheckExact(temp_string_one)) || !(PyString_CheckExact(temp_string_two))) 
    {
        PyErr_SetString(PyExc_TypeError, "You must supply 2 string objects");
        return NULL;   
    } 

    /* Are they the same size? */
    if (PyString_Size(temp_string_one) != PyString_Size(temp_string_two)) 
    {
        Py_RETURN_FALSE;
    }

    
    left = (const volatile unsigned char *) PyString_AsString(temp_string_one);
    right = (const volatile unsigned char *) PyString_AsString(temp_string_two);
    string_size = PyString_Size(temp_string_one);

    for(i = 0; i < string_size; i++)
    {
        sentinel |= *left++ ^ *right++;
    }

    return constant_byte_compare(sentinel, 0);
}
开发者ID:levigross,项目名称:constant_time_compare,代码行数:49,代码来源:constant_time_compare.c


示例7: uwsgi_request_marshal

/* uwsgi MARSHAL|33 */
int uwsgi_request_marshal(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
	PyObject *func_result;

	PyObject *umm = PyDict_GetItemString(uwsgi->embedded_dict,
					     "message_manager_marshal");
	if (umm) {
		PyObject *ummo = PyMarshal_ReadObjectFromString(wsgi_req->buffer,
								wsgi_req->uh.pktsize);
		if (ummo) {
			if (!PyTuple_SetItem(uwsgi->embedded_args, 0, ummo)) {
				if (!PyTuple_SetItem(uwsgi->embedded_args, 1, PyInt_FromLong(wsgi_req->uh.modifier2))) {
					func_result = PyEval_CallObject(umm, uwsgi->embedded_args);
					if (PyErr_Occurred()) {
						PyErr_Print();
					}
					if (func_result) {
						PyObject *marshalled = PyMarshal_WriteObjectToString(func_result, 1);
						if (!marshalled) {
							PyErr_Print();
						}
						else {
							if (PyString_Size(marshalled) <= 0xFFFF) {
								wsgi_req->uh.pktsize = (uint16_t)
									PyString_Size(marshalled);
								if (write(wsgi_req->poll.fd, wsgi_req, 4) == 4) {
									if (write(wsgi_req->poll.fd, PyString_AsString(marshalled), wsgi_req->uh.pktsize) != wsgi_req->uh.pktsize) {
										uwsgi_error("write()");
									}
								}
								else {
									uwsgi_error("write()");
								}
							}
							else {
								fprintf(stderr, "marshalled object is too big. skip\n");
							}
							Py_DECREF(marshalled);
						}
						Py_DECREF(func_result);
					}
				}
			}
			//Py_DECREF(ummo);
		}
	}
	PyErr_Clear();

	return 0;
}
开发者ID:mlzboy,项目名称:resys,代码行数:50,代码来源:uwsgi_handlers.c


示例8: to_javascript_object

static jsval to_javascript_object(JSContext *context, PyObject *value) {
    if (PyString_Check(value)) {
        JSString *obj = JS_NewStringCopyN(context, PyString_AsString(value), PyString_Size(value));
        return STRING_TO_JSVAL(obj);
    } else if (PyUnicode_Check(value)) {
        PyObject *encoded = PyUnicode_AsUTF8String(value);
        JSString *obj = JS_NewStringCopyN(context, PyString_AsString(encoded), PyString_Size(encoded));
        Py_DECREF(encoded);
        return STRING_TO_JSVAL(obj);
    } else if (PyFloat_Check(value)) {
        return DOUBLE_TO_JSVAL(PyFloat_AsDouble(value));
    } else if (PyInt_Check(value)) {
        return INT_TO_JSVAL(PyInt_AsLong(value));
    } else if (PyLong_Check(value)) {
        return INT_TO_JSVAL(PyLong_AsLong(value));
    } else if (PyList_Check(value)) {
        JSObject *obj = JS_NewArrayObject(context, 0, NULL);
        int i;
        for (i = 0; i < PyList_Size(value); i++) {
            jsval item = to_javascript_object(context, PyList_GetItem(value, i));
            JS_SetElement(context, obj, i, &item);
        }
        return OBJECT_TO_JSVAL(obj);
    } else if (PyTuple_Check(value)) {
        JSObject *obj = JS_NewArrayObject(context, 0, NULL);
        int i;
        for (i = 0; i < PyTuple_Size(value); i++) {
            jsval item = to_javascript_object(context, PyTuple_GetItem(value, i));
            JS_SetElement(context, obj, i, &item);
        }
        return OBJECT_TO_JSVAL(obj);
    } else if (PyDict_Check(value)) {
        JSObject *obj = JS_NewObject(context, NULL, NULL, NULL);
        populate_javascript_object(context, obj, value);
        return OBJECT_TO_JSVAL(obj);
    } else if (PyDateTime_Check(value)) {
        JSObject *obj = JS_NewDateObject(context,
            PyDateTime_GET_YEAR(value),
            PyDateTime_GET_MONTH(value) - 1,
            PyDateTime_GET_DAY(value),
            PyDateTime_DATE_GET_HOUR(value),
            PyDateTime_DATE_GET_MINUTE(value),
            PyDateTime_DATE_GET_SECOND(value));
        return OBJECT_TO_JSVAL(obj);
    } else {
        return JSVAL_NULL;
    }
}
开发者ID:jordanm,项目名称:spindly,代码行数:48,代码来源:spindly.c


示例9: py_current_wsgi_req

PyObject *py_uwsgi_write(PyObject * self, PyObject * args) {
	PyObject *data;
	char *content;
	size_t content_len;

	struct wsgi_request *wsgi_req = py_current_wsgi_req();

	data = PyTuple_GetItem(args, 0);
	if (PyString_Check(data)) {
		content = PyString_AsString(data);
		content_len = PyString_Size(data);
		UWSGI_RELEASE_GIL
		uwsgi_response_write_body_do(wsgi_req, content, content_len);
		UWSGI_GET_GIL
		// this is a special case for the write callable
		// no need to honout write-errors-exception-only
		if (wsgi_req->write_errors > uwsgi.write_errors_tolerance && !uwsgi.disable_write_exception) {
                        uwsgi_py_write_set_exception(wsgi_req);
			return NULL;
		}
	}

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:EasyPost,项目名称:uwsgi,代码行数:25,代码来源:wsgi_handlers.c


示例10: PyList_New

static PyObject *uwsgi_Input_readlines(uwsgi_Input *self, PyObject *args) {

	long hint = 0;

        if (!PyArg_ParseTuple(args, "|l:readline", &hint)) {
                return NULL;
        }


	PyObject *res = PyList_New(0);
	for(;;) {
		PyObject *line = uwsgi_Input_getline(self, hint);
		if (!line) {
			Py_DECREF(res);
			return NULL;
		}
		if (PyString_Size(line) == 0) {
			Py_DECREF(line);
			return res;
		}
		PyList_Append(res, line);	
		Py_DECREF(line);
	}

	return res;
}
开发者ID:EasyPost,项目名称:uwsgi,代码行数:26,代码来源:wsgi_handlers.c


示例11: PyObject_CallFunction

/* Note that this always assumes in and out are sys.stdin and sys.stdout. */
static char *bits_readline_function(FILE *in, FILE *out, char *prompt)
{
    PyObject *pyret;
    Py_ssize_t len;
    char *temp;
    char *ret;

    (void)in;
    (void)out;

    pyret = PyObject_CallFunction(readline_callback, "s", prompt);

    if (!pyret)
        return NULL;
    if (!PyString_Check(pyret)) {
        PyErr_Format(PyExc_TypeError, "Python readline callback returned a non-string");
        return NULL;
    }
    temp = PyString_AsString(pyret);
    if (!temp)
        return NULL;
    len = PyString_Size(pyret);
    ret = PyMem_Malloc(len+1);
    if (!ret) {
        PyErr_NoMemory();
        return NULL;
    }
    return memcpy(ret, temp, len+1);
}
开发者ID:mfleming,项目名称:bits,代码行数:30,代码来源:bitsmodule.c


示例12: py_to_DEVICEMODE

BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict)
{
	PyObject *obj, *dict_copy = PyDict_Copy(dict);
	BOOL result = False;

	if (!(obj = PyDict_GetItemString(dict_copy, "private")))
		goto done;

	if (!PyString_Check(obj))
		goto done;

	devmode->dev_private = PyString_AsString(obj);
	devmode->driverextra = PyString_Size(obj);

	PyDict_DelItemString(dict_copy, "private");

	if (!to_struct(devmode, dict_copy, py_DEVICEMODE))
		goto done;

	result = True;

done:
	Py_DECREF(dict_copy);
	return result;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:25,代码来源:py_spoolss_printers_conv.c


示例13: CSVParser_iternext_filelike

static PyObject *
CSVParser_iternext_filelike(CSVParser *self)
{
    char *buf;
    char c;
    PyObject *fields = NULL;
    PyObject *lineobj = NULL;
    long i;
    long linelen;
    Logq_Engine_reset(self->engine);
    while(!self->engine->is_success){
        if (parse_reset(self) < 0)
            return NULL;
        do {
            lineobj = PyIter_Next(self->pyfile);
            if (lineobj == NULL) {
                /* End of input OR exception */
                if (!PyErr_Occurred() && (self->field_len != 0 ||
                                          self->state == IN_QUOTED_FIELD)) {
                    if (parse_save_field(self) >= 0 )
                        break;
                }
                return NULL;
            }
            ++self->line_num;

            buf = PyString_AsString(lineobj);
            linelen = PyString_Size(lineobj);

            if (buf == NULL || linelen < 0) {
                return NULL;
            }
            for(i=0; i<linelen; ++i){
                c = buf[i];
                if (c == '\0') {
                    Py_DECREF(lineobj);
                    PyErr_Format(csv_error_obj,
                                 "line contains NULL byte");
                    goto err;
                }
                if (parse_process_char(self, c) < 0) {
                    Py_DECREF(lineobj);
                    goto err;
                }
                //query fail. go next line
                if (self->state == QUERY_FAIL){
                    if(buf[linelen-1]=='\n'){
                        self->state = START_RECORD;
                    }
                    break;
                }
            }
            Py_DECREF(lineobj);
        } while (self->state != START_RECORD);
    }
    fields = self->fields;
    self->fields = NULL;
err:
    return fields;
}
开发者ID:takada-at,项目名称:logq,代码行数:60,代码来源:csv.c


示例14: pygimp_bilinear

static PyObject *
pygimp_bilinear(PyObject *self, PyObject *args, PyObject *kwargs)
{
    gdouble x, y;
    gdouble values[4];
    PyObject *py_values;
    static char *kwlist[] = { "x", "y", "values", NULL };

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "ddO:bilinear", kwlist,
				     &x, &y, &py_values))
  	return NULL;

    if (PyString_Check(py_values)) {
        if (PyString_Size(py_values) == 4) {
            guchar ret;
            ret = gimp_bilinear_8(x, y, (guchar *)PyString_AsString(py_values));
            return PyString_FromStringAndSize((char *)&ret, 1);
        }
    } else if (PySequence_Check(py_values)) {
        if (PySequence_Size(py_values) == 4) {
            int i;
            for (i = 0; i < 4; i++) {
                PyObject *v;
                v = PySequence_GetItem(py_values, i);
                values[i] = PyFloat_AsDouble(v);
                Py_DECREF(v);
            }
            return PyFloat_FromDouble(gimp_bilinear(x, y, values));
        }
    }

    PyErr_SetString(PyExc_TypeError, "values is not a sequence of 4 items");
    return NULL;
}
开发者ID:jiapei100,项目名称:gimp,代码行数:35,代码来源:gimpcolormodule.c


示例15: PyObject_CallMethod

int c4_PyStream::Read(void *buffer_, int length_) {
  PyObject *o = PyObject_CallMethod(_stream, "read", "i", length_);
  int n = o != 0 ? PyString_Size(o): 0;
  if (n > 0)
    memcpy(buffer_, PyString_AsString(o), n);
  return n;
}
开发者ID:azynheira,项目名称:metakit,代码行数:7,代码来源:PyStorage.cpp


示例16: find_builtin_names

static PyObject *
find_builtin_names(void)
{
	PyObject *builtins, *names, *key, *value;
	int pos = 0;
	builtins = PyEval_GetBuiltins();
	if (builtins == NULL || !PyDict_Check(builtins)) {
  		PyErr_SetString(PyExc_SystemError, "no builtins dict!");
		return NULL;
	}
	names = PyDict_New();
	if (names == NULL)
		return NULL;
	while (PyDict_Next(builtins, &pos, &key, &value)) {
		if (PyString_Check(key) &&
				PyString_Size(key) > 0 &&
				PyString_AS_STRING(key)[0] != '_') {
			if (PyDict_SetItem(names, key, Py_None) < 0) {
				Py_DECREF(names);
				return NULL;
			}
		}
	}
	return names;
}
开发者ID:akavel,项目名称:pltscheme-cvs-cvs2git-1,代码行数:25,代码来源:moduleobject.c


示例17: __Pyx_Print

static int __Pyx_Print(PyObject *arg_tuple, int newline) {
    PyObject *f;
    PyObject* v;
    int i;

    if (!(f = __Pyx_GetStdout()))
        return -1;
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                return -1;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            return -1;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0 &&
                isspace(Py_CHARMASK(s[len-1])) &&
                s[len-1] != ' ')
                    PyFile_SoftSpace(f, 0);
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            return -1;
        PyFile_SoftSpace(f, 0);
    }
    return 0;
}
开发者ID:wflynny,项目名称:spinwaves_git_final,代码行数:31,代码来源:hellow.c


示例18: PyString_AsBstr

// String conversions
// Convert a Python string object to a BSTR - allow embedded NULLs, etc.
static BOOL PyString_AsBstr(PyObject *stringObject, BSTR *pResult)
{
	int size=PyString_Size(stringObject);
	const char *buf = PyString_AsString(stringObject);
	if (buf==NULL) return FALSE;

	/* We assume that we dont need more 'wide characters' for the result
	   then the number of bytes in the input. Often we
	   will need less, as the input may contain multi-byte chars, but we
	   should never need more 
	*/

	LPWSTR wstr = (LPWSTR)malloc(size*sizeof(WCHAR));
	if (wstr==NULL) {
		PyErr_SetString(PyExc_MemoryError, "No memory for wide string buffer");
		return FALSE;
	}
	/* convert and get the final character size */
	size = MultiByteToWideChar(CP_ACP, 0, buf, size, wstr, size);
	*pResult = SysAllocStringLen(wstr, size);
	if (*pResult==NULL)
		PyErr_SetString(PyExc_MemoryError, "allocating BSTR");
	free(wstr);
	return *pResult != NULL;
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:27,代码来源:PyUnicode.cpp


示例19: PyWinObject_AsString

// Convert a Python object to a "char *" - allow embedded NULLs, None, etc.
BOOL PyWinObject_AsString(PyObject *stringObject, char **pResult, BOOL bNoneOK /*= FALSE*/, DWORD *pResultLen /* = NULL */)
{
	PyObject *tempObject = NULL;
	if (stringObject==Py_None) {
		if (!bNoneOK) {
			PyErr_SetString(PyExc_TypeError, "None is not a valid string in this context");
			return FALSE;
		}
		*pResult = NULL;
		if (pResultLen) *pResultLen = 0;
		return TRUE;
	}
	// Convert the string if a WIDE string.
	if (PyUnicode_Check(stringObject))
		stringObject = tempObject = PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(stringObject), PyUnicode_GET_SIZE(stringObject), NULL);

	if (!PyString_Check(stringObject)) {
		PyErr_Format(PyExc_TypeError, "The object must be a string or unicode object (got '%s')",
					 stringObject->ob_type->tp_name);
		return FALSE;
	}
	char *temp = PyString_AsString(stringObject);
	int len = PyString_Size(stringObject);
	*pResult = (char *)PyMem_Malloc(len+1);
	if (*pResult) {
		memcpy(*pResult, temp, len+1);
		if (pResultLen) *pResultLen = len;
	}
	Py_XDECREF(tempObject);
	return (*pResult != NULL);
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:32,代码来源:PyUnicode.cpp


示例20: logger

struct matcher_entry *matchers_get_response(u_char *data, u_int datalen, struct ctx *ctx, u_int type, u_int src_port, u_int dst_port)
{

    struct matcher_entry *matcher;

#ifdef HAVE_PYTHON
    PyObject *args;
    PyObject *value;
    Py_ssize_t rdatalen;
    char *rdata;
#endif

    if(!(matcher = matchers_match((const char *)data, datalen, ctx, type, src_port, dst_port))) {
        logger(DBG, "No matchers found for data");
        return NULL;
    }

#ifdef HAVE_PYTHON
    if(matcher->pyfunc) {
        logger(DBG, "We have a Python code to construct response");
        args = PyTuple_New(2);
        PyTuple_SetItem(args,0,PyString_FromStringAndSize((const char *)data, datalen)); // here is data
        PyTuple_SetItem(args,1,PyInt_FromSsize_t(datalen));

        value = PyObject_CallObject(matcher->pyfunc, args);
        if(value == NULL) {
            PyErr_Print();
            logger(WARN, "Python function returns no data!");
            return NULL;
        }

        rdata = PyString_AsString(value);
        rdatalen = PyString_Size(value);

        if(rdata != NULL && rdatalen > 0) {
            matcher->response_len = (u_int) rdatalen;
            if(matcher->response) {
                // We already have previous response, free it
                free(matcher->response);
            }
            matcher->response = malloc(matcher->response_len);
            memcpy(matcher->response, (u_char *) rdata, rdatalen);
        } else {
            PyErr_Print();
            logger(WARN, "Python cannot convert return string");
            return NULL;
        }
        return matcher;
    }
#endif

    if(matcher->response) {
        logger(DBG, "We have a plain text response");
        return matcher;
    }

    logger(WARN, "There is no response data!");
    return NULL;

}
开发者ID:DINKIN,项目名称:lrc,代码行数:60,代码来源:matchers.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyStructSequence_New函数代码示例发布时间:2022-05-30
下一篇:
C++ PyString_InternFromString函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap