Commit 8cc8f849cc71721d8bfc3c29e3454dced762fc78

Authored by Jürgen Knödlseder
1 parent 64618701

Make GFilename typemap compatible with Python 3.

Python 3 uses unicode instead of a string.
Showing 1 changed file with 10 additions and 2 deletions
pyext/typemap_GFilename.i
... ... @@ -37,8 +37,12 @@
37 37 ***************************************************************************/
38 38 %typemap(in) GFilename& (GFilename temp) {
39 39 if (PyString_Check($input)) {
40   - temp = GFilename(std::string(PyString_AsString($input)));
41   - $1 = &temp;
  40 + temp = GFilename(std::string(PyString_AsString($input)));
  41 + $1 = &temp;
  42 + }
  43 + else if (PyUnicode_Check($input)) {
  44 + temp = GFilename(std::string(PyBytes_AS_STRING(PyUnicode_AsEncodedString($input, "utf-8", "Error ~"))));
  45 + $1 = &temp;
42 46 }
43 47 else {
44 48 void *filename_argp1 = 0;
... ... @@ -65,6 +69,10 @@
65 69 SWIG_CheckState(SWIG_ConvertPtr($input, 0, $1_descriptor, 0))) {
66 70 $1 = 1;
67 71 }
  72 + else if (PyUnicode_Check($input) ||
  73 + SWIG_CheckState(SWIG_ConvertPtr($input, 0, $1_descriptor, 0))) {
  74 + $1 = 1;
  75 + }
68 76 else {
69 77 $1 = 0;
70 78 }
... ...