Results 1 to 2 of 2

Thread: Unicode handling in IcePy

  1. #1
    grembo is offline Registered User
    Name: Michael Gmelin
    Organization: Grem Equity GmbH
    Project: E-Commerce platform
    Join Date
    Jan 2009
    Posts
    85

    Unicode handling in IcePy

    It seem like the unicode handling in IcePy is asymmetric, since Python unicode sent into the marshaling code will be transcoded to UTF-8 while strings received will be plain UTF-8, which is not all that useful in practice. Using Ice.Plugin.Converter - as suggested in Python and Unicode - won't do the trick, since changing the encoding won't affect the type (str vs. unicode).

    The workaround we're using right now is to change Python's default encoding from ascii to UTF-8, but this is kind of a hack. There are several ways to accomplish this, we're using the following approach (this is no recommendation, but it's a workaround that does the trick and works ok in our specific environment):
    Code:
    import sys
    reload(sys)
    sys.setdefaultencoding('UTF-8')
    del sys.setdefaultencoding
    The alternative is to use the decode method a lot (like mystruct.stringMember.decode('UTF-8'), which is really error prone.

    All of this is happening in Ice-3.4.2/py/modules/IcePy/Types.cpp, changing it shouldn't be too hard.

    In the function "IcePy::PrimitiveInfo::marshal" when a string is encountered, writeString() is called, which detect and automatically convert a python unicode type to a UTF8 string, if Py_USING_UNICODE is defined.

    However, in the function "IcePy::PrimitiveInfo::unmarshal" Ice strings are only returned as plain Python strings which are UTF-8 encoded, and there is no option to get a Python unicode value at all.

    This behaviour is very asymmetric, and means that if you're working in a pure unicode environment, you have to manually convert every string you receive from Ice into a python unicode using .decode('utf-8').

    What would be much better is to have a configuration option that would instruct IcePy to always convert Ice strings to Python unicode types.

    Cheers
    Michael

  2. #2
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi Michael,

    I agree, the current behavior could use some improvement. This is on our list of things to fix for the next release.

    Regards,
    Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Python and Unicode
    By cebix in forum Comments
    Replies: 3
    Last Post: 04-25-2008, 04:59 AM
  2. icepatch2 unicode error
    By incubator in forum Help Center
    Replies: 5
    Last Post: 11-22-2006, 04:04 AM
  3. UNICODE not required in 1.3
    By amrufon in forum Comments
    Replies: 1
    Last Post: 03-11-2004, 07:22 AM
  4. unicode does not support multiple word languare.
    By damingyipai in forum Bug Reports
    Replies: 4
    Last Post: 03-09-2004, 10:28 PM
  5. Unicode question
    By Mr.Freeze in forum Help Center
    Replies: 1
    Last Post: 08-14-2003, 07:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •