How to generate java .properties files in python

Arnaud Delobelle arnodel at gmail.com
Mon Dec 5 17:45:56 EST 2011


On 5 December 2011 21:46, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 05.12.11 22:25, Arnaud Delobelle написав(ла):
>> On 5 December 2011 20:05, Serhiy Storchaka<storchaka at gmail.com>  wrote:
>>> You must also encode backslash ('\\'), whitespaces and control characters
>>> (ord(c)<=32), '=' and ':' (key/value delimiters), '#' (comment) and '!'.
>> Fortunately there aren't any of these in the keys.
>
> "a=b" is same as "a= b".

You're right - all my values are trimmed for whitespace on both sides,
so it's OK for me.  Although if I wanted to make a general purpose
tool I would have to take this into account.
I might just escape all whitespace after all, for safety's sake.

>>> And don't forget characters with code>0xFFFF.
>> I haven't thought of these.  I don't think that I have any, but I'll
>> check.  Do you know how they are encoded?
>
> Java uses UTF-16.
>
> if i>=0x110000:
>    raise some exception
> if i>=0x10000:
>    return '\\u%04X\\u%04X' % (0xD800+((i-0x10000)>>10), 0xDC00+(i&0x3FF))

Thanks.  I'm using .encode("latin1", "backslashreplace") now as
suggested by Peter Otten.  I can't see from the docs if this uses
UTF-16 escape sequences.

-- 
Arnaud



More information about the Python-list mailing list