[Twisted-web] Athena callRemote with str()

Phil Mayers p.mayers at imperial.ac.uk
Sat Jul 1 18:01:49 CDT 2006


Jean-Paul Calderone wrote:
> On Sat, 01 Jul 2006 22:12:19 +0100, Phil Mayers 
> <p.mayers at imperial.ac.uk> wrote:
>> Is the behaviour that Athena won't permit a server-side callRemote to 
>> return a str() and mandates a unicode() intentional? If so, what is 
>> the rationale?
> 
> Yep.  JavaScript doesn't have a byte string type, only a character string
> type.  Athena won't guess what kind of characters you want to result from
> a Python str.

Hmm. I had not appreciated the wholly character-based nature of 
javascript strings. Thanks - I'll recast str() as unicode(). In case 
anyone is interested the specific thing I was passing was packed MAC and 
IP addresses, which of course are not unicode strings, for a host 
management database. I will have to unpack them to get unambiguous 
encodings :o(

On a related note, is there any particular reason that Nevow uses it's 
own json lib instead of $thebetter of the python json libs? Because at 
least one of them has support for pluggable mappings of types to 
serialisers - e.g. DateTime -> $thestringrep - allowing applications to 
be explicit and hook when sending complex types over the wire, but 
without having to do so in boilerplate each call.

Thinking about it some more, when operating in a Mantissa-like 
environment where multiple independent fragments from independent 
applications are running in a single page, the serialiser mappings would 
have to be per-fragment/application. Tricky.



More information about the Twisted-web mailing list