[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freeswitch-dev
Subject:    Re: [Freeswitch-dev] ESL events, header data in non-ascii characters and unicode hell
From:       Anton VG <anton.vazir () gmail ! com>
Date:       2012-03-29 10:32:46
Message-ID: CAGX+Xzt1VJf-xsGgt4Dex4GPbZesHnpqBKidir=1tpurUW=Uww () mail ! gmail ! com
[Download RAW message or body]

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@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.

_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org
http://www.freeswitchsolutions.com

FreeSWITCH-powered IP PBX: The CudaTel Communication Server
http://www.cudatel.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://wiki.freeswitch.org
http://www.cluecon.com

FreeSWITCH-dev mailing list
FreeSWITCH-dev@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev
http://www.freeswitch.org
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic