search for: python_to_string

Displaying 15 results from an estimated 15 matches for "python_to_string".

2018 Aug 08
2
[PATCH nbdkit] python: Try harder to print the full traceback on error.
...ption.py | 20 +++++++- tests/test-python-exception.sh | 13 ++++- 3 files changed, 109 insertions(+), 16 deletions(-) diff --git a/plugins/python/python.c b/plugins/python/python.c index 7eb91d7..3450b9b 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -129,27 +129,91 @@ python_to_string (PyObject *str) return NULL; } +/* This is the fallback in case we cannot get the full traceback. */ +static void +print_python_error (const char *callback, PyObject *error) +{ + PyObject *error_str; + char *error_cstr = NULL; + + error_str = PyObject_Str (error); + error_cstr = python_to...
2018 Apr 05
1
Re: [PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...exception.py | 45 +++++++++++++++++++++++++++++++++++++ > tests/test-python-exception.sh | 42 ++++++++++++++++++++++++++++++++++ > 5 files changed, 144 insertions(+), 3 deletions(-) > > +/* Convert bytes/str/unicode into a string. Caller must free. */ > +static char * > +python_to_string (PyObject *str) > +{ > + char *r; > + > + if (str) { > +#ifdef HAVE_PYUNICODE_ASUTF8 > + if (PyUnicode_Check (str)) { > + r = PyUnicode_AsUTF8 (str); > + r = strdup (r); > + return r; Any simpler to just write: return strdup (PyUnicode_AsUTF8 (str));...
2018 Aug 08
0
Re: [PATCH nbdkit] python: Try harder to print the full traceback on error.
.../test-python-exception.sh | 13 ++++- > 3 files changed, 109 insertions(+), 16 deletions(-) > > diff --git a/plugins/python/python.c b/plugins/python/python.c > index 7eb91d7..3450b9b 100644 > --- a/plugins/python/python.c > +++ b/plugins/python/python.c > @@ -129,27 +129,91 @@ python_to_string (PyObject *str) > return NULL; > } > > +/* This is the fallback in case we cannot get the full traceback. */ > +static void > +print_python_error (const char *callback, PyObject *error) > +{ > + PyObject *error_str; > + char *error_cstr = NULL; > + > + error_...
2020 Sep 01
0
[nbdkit PATCH 1/2] python: Implement .list_exports and friends
...ethod did not return " + "something which is iterable"); + Py_DECREF (r); + return -1; + } + + while ((t = PyIter_Next (iter)) != NULL) { + PyObject *py_name, *py_desc; + CLEANUP_FREE char *name = NULL; + CLEANUP_FREE char *desc = NULL; + + name = python_to_string (t); + if (!name) { + if (!PyTuple_Check (t) || PyTuple_Size (t) != 2) { + nbdkit_error ("list_exports method did not return an iterable of " + "2-tuples"); + Py_DECREF (iter); + Py_DECREF (r); + return -1; + } +...
2018 Apr 05
4
[PATCH nbdkit] python: Turn python exceptions into nbdkit errors
Much more annoying that it needs to be, but I have tested it and it works on Python 2 & 3. Note this will not work on Python 3.0 - 3.2, but I guess we don't care about those versions. Rich.
2019 Nov 23
1
[PATCH nbdkit] python: Print readable tracebacks
...thon.c @@ -167,7 +167,7 @@ print_python_traceback (const char *callback, type, error, traceback, NULL); if (rv == NULL) return -1; - traceback_str = PyObject_Str (rv); + traceback_str = PyUnicode_Join (NULL, rv); Py_DECREF (rv); traceback_cstr = python_to_string (traceback_str); if (traceback_cstr == NULL) { -- 2.21.0
2020 Sep 01
4
[nbdkit PATCH 0/2] More language bindings for .list_exports
This picks up python and ocaml. Some of our languages are lacking a number of bindings (for example, lua and perl lack .extents, so I didn't have anything to copy from), and I felt less comfortable with golang and rust. But for python and ocaml, I was able to test a working implementation. Eric Blake (2): python: Implement .list_exports and friends ocaml: Implement .list_exports and
2018 Apr 05
0
[PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...on.c b/plugins/python/python.c index 83a32ea..02f0d4c 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -103,13 +103,58 @@ callback_defined (const char *name, PyObject **obj_rtn) return 1; } +/* Convert bytes/str/unicode into a string. Caller must free. */ +static char * +python_to_string (PyObject *str) +{ + char *r; + + if (str) { +#ifdef HAVE_PYUNICODE_ASUTF8 + if (PyUnicode_Check (str)) { + r = PyUnicode_AsUTF8 (str); + r = strdup (r); + return r; + } + else +#endif +#ifdef HAVE_PYSTRING_ASSTRING + if (PyString_Check (str)) { + r = PyString_AsSt...
2019 Sep 11
0
[PATCH nbdkit] python: Drop support for Python 2.
..." != "xno" && test "x$PYTHON" != "xno"]) AC_SUBST([PYTHON_CFLAGS]) diff --git a/plugins/python/python.c b/plugins/python/python.c index 20232f4..2e1a53f 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -117,17 +117,9 @@ static char * python_to_string (PyObject *str) { if (str) { -#ifdef HAVE_PYUNICODE_ASUTF8 if (PyUnicode_Check (str)) return strdup (PyUnicode_AsUTF8 (str)); - else -#endif -#ifdef HAVE_PYSTRING_ASSTRING - if (PyString_Check (str)) - return strdup (PyString_AsString (str)); - else -#endif - if (Py...
2019 Sep 11
3
[PATCH nbdkit] python: Drop support for Python 2.
This patch proposes to drop support for Python 2 in nbdkit. Rather than abruptly drop it everywhere, my proposal is that we point people to nbdkit 1.14 (the current stable version) if they want to continue with Python 2 plugins, while gently reminding them of the upcoming Python 2.7 end of life announcement. Libnbd never supported Python 2. Libguestfs in theory supports Python 2 but I dropped
2018 Apr 11
0
[nbdkit PATCH v2 1/5] python: Let zero's may_trim parameter be optional
...heck_list (args, name)) + r = 1; +#if PY_MAJOR_VERSION >= 3 + else { + args = PyTuple_GetItem (spec, 5); + if (check_list (args, name)) + r = 1; + } +#endif + + Py_DECREF (spec); + return r; +} + /* Convert bytes/str/unicode into a string. Caller must free. */ static char * python_to_string (PyObject *str) @@ -481,21 +548,48 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) PyObject *obj = handle; PyObject *fn; PyObject *args; + PyObject *kwargs; PyObject *r; if (callback_defined ("zero", &fn)) { + static int zero_may_trim = -1;...
2018 Apr 06
1
[nbdkit PATCH] python: Let zero's may_trim parameter be optional
...+ r = 1; + else { + /* inspecting kwonly args is only available in python 3 */ + args = PyTuple_GetItem(spec, 5); + if (check_list(args, name)) + r = 1; + } + + Py_DECREF (spec); + return r; +} + /* Convert bytes/str/unicode into a string. Caller must free. */ static char * python_to_string (PyObject *str) @@ -530,21 +594,31 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) PyObject *obj = handle; PyObject *fn; PyObject *args; + PyObject *kwargs = NULL; PyObject *r; if (callback_defined ("zero", &fn)) { + if (zero_may_trim <...
2019 Nov 25
6
[nbdkit PATCH 0/5] Counterproposal for python v2 interfaces
As mentioned in my reviews, I wonder if we should make our python callbacks look a bit more Pythonic by having kwargs added for each new flag that we want to expose. The idea was first floated here: https://www.redhat.com/archives/libguestfs/2018-April/msg00108.html Note that with my proposal, there is no need for a python script to expose a global API_VERSION variable; new flags are added
2020 Sep 21
18
[nbdkit PATCH v3 00/14] exportname filter
It's been several weeks since I posted v2 (I got distracted by improving libnbd to better test things, which in turn surfaced some major memory leak problems in nbdsh that are now fixed). Many of the patches are minor rebases from v2, with the biggest changes being fallout from: - patch 2: rename nbdkit_add_default_export to nbdkit_use_default_export - overall: this missed 1.22, so update
2018 Apr 11
10
[nbdkit PATCH v2 0/5] FUA support in Python scripts
First out of our four language bindings to add FUA support (for reference, I added 'zero' support for python, perl, and ruby back in 1.1.13, then Rich had to add it for ocaml in 1.1.20). I tested this heavily under python 2, but for now only compile tested under python 3; I plan to do further testing there and make any tweaks if necessary. I wrote patch 5 early on, but then realized I