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:
@@ -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)
|
||||||
|
Reference in New Issue
Block a user