I am seeing some odd behavior related to the django.utils.safestring.SafeString class. What I see is that if my render function returns a SafeString, the "safeness" of it is lost and its tags end up getting escaped. I've looked at this in detail in pdb and I think the issue is in force_unicode(), but I don't have the full answer, am hoping a developer that knows this code can give me some ideas.
I have a widget whose render() method returns a SafeString, ie: def render(self, name, value, attrs=None): mystr = "some string" # note it's a string, not unicode - this is important return mark_safe(mystr) # returns a SafeString If at this point in the code, I start stepping through the code, I find that this SafeString value gets returned without any modification by my render() function, then by as_widget(), and then by __unicode__ (). At those points in the code, if I munge the code a bit to create a temporary variable and then look a the type of that temporary variable, the value being returned is still a <class 'django.utils.safestring.SafeString'>, as you'd expect. Eventually I end up in the force_unicode() function at code that looks like this: if hasattr(s, '__unicode__'): s = unicode(s) The call to unicode(s) has resulted in my render function getting called, and as far as I can tell, unicode(s) should simply return the value that my render function returned. I would expect the resulting 's' to be a SafeString. However, if I look at the type of s after unicode(s) has been called, it's type is now <type 'unicode'> rather than <class 'django.utils.safestring.SafeString'> This seems to result in the mark_safe() that I did in my render function not having the intended effect. I have anlayzed this code to death, and I absolutely cannot figure out why the value being returned by my render function would be changing from SafeString to unicode. Note that if in my render() function I have a unicode string rather than a normal string, I don't see this issue. I can obviously work around this, but would like to know if this seems like a bug that I should post. Perhaps it is a python bug even? That's hard to believe, but I guess it's possible. Margie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---