[Freeswitch-dev] ESL events, header data in non-ascii characters and unicode hell

Anton VG anton.vazir at gmail.com
Thu Mar 29 14:32:46 MSD 2012


Fixed that... for those who interested:

esl_wrap.cpp must be changed to return bytes instead PyUnicode object:
Unfortunately this is manual quick hack, and not the way to change the
SWIG ESL.i, so the FS way would be the type mapping maybe.

and this allows us to deal with exceptions and codings/decodings in
our code instead of uncatchable hard error.

SWIGINTERNINLINE PyObject *
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
  char *cstr1;
  if (carray) {
    if (size > INT_MAX) {
      swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
      return pchar_descriptor ?.
      SWIG_InternalNewPointerObj(const_cast< char * >(carray),
pchar_descriptor, 0) : SWIG_Py_Void();
    } else {
#if PY_VERSION_HEX >= 0x03000000
      return PyBytes_FromStringAndSize(carray, static_cast< int
>(size));
      //return PyUnicode_FromStringAndSize(carray, static_cast< int
>(size));
#else
      return PyString_FromStringAndSize(carray, static_cast< int
>(size));
#endif
    }
  } else {
    return SWIG_Py_Void();
  }
}

2012/3/28 Anton VG <anton.vazir at gmail.com>:
> Guys,
>
> Some users enter their name in unicode (non ascii chars) - russian for
> example or french
>
> When using Python ESL in Python3 - I get this weird behavior.
> ESLevent already attempted to be returned as a unicode str, and damn
> Py3 attempts to unicode it before
> I can catch an exception in the ESL.py code and remove the non ascii
> chars or handle it another way.
>
> (python 2 have been just passing the bytes over)
>
>  File "/home/anton/GIT/auth_server/ESL/ESL.py", line 78, in getHeader
>    def getHeader(self, *args): return _ESL.ESLevent_getHeader(self, *args)
> UnicodeDecodeError: 'utf8' codec can't decode byte 0xef in position 1:
> invalid continuation byte
>
> While the data is ascii or unicode correct, all OK.
>
> Please help determine where I can tap in to have headers data to be
> cast as bytes before passed over to PythonLIB
>
> As ESL and other libs are automatically compiled using SWIG - I have
> no idea yet where to look at.



Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-dev mailing list