mangroveorg/mangrove — comment on commit 3f297250198c4b24c8bb63186af08c8771c2dc4e
File:  line 0
By jwishnie:

Reading through PEP100 (http://www.python.org/dev/peps/pep-0100) it looks like default internal rep for a 'unicode' type is UTF-16 (UCS2), not UTF-8.

But in general, Python's 'codec' string interface means that we shouldn't have to care how a particular implementation of the interpreter internally represents a 'unicode' or 'unichr' as long as one ALWAYS used 'encode' and 'decode' when a specific encoding is required.

So it is GOOD PRACTICE to always use 'encode'/'decode'—if the string is already in the requested encoding this should basically be a no-op, so no harm done.

It also make the code more explicit by making it very clear the encoding required by the function being called.

That said, wouldn't it be SAFER for 'sms_client.send_sms') to accept any 'basestring' in any encoding and do the necessary encoding to utf-8 internally rather than relying on callers to do this??