[Twisted-web] [Nevow] json serializer and strings

Jean-Paul Calderone exarkun at divmod.com
Sat Sep 9 16:42:22 CDT 2006


On Sat, 09 Sep 2006 22:40:53 +0200, Manlio Perillo <manlio_perillo at libero.it> wrote:
>Jean-Paul Calderone ha scritto:
>> On Sat, 09 Sep 2006 20:08:16 +0200, Manlio Perillo
>> <manlio_perillo at libero.it> wrote:
>>> Hi.
>>>
>>> Why the json serializer does not support plain strings?
>>>
>>> I'm having problems because I want to serialize keywords arguments and
>>> the dictionary keys are str objects, not unicode.
>>>
>>> There are some problems with this:
>>>
>>>    elif isinstance(obj, str):
>>>        w('"')
>>>        w(stringEncode(obj.decode("us-ascii"))
>>>        w('"')
>>> ?
>>
>> Yes.  What if it is not an ASCII string?
>
>Raise an arror?
>Is this really a problem?

Yes.

>
>Unfortunalety(?) plain strings are widely used in the CPython
>implementation (keywords arguments stores keys as str not unicode).
>
>> If you know that your strings
>> are ASCII strings, decode them before you give them to Athena.
>>
>
>I'm not using json for Athena, just to serialize a dictionary (keywords
>arguments) in JSON format.
>

You should probably use another json library, then.  nevow.json is primarily
a support library for athena.

Jean-Paul



More information about the Twisted-web mailing list