File: python3.diff

package info (click to toggle)
libgnatcoll-bindings 18-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 980 kB
  • sloc: ada: 6,581; ansic: 722; python: 687; makefile: 48; sh: 46
file content (45 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Description: fix incompatibilities with Python3.
 Three function have been obsoleted.
 The documentation advices io.open() instead of PyFile_FromString(),
 but builtin.open() is an alias and its module is certainly already imported.
Forwarded: no
Author: Nicolas Boulenguez <nicolas@debian.org>

--- a/python/python_support.c
+++ b/python/python_support.c
@@ -387,25 +387,20 @@
 PyObject* ada_PyUnicode_AsEncodedString
   (PyObject *unicode, const char *encoding, const char *errors)
 {
-#ifdef Py_UNICODE_WIDE
-  return PyUnicodeUCS4_AsEncodedString (unicode, encoding, errors);
-#else
-  return PyUnicodeUCS2_AsEncodedString (unicode, encoding, errors);
-#endif
+  return PyUnicode_AsEncodedString (unicode, encoding, errors);
 }
 
 PyObject* ada_PyUnicode_FromString (const char *u)
 {
-#if PY_VERSION_HEX >= 0x02060000
-#ifdef Py_UNICODE_WIDE
-  return PyUnicodeUCS4_FromString (u);
-#else
-  return PyUnicodeUCS2_FromString (u);
-#endif
-#else
-  /* Not available in this version */
-  return 0;
-#endif
+  return PyUnicode_FromString (u);
+}
+
+PyObject* PyFile_FromString (const char *file_name, const char *mode)
+{
+  PyObject *builtin = PyImport_ImportModule ("builtin");
+  if (builtin == NULL)
+    return NULL;
+  return PyObject_CallMethod (builtin, "open", "ss", file_name, mode);
 }
 
 int