facebook/tornado — pull request #1027 by zhang-peter (2014-04-08 07:09:27+00:00)
Title: Correct function that converts object to unicode string or string encoded as utf8

```Python
class Foo(object):
text = u'\u4e2d\u56fd' # they are two chinese characters

def __str__(self):
return self.text
def __unicode__(self):
return self.text

foo = Foo()
print str(foo)
```

If object "foo" is an instance of class "Foo", str(foo) will raise the following Exception:
```Python
Traceback (most recent call last):
File "/tmp/test.py", line 12, in
print str(foo)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
```

unicode(foo) will work. Under Python3.x, we use str(). In case of Python2.x, we use unicode().