← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1155280] Re: Use unicode() everywhere and not str()

 

** Changed in: nova
   Importance: Undecided => Wishlist

** Changed in: nova
       Status: New => Opinion

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1155280

Title:
  Use unicode() everywhere and not str()

Status in OpenStack Compute (Nova):
  Opinion

Bug description:
  In nova/__init__.py - gettext.install uses the 'unicode=1' parameter,
  meaning that whenever the gettext installed function is used, the
  result will be a unicode string.

  This is great as it means all strings internal to nova will be in
  unicode format, and automatically outputted in
  locale.getpreferredencoding().

  However there are lots of places in nova where 'str()' is used;
  usually to get the message out of an exception. The str function
  assumes that the unicode string is encoded in 7-bit-ascii, so could
  raise an exception as shown here:

  >>> u = u'\u507d\u306eISCSI: %s'
  >>> str(u)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

  ----

  This bug proposes to enforce a policy that all human readable output
  messages be stored inside of openstack as unicode strings.

   * All wrappings of exception messages in str() should be changed to
  unicode()

  If str() is truly needed:

   * For writing to files, it should be changed to: some_unicode_string.decode(locale.getpreferredencoding())
   * For outputting over the network, some_unicode_string.decode('utf-8'); should be used
   * For turning ints into string and the like, just leave it as is.

  (This bug is a re-write and fix of
  https://bugs.launchpad.net/nova/+bug/1152188 )

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1155280/+subscriptions