On Thu, 2007-07-12 at 08:55 -0500, Jeremy Dunck wrote: > On 7/12/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > > On Thu, 2007-07-12 at 05:34 -0500, Jeremy Dunck wrote: > ... > > > What's going on here is that the memcache.py library does this with > > > the passed parameters: > > > > > > fullcmd = "%s %s %d %d %d\r\n%s" % (cmd, key, flags, time, len(val), val) > > > > > > Since "key" is often a unicode string, it infects, as it were, the > > > rest of the line, forcing "val" to be encoded, then decoded. > > > > I thought I understood the problem until I read this sentence. Now my > > brain hurts. I fully understand that the whole string is treated as > > Unicode as soon as one argument is Unicode. Why is "val" the problem > > here then? What sort of object is "val" and why doesn't unicode(val) > > work (aah ... is is going via str(val) and val is non-ASCII? That could > > do it). > > Sorry for not giving more context. > > In that quoted line, cmd is a str (created by the library itself), key > is whatever the low-level django API passes in (very likely a > Unicode), and val is a pickled object (that is, arbitrary binary).
Okay. That makes things clearer. Memcache is expecting to handle val as an opaque sequence of bytes here (they are using the binary pickling format), which is the key point. So your proposed fix looks right to me. > When key is Unicode, it forces val to be decoded into Unicode, which > fails, since it's a binary. Yes, I agree. Regards, Malcolm -- Honk if you love peace and quiet. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
