After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 701600 - Port to Python3
Port to Python3
Status: RESOLVED OBSOLETE
Product: libxslt
Classification: Platform
Component: python
git master
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks: python3
 
 
Reported: 2013-06-04 14:48 UTC by Armin K.
Modified: 2021-07-05 11:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Port to Python 3 (47.11 KB, patch)
2013-06-04 18:17 UTC, Armin K.
none Details | Review
Convert Tests to Python 3 (12.37 KB, patch)
2013-06-04 18:34 UTC, Armin K.
none Details | Review
Port Tests to Python 3 (12.46 KB, patch)
2013-06-04 19:04 UTC, Armin K.
none Details | Review

Description Armin K. 2013-06-04 14:48:20 UTC
https://live.gnome.org/GnomeGoals/Python3Porting

Package isn't listed there, but the external links for porting should be useful. Python3 is out for a while and it would be nice to port this package to support it.
Comment 1 Armin K. 2013-06-04 18:17:20 UTC
Created attachment 246022 [details] [review]
Port to Python 3
Comment 2 Armin K. 2013-06-04 18:34:25 UTC
Created attachment 246023 [details] [review]
Convert Tests to Python 3
Comment 3 Daniel Veillard 2013-06-04 18:59:04 UTC
Okay I will look, but the patches should be closely modeled against the
equivalent patches I made for libxml2. Did you reuse the set of patches
from libxml2 or is that completely new work from you ?

  thanks,

Daniel
Comment 4 Armin K. 2013-06-04 19:04:45 UTC
Created attachment 246026 [details] [review]
Port Tests to Python 3
Comment 5 Armin K. 2013-06-04 19:05:50 UTC
As I said, I've mostly looked at libxml2 work and applied it to libxslt files. I don't know Python or Python C bindings to do it on my own. Any modifications welcome. I am unable to do anything else because I don't know.
Comment 6 Daniel Veillard 2013-06-04 19:12:08 UTC
Ahh, okay :-) I was lacking time mostly ... and I will have to do libvirt too
at some point, thanks for the help, I will try to allocate time for this,
unlikely this week, maybe later in the month,

   thanks !

Daniel
Comment 7 James Salter 2015-01-23 16:28:10 UTC
Also interested in this and started writing my own patch before finding this item.

Some points on the patch:

1. I am a bit confused about this bit of code:

@@ -689,14 +698,23 @@ libxslt_xsltApplyStylesheetUser(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
 		j = 0;
 		while (PyDict_Next(pyobj_params, &ppos, &name, &value)) {
 		    const char *tmp;
-		    int size;
-
-		    tmp = PyString_AS_STRING(name);
-		    size = PyString_GET_SIZE(name);
-		    params[j * 2] = (char *) xmlCharStrndup(tmp, size);
-		    if (PyString_Check(value)) {
-			tmp = PyString_AS_STRING(value);
-			size = PyString_GET_SIZE(value);
+		    Py_ssize_t size;
+
+#if PY_VERSION_HEX >= 0x03030000
+		    tmp = PyUnicode_AsUTF8AndSize(name, &size);
+		    params[j * 2] = (char *) xmlCharStrndup(tmp, (int) size);
+#else
+		    PyObject *b;
+		    b = PyUnicode_AsUTF8String(name);
+		    if (b != NULL) {
+			params[j * 2] = (char *) xmlCharStrndup(PyBytes_AS_STRING(b),
+								PyBytes_GET_SIZE(b));
+			Py_DECREF(b);
+		    }
+#endif
+		    if (PyBytes_Check(value)) {
+			tmp = PyBytes_AS_STRING(value);
+			size = PyBytes_GET_SIZE(value);
 			params[(j * 2) + 1] = (char *)
 			    xmlCharStrndup(tmp, size);
 		    } else {

PyUnicode_AsUTF8String is used on name for all python < 3.3. 

For Python 2.x, that will break existing functionality where the caller was passing a str (i.e. everybody, because that's what it previously took).

It also changes the type of value to bytes for all versions, which breaks python 2.7 callers passing str, and python 3.x callers which are presumably expecting to pass unicode.

I would have thought that this code would be unmodified for python 2.x and support unicode for 3.x.

2. I think this should use PY_IMPORT_INT 

@@ -417,13 +483,13 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
             }
             break;
         case XPATH_BOOLEAN:
-            ret = PyInt_FromLong((long) obj->boolval);
+            ret = PyLong_FromLong((long) obj->boolval);
Comment 8 Armin K. 2015-01-23 16:43:34 UTC
Again, as said in comment 5, I did mirror what libxml2 did at that time. I have no knowledge of Python. Feel free to take this patch and improve it as needed.
Comment 9 James Salter 2015-01-23 16:58:15 UTC
Wow thanks for the quick response, I was not expecting that after 18 months! To be clear, the patch is a much better start than the tiny amount I had. I may have time to submit a revision next week.
Comment 10 Timo Gurr 2017-01-03 13:37:08 UTC
I don't want to hijack this thread but since various distributions have been shipping with patches for Python 3 compatibility there is now an additional one required to work with the recently released Python 3.6:

http://pkgs.fedoraproject.org/cgit/rpms/libxml2.git/tree/libxml2-2.9.4-remove-pyverify_fd.patch

https://bugzilla.redhat.com/show_bug.cgi?id=1406920
Comment 11 Timo Gurr 2017-01-03 13:42:48 UTC
(In reply to Timo Gurr from comment #10)
> I don't want to hijack this thread but since various distributions have been
> shipping with patches for Python 3 compatibility there is now an additional
> one required to work with the recently released Python 3.6:
> 
> http://pkgs.fedoraproject.org/cgit/rpms/libxml2.git/tree/libxml2-2.9.4-
> remove-pyverify_fd.patch
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1406920

Replying to myself I just noticed the product of this bug is libxslt and not libxml2 which I searched for, my bad, sorry for the unnecessary noise!
Comment 12 GNOME Infrastructure Team 2021-07-05 11:00:35 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/libxslt/-/issues/

Thank you for your understanding and your help.