From 6a3c687f039f8f6cfeb8d12d81cd71157ad43ddd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Sep 2010 22:18:45 -0700 Subject: pidl/python: Allow passing in UTF8 string objects as well as unicode objects for IDL strings. Signed-off-by: Andrew Tridgell --- pidl/lib/Parse/Pidl/Samba4/Python.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pidl/lib/Parse/Pidl/Samba4/Python.pm') diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index d4db4c0834..ed43ba4d3e 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -987,9 +987,21 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } if (is_charset_array($e, $l)) { - $self->pidl("PY_CHECK_TYPE(&PyUnicode_Type, $py_var, $fail);"); + $self->pidl("if (PyUnicode_Check($py_var)) {"); + $self->indent; # FIXME: Use Unix charset setting rather than utf-8 $self->pidl($var_name . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); + $self->deindent; + $self->pidl("} else if (PyString_Check($py_var)) {"); + $self->indent; + $self->pidl($var_name . " = PyString_AsString($py_var);"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; + $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected string or unicode object, got %s\", Py_TYPE($py_var)->tp_name);"); + $self->pidl("$fail;"); + $self->deindent; + $self->pidl("}"); } else { my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; $self->pidl("PY_CHECK_TYPE(&PyList_Type, $py_var, $fail);"); -- cgit