Fix support for Unicode volume names

It is possible to create a Unicode volume from the command line,
but it cannot be manipulated by name for operations such as delete.
This is because the find_resource function tries to match the
Unicode string to a regular byte string, and a UnicodeWarning is
issued, failing the match.  Fix by decoding the Unicode name when
trying to match.

Fixes bug 1065275.

Change-Id: I8e19a78bbc1ccb503ccd39dc3b904fc4f6f77858
This commit is contained in:
Eric Harney
2012-10-23 15:40:17 -04:00
parent 5a3a18d0cb
commit 01dad32c07

View File

@@ -1,3 +1,4 @@
import locale
import os import os
import re import re
import sys import sys
@@ -178,6 +179,13 @@ def find_resource(manager, name_or_id):
try: try:
return manager.find(name=name_or_id) return manager.find(name=name_or_id)
except exceptions.NotFound: except exceptions.NotFound:
try:
# For command-line arguments that are in Unicode
encoding = (locale.getpreferredencoding() or
sys.stdin.encoding or
'UTF-8')
return manager.find(display_name=(name_or_id.decode(encoding)))
except (UnicodeDecodeError, exceptions.NotFound):
try: try:
# Volumes does not have name, but display_name # Volumes does not have name, but display_name
return manager.find(display_name=name_or_id) return manager.find(display_name=name_or_id)