Exemplo n.º 1
1
static PyObject *
PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
{
	char *effect;
#ifdef IS_PY3K
	PyObject *string = PyUnicode_AsUTF8String(args);
	if (string == NULL)
		return NULL;
	effect = PyBytes_AsString(string);
#else
	effect = PyString_AsString(args);
#endif
	bool result = self->obj->LoadFromMemory(effect);
#ifdef IS_PY3K
	Py_DECREF(string);
#endif
	return PyBool_FromLong(result);
}
Exemplo n.º 2
0
int
PyCode_Addr2Line(PyCodeObject *co, int addrq)
{
    Py_ssize_t size = PyBytes_Size(co->co_lnotab) / 2;
    unsigned char *p = (unsigned char*)PyBytes_AsString(co->co_lnotab);
    int line = co->co_firstlineno;
    int addr = 0;
    while (--size >= 0) {
        addr += *p++;
        if (addr > addrq)
            break;
        line += (signed char)*p;
        p++;
    }
    return line;
}
Exemplo n.º 3
0
/* Given a string buffer containing Python source code, compile it
   and return a code object as a new reference. */
static PyObject *
compile_source(PyObject *pathname, PyObject *source)
{
    PyObject *code, *fixed_source;

    fixed_source = normalize_line_endings(source);
    if (fixed_source == NULL) {
        return NULL;
    }

    code = Py_CompileStringObject(PyBytes_AsString(fixed_source),
                                  pathname, Py_file_input, NULL, -1);

    Py_DECREF(fixed_source);
    return code;
}
Exemplo n.º 4
0
static int
conv_pyobj_reg(PyObject *pyobj, unsigned long *reg)
{
#ifdef IS_PY3K
    if (PyLong_Check(pyobj)) {
#else
    if (PyLong_Check(pyobj) || PyInt_Check(pyobj)) {
#endif
        *reg = PyLong_AsUnsignedLong(pyobj);
    }
    else if (PyBool_Check(pyobj)) {
        *reg = (pyobj == Py_True) ? 1 : 0;
    }
    else if (PyBytes_Check(pyobj)) {
        *reg = (unsigned long)PyBytes_AsString(pyobj);
    }
    else {
        PyErr_SetString(PyExc_TypeError, "argument should be unsigned long, bool or bytes");
        return 0;
    }

    if (PyErr_Occurred()) {
        return 0;
    }

    return 1;
}

static int
build_regs(PyObject *args[NUM_REGS], regs_t *regs)
{
    unsigned long *regarray[NUM_REGS] = {&regs->rax, &regs->rbx, &regs->rcx, &regs->rdx, &regs->rsi, &regs->rdi};

    memset(regs, 0, sizeof(*regs));

    int i;
    for (i = 0; i < NUM_REGS; i++) {
        if (args[i] == NULL) {
            continue;
        }
        else if (!conv_pyobj_reg(args[i], regarray[i])) {
            return 0;
        }
    }

    return 1;
}
Exemplo n.º 5
0
//-------------------------------------------------------------------------------------
std::string Pickler::pickle(PyObject* pyobj, int8 protocol)
{
	PyObject* pyRet = PyObject_CallFunction(picklerMethod_, 
		const_cast<char*>("(Oi)"), pyobj, protocol);
	
	SCRIPT_ERROR_CHECK();
	
	if(pyRet)
	{
		std::string str;
		str.assign(PyBytes_AsString(pyRet), PyBytes_Size(pyRet));
		S_RELEASE(pyRet);
		return str;
	}
	
	return "";
}
Exemplo n.º 6
0
static inline void
pyobj2doc_pair(PyObject *key, PyObject *value, rapidjson::Document& doc)
{
    const char *key_string;
#ifdef PY3
    PyObject *utf8_item;
    utf8_item = PyUnicode_AsUTF8String(key);
    key_string = PyBytes_AsString(utf8_item);
#else
    key_string = PyString_AsString(key);
#endif
    rapidjson::Value s;
    s.SetString(key_string, doc.GetAllocator());
    rapidjson::Value _v;
    pyobj2doc(value, _v, doc);
    doc.AddMember(s, _v, doc.GetAllocator());
}
Exemplo n.º 7
0
//-------------------------------------------------------------------------------------
void TelnetHandler::processPythonCommand(std::string command)
{
	if(pTelnetServer_->pScript() == NULL || command.size() == 0)
		return;
	
	command += "\n";
	PyObject* pycmd = PyUnicode_DecodeUTF8(command.data(), command.size(), NULL);
	if(pycmd == NULL)
	{
		SCRIPT_ERROR_CHECK();
		return;
	}

	DEBUG_MSG(fmt::format("TelnetHandler::processPythonCommand: size({}), command={}.\n", 
		command.size(), command));

	std::string retbuf = "";
	PyObject* pycmd1 = PyUnicode_AsEncodedString(pycmd, "utf-8", NULL);

	pTelnetServer_->pScript()->run_simpleString(PyBytes_AsString(pycmd1), &retbuf);

	// 把返回值中的'\n'替換成'\r\n',以解决在vt100终端中显示不正确的问题
	std::string::size_type pos = 0;
	while ((pos = retbuf.find('\n', pos)) != std::string::npos)
	{
		if (retbuf[pos - 1] != '\r')
		{
			retbuf.insert(pos, "\r");
			pos++;
		}
		pos++;
	}

	if(retbuf.size() > 0)
	{
		// 将结果返回给客户端
		Network::Bundle* pBundle = Network::Bundle::createPoolObject();
		(*pBundle) << retbuf;
		pEndPoint_->send(pBundle);
		Network::Bundle::reclaimPoolObject(pBundle);
		sendEnter();
	}

	Py_DECREF(pycmd);
	Py_DECREF(pycmd1);
}
Exemplo n.º 8
0
// The Python simpleEnc function.
static PyObject *simpleEnc_encode(PyObject *self, PyObject *args) {

    PyBytesObject *srcObj;
    uint8_t *src;
    int srcSize;
    int pos;
    uint32_t numBytes;
    uint32_t matchPos;

    if (!PyArg_ParseTuple(args, "Oi", &srcObj, &pos))
        return NULL;

    src = (uint8_t *) PyBytes_AsString((PyObject*) srcObj);
    srcSize = PySequence_Length((PyObject*) srcObj);
    numBytes = simpleEnc(src, srcSize, pos, &matchPos);
    return Py_BuildValue("ii", numBytes, matchPos);
}
Exemplo n.º 9
0
char *GetCharFromDict(PyObject * dict, const char *key)
{
	PyObject *o, *o2 = NULL;
	char *ps = NULL, *result = NULL;
	size_t length;

	o = PyDict_GetItemString(dict, key);
	if (o == NULL) {
		PyErr_Format(PyExc_ValueError, "Missing key in dictionary: %s",
			     key);
		return NULL;
	}

	if (PyUnicode_Check(o)) {
		o2 = PyUnicode_AsASCIIString(o);
		if (o2 == NULL) {
			return NULL;
		}
		ps = PyBytes_AsString(o2);
	}
#if PY_MAJOR_VERSION < 3
	else if (PyString_Check(o)) {
		ps = PyString_AsString(o);
	}
#endif


	if (ps == NULL) {
		PyErr_Format(PyExc_ValueError,
			     "Can not get string value for key %s", key);
		goto out;
	}
	length = strlen(ps) + 1;
	result = (char *)malloc(length);
	if (result == NULL) {
		PyErr_Format(PyExc_ValueError, "Failed to allocate memory!");
		goto out;
	}
	memcpy(result, ps, length);

out:
	if (o2 != NULL) {
		Py_DECREF(o2);
	}
	return result;
}
Exemplo n.º 10
0
RPM_GNUC_NORETURN
static void die(PyObject *cb)
{
    char *pyfn = NULL;
    PyObject *r;

    if (PyErr_Occurred()) {
	PyErr_Print();
    }
    if ((r = PyObject_Repr(cb)) != NULL) { 
	pyfn = PyBytes_AsString(r);
    }
    fprintf(stderr, _("error: python callback %s failed, aborting!\n"), 
	    	      pyfn ? pyfn : "???");
    rpmdbCheckTerminate(1);
    exit(EXIT_FAILURE);
}
Exemplo n.º 11
0
PyObject *
getitem(_MetadataLocationObject *self, PyObject *pykey)
{
    char *key, *value;

    if (check_MetadataLocationStatus(self))
        return NULL;

    if (!PyUnicode_Check(pykey) && !PyBytes_Check(pykey)) {
        PyErr_SetString(PyExc_TypeError, "Unicode or bytes expected!");
        return NULL;
    }

    if (PyUnicode_Check(pykey)) {
        pykey = PyUnicode_AsUTF8String(pykey);
    }

    key = PyBytes_AsString(pykey);

    value = NULL;

    if (!strcmp(key, "primary")) {
        value = self->ml->pri_xml_href;
    } else if (!strcmp(key, "filelists")) {
        value = self->ml->fil_xml_href;
    } else if (!strcmp(key, "other")) {
        value = self->ml->oth_xml_href;
    } else if (!strcmp(key, "primary_db")) {
        value = self->ml->pri_sqlite_href;
    } else if (!strcmp(key, "filelists_db")) {
        value = self->ml->fil_sqlite_href;
    } else if (!strcmp(key, "other_db")) {
        value = self->ml->oth_sqlite_href;
    } else if (!strcmp(key, "group")) {
        value = self->ml->groupfile_href;
    } else if (!strcmp(key, "group_gz")) {
        value = self->ml->cgroupfile_href;
    } else if (!strcmp(key, "updateinfo")) {
        value = self->ml->updateinfo_href;
    }

    if (value)
        return PyUnicode_FromString(value);
    else
        Py_RETURN_NONE;
}
Exemplo n.º 12
0
PyObject *
Index__find(Index *self, PyObject *py_path)
{
    char *path;
    size_t idx;
    int err;

    path = PyBytes_AsString(py_path);
    if (!path)
        return NULL;

    err = git_index_find(&idx, self->index, path);
    if (err < 0)
        return Error_set_str(err, path);

    return PyLong_FromSize_t(idx);
}
Exemplo n.º 13
0
static PyObject *
read_history_file(PyObject *self, PyObject *args)
{
    PyObject *filename_obj = Py_None, *filename_bytes;
    if (!PyArg_ParseTuple(args, "|O:read_history_file", &filename_obj))
        return NULL;
    if (filename_obj != Py_None) {
        if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
            return NULL;
        errno = read_history(PyBytes_AsString(filename_bytes));
        Py_DECREF(filename_bytes);
    } else
        errno = read_history(NULL);
    if (errno)
        return PyErr_SetFromErrno(PyExc_IOError);
    Py_RETURN_NONE;
}
Exemplo n.º 14
0
const gchar *
_py_get_callable_name(PyObject *callable, gchar *buf, gsize buf_len)
{
  PyObject *name = PyObject_GetAttrString(callable, "__name__");

  if (name)
    {
      g_strlcpy(buf, PyBytes_AsString(name), buf_len);
    }
  else
    {
      PyErr_Clear();
      g_strlcpy(buf, "<unknown>", buf_len);
    }
  Py_XDECREF(name);
  return buf;
}
Exemplo n.º 15
0
/* Given the contents of a .py[co] file in a buffer, unmarshal the data
   and return the code object. Return None if it the magic word doesn't
   match (we do this instead of raising an exception as we fall back
   to .py if available and we don't want to mask other errors).
   Returns a new reference. */
static PyObject *
unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime)
{
    PyObject *code;
    unsigned char *buf = (unsigned char *)PyBytes_AsString(data);
    Py_ssize_t size = PyBytes_Size(data);

    if (size < 12) {
        PyErr_SetString(ZipImportError,
                        "bad pyc data");
        return NULL;
    }

    if (get_uint32(buf) != (unsigned int)PyImport_GetMagicNumber()) {
        if (Py_VerboseFlag) {
            PySys_FormatStderr("# %R has bad magic\n",
                               pathname);
        }
        Py_INCREF(Py_None);
        return Py_None;  /* signal caller to try alternative */
    }

    if (mtime != 0 && !eq_mtime(get_uint32(buf + 4), mtime)) {
        if (Py_VerboseFlag) {
            PySys_FormatStderr("# %R has bad mtime\n",
                               pathname);
        }
        Py_INCREF(Py_None);
        return Py_None;  /* signal caller to try alternative */
    }

    /* XXX the pyc's size field is ignored; timestamp collisions are probably
       unimportant with zip files. */
    code = PyMarshal_ReadObjectFromString((char *)buf + 12, size - 12);
    if (code == NULL) {
        return NULL;
    }
    if (!PyCode_Check(code)) {
        Py_DECREF(code);
        PyErr_Format(PyExc_TypeError,
             "compiled module %R is not a code object",
             pathname);
        return NULL;
    }
    return code;
}
Exemplo n.º 16
0
static PyObject *
patches(PyObject *self, PyObject *args)
{
	PyObject *text, *bins, *result;
	struct flist *patch;
	const char *in;
	char *out;
	Py_ssize_t len, outlen, inlen;

	if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
		return NULL;

	len = PyList_Size(bins);
	if (!len) {
		/* nothing to do */
		Py_INCREF(text);
		return text;
	}

	if (PyObject_AsCharBuffer(text, &in, &inlen))
		return NULL;

	patch = fold(bins, 0, len);
	if (!patch)
		return NULL;

	outlen = calcsize(inlen, patch);
	if (outlen < 0) {
		result = NULL;
		goto cleanup;
	}
	result = PyBytes_FromStringAndSize(NULL, outlen);
	if (!result) {
		result = NULL;
		goto cleanup;
	}
	out = PyBytes_AsString(result);
	if (!apply(out, in, inlen, patch)) {
		Py_DECREF(result);
		result = NULL;
	}
cleanup:
	lfree(patch);
	return result;
}
Exemplo n.º 17
0
static PyObject *
trie_has_prefix(trieobject *mp, PyObject *py_prefix)
{
    const char *prefix;
    int has_prefix;
#ifdef IS_PY3K
    PyObject* bytes;
#endif

    /* Make sure prefix is a string. */
#ifdef IS_PY3K
    if(!PyUnicode_Check(py_prefix)) {
#else
    if(!PyString_Check(py_prefix)) {
#endif
        PyErr_SetString(PyExc_TypeError, "prefix must be a string");
        return NULL;
    }
#ifdef IS_PY3K
    bytes = PyUnicode_AsASCIIString(py_prefix);
    if(!bytes) {
        PyErr_SetString(PyExc_TypeError, "prefix must be an ASCII string");
        return NULL;
    }
    prefix = PyBytes_AsString(bytes);
#else
    prefix = PyString_AS_STRING(py_prefix);
#endif
    has_prefix = Trie_has_prefix(mp->trie, prefix);
#ifdef IS_PY3K
    Py_DECREF(bytes);
    return PyLong_FromLong((long)has_prefix);
#else
    return PyInt_FromLong((long)has_prefix);
#endif
}

static PyObject *
trie_has_prefix_onearg(trieobject *mp, PyObject *py_args)
{
    PyObject *py_arg;
    if(!PyArg_ParseTuple(py_args, "O", &py_arg))
        return NULL;
    return trie_has_prefix(mp, py_arg);
}
Exemplo n.º 18
0
const char* getNameFromFile(PyObject* value)
{
    const char* string = 0;
    PyObject *oname = PyObject_GetAttrString (value, "name");
    if (oname) {
        if (PyUnicode_Check (oname)) {
            string = PyUnicode_AsUTF8 (oname);
        }
        else if (PyBytes_Check (oname)) {
            string = PyBytes_AsString (oname);
        }
        Py_DECREF (oname);
    }

    if (!string)
        throw Base::TypeError("Unable to get filename");
    return string;
}
Exemplo n.º 19
0
static FNFCIGETNEXTCABINET(cb_getnextcabinet)
{
    if (pv) {
	PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab);
	if (result == NULL)
	    return -1;
	if (!PyBytes_Check(result)) {
	    PyErr_Format(PyExc_TypeError, 
		"Incorrect return type %s from getnextcabinet",
		result->ob_type->tp_name);
	    Py_DECREF(result);
	    return FALSE;
	}
	strncpy(pccab->szCab, PyBytes_AsString(result), sizeof(pccab->szCab));
	return TRUE;
    }
    return FALSE;
}
Exemplo n.º 20
0
/* Returns a newly allocated string with the contents of the given unicode
   string object converted to CHARSET.  If an error occurs during the
   conversion, NULL will be returned and a python exception will be set.

   The caller is responsible for xfree'ing the string.  */
static gdb::unique_xmalloc_ptr<char>
unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
{
  gdb::unique_xmalloc_ptr<char> result;

  /* Translate string to named charset.  */
  gdbpy_ref<> string (PyUnicode_AsEncodedString (unicode_str, charset, NULL));
  if (string == NULL)
    return NULL;

#ifdef IS_PY3K
  result.reset (xstrdup (PyBytes_AsString (string.get ())));
#else
  result.reset (xstrdup (PyString_AsString (string.get ())));
#endif

  return result;
}
Exemplo n.º 21
0
/*NUMPY_API
 * Convert object to sort kind
 */
NPY_NO_EXPORT int
PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind)
{
    char *str;
    PyObject *tmp = NULL;

    if (PyUnicode_Check(obj)) {
        obj = tmp = PyUnicode_AsASCIIString(obj);
        if (obj == NULL) {
            return NPY_FAIL;
        }
    }

    *sortkind = NPY_QUICKSORT;
    str = PyBytes_AsString(obj);
    if (!str) {
        Py_XDECREF(tmp);
        return NPY_FAIL;
    }
    if (strlen(str) < 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Sort kind string must be at least length 1");
        Py_XDECREF(tmp);
        return NPY_FAIL;
    }
    if (str[0] == 'q' || str[0] == 'Q') {
        *sortkind = NPY_QUICKSORT;
    }
    else if (str[0] == 'h' || str[0] == 'H') {
        *sortkind = NPY_HEAPSORT;
    }
    else if (str[0] == 'm' || str[0] == 'M') {
        *sortkind = NPY_MERGESORT;
    }
    else {
        PyErr_Format(PyExc_ValueError,
                     "%s is an unrecognized kind of sort",
                     str);
        Py_XDECREF(tmp);
        return NPY_FAIL;
    }
    Py_XDECREF(tmp);
    return NPY_SUCCEED;
}
Exemplo n.º 22
0
static PyObject* Preprocessor_preprocess(Preprocessor* self, PyObject *args)
{
    PyObject *f = NULL;
    if (!PyArg_ParseTuple(args, "|O:preprocess", &f))
        return NULL;
    try
    {
        boost::shared_ptr<FILE> file;
        long fd;
        if (!f || f == Py_None)
        {
            fd = fileno(stdout);
        }
        else if (PyUnicode_Check(f))
        {
            ScopedPyObject utf8_filename(PyUnicode_AsUTF8String(f));
            const char *filename;
            if (utf8_filename && (filename = PyBytes_AsString(utf8_filename)))
            {
                file.reset(fopen(filename, "w"), &fclose);
                fd = fileno(file.get());
            }
            else
            {
                return NULL;
            }
        }
        else
        {
            // Assume it's a file-like object with a fileno() method.
            PyObject *pylong = PyObject_CallMethod(f, (char*)"fileno", NULL);
            if (!pylong || (fd = PyLong_AsLong(pylong)) == -1)
                return NULL;
        }
        self->preprocessor->preprocess(fd);
    }
    catch (...)
    {
        set_python_exception();
        return NULL;
    }
    Py_INCREF(Py_None);
    return Py_None;
}
Exemplo n.º 23
0
static PyObject *PyImage_color_conv(PyImage *self, PyObject *args, PyObject *kwds)
{
    int format;

    if (!PyArg_ParseTuple(args, "i:color_conv", &format)) {
        return NULL;
    }

    PyObject *result = PyBytes_FromStringAndSize(NULL, self->x->rowsOut * self->x->colsOut * 4);
    if (result == NULL) {
        return NULL;
    }

    CALL_CPP_CLEANUP("color_conv",
                     (self->x->color_conv(format, (agg::int8u *)PyBytes_AsString(result))),
                     Py_DECREF(result));

    return Py_BuildValue("nnN", self->x->rowsOut, self->x->colsOut, result);
}
Exemplo n.º 24
0
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
Exemplo n.º 25
0
//-------------------------------------------------------------------------------------
std::string Pickler::pickle(PyObject* pyobj)
{
	AUTO_SCOPED_PROFILE("pickle");

	PyObject* pyRet = PyObject_CallFunction(picklerMethod_, 
		const_cast<char*>("(O)"), pyobj);
	
	SCRIPT_ERROR_CHECK();
	
	if(pyRet)
	{
		std::string str;
		str.assign(PyBytes_AsString(pyRet), PyBytes_Size(pyRet));
		S_RELEASE(pyRet);
		return str;
	}
	
	return "";
}
Exemplo n.º 26
0
static int
_generate_foreign(PyObject *s, void *g)
{
    PyObject *res;
    const char *strres;
    int status;

    res = generate_real(GRMOBJ(SYMOBJ(s)->data.foreign.grammar), SYMOBJ(s)->data.foreign.start_sym);
    if (!res)
        return -1;
    strres = PyBytes_AsString(res);
    if (!strres) {
        Py_DECREF(res);
        return -1;
    }
    status = gen_state_write((gen_state_t *)g, strres, PyBytes_GET_SIZE(res));
    Py_DECREF(res);
    return status;
}
Exemplo n.º 27
0
static int
PyUnitListProxy_setitem(
    PyUnitListProxy* self,
    Py_ssize_t index,
    PyObject* arg) {

  PyObject* value;
  PyObject* unicode_value;
  PyObject* bytes_value;

  if (index > self->size) {
    PyErr_SetString(PyExc_IndexError, "index out of range");
    return -1;
  }

  value = _get_unit(self->unit_class, arg);
  if (value == NULL) {
    return -1;
  }

  unicode_value = PyObject_CallMethod(value, "to_string", "s", "fits");
  if (unicode_value == NULL) {
    Py_DECREF(value);
    return -1;
  }
  Py_DECREF(value);

  if (PyUnicode_Check(unicode_value)) {
    bytes_value = PyUnicode_AsASCIIString(unicode_value);
    if (bytes_value == NULL) {
      Py_DECREF(unicode_value);
      return -1;
    }
    Py_DECREF(unicode_value);
  } else {
    bytes_value = unicode_value;
  }

  strncpy(self->array[index], PyBytes_AsString(bytes_value), MAXSIZE);
  Py_DECREF(bytes_value);

  return 0;
}
Exemplo n.º 28
0
static PyObject *
rpmts_PgpPrtPkts(rpmtsObject * s, PyObject * args, PyObject * kwds)
{
    PyObject * blob;
    unsigned char * pkt;
    unsigned int pktlen;
    int rc;
    char * kwlist[] = {"octets", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:PgpPrtPkts", kwlist, &blob))
    	return NULL;

    pkt = (unsigned char *)PyBytes_AsString(blob);
    pktlen = PyBytes_Size(blob);

    rc = pgpPrtPkts(pkt, pktlen, NULL, 1);

    return Py_BuildValue("i", rc);
}
Exemplo n.º 29
0
void load_tkinter_funcs(void)
{
    // Load tkinter global funcs from tkinter compiled module.
    // Sets an error on failure.
    void *main_program, *tkinter_lib;
    PyObject *module = NULL, *py_path = NULL, *py_path_b = NULL;
    char *path;

    // Try loading from the main program namespace first.
    main_program = dlopen(NULL, RTLD_LAZY);
    if (_func_loader(main_program) == 0) {
        goto exit;
    }
    // Clear exception triggered when we didn't find symbols above.
    PyErr_Clear();

    // Handle PyPy first, as that import will correctly fail on CPython.
    module = PyImport_ImportModule("_tkinter.tklib_cffi");   // PyPy
    if (!module) {
        PyErr_Clear();
        module = PyImport_ImportModule("_tkinter");  // CPython
    }
    if (!(module &&
          (py_path = PyObject_GetAttrString(module, "__file__")) &&
          (py_path_b = PyUnicode_EncodeFSDefault(py_path)) &&
          (path = PyBytes_AsString(py_path_b)))) {
        goto exit;
    }
    tkinter_lib = dlopen(path, RTLD_LAZY);
    if (!tkinter_lib) {
        PyErr_SetString(PyExc_RuntimeError, dlerror());
        goto exit;
    }
    _func_loader(tkinter_lib);
    // dlclose is safe because tkinter has been imported.
    dlclose(tkinter_lib);
    goto exit;
exit:
    Py_XDECREF(module);
    Py_XDECREF(py_path);
    Py_XDECREF(py_path_b);
}
Exemplo n.º 30
0
static PyObject *
rpmts_PgpImportPubkey(rpmtsObject * s, PyObject * args, PyObject * kwds)
{
    PyObject * blob;
    unsigned char * pkt;
    unsigned int pktlen;
    int rc;
    char * kwlist[] = {"pubkey", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:PgpImportPubkey",
    	    kwlist, &blob))
	return NULL;

    pkt = (unsigned char *)PyBytes_AsString(blob);
    pktlen = PyBytes_Size(blob);

    rc = rpmtsImportPubkey(s->ts, pkt, pktlen);

    return Py_BuildValue("i", rc);
}