Update is_ascii to work with py3
Change-Id: I28439cab9948aff4ed0abaad52ab89169d5e50a1
This commit is contained in:
parent
4e3d973209
commit
795cd4da7f
|
@ -304,6 +304,12 @@ class TestUtils(test_utils.TestCase):
|
|||
def test_build_kwargs_dict_value_empty_str(self):
|
||||
self.assertEqual({}, utils.build_kwargs_dict('arg_bla', ''))
|
||||
|
||||
def test_is_ascii_bytes(self):
|
||||
self.assertFalse(utils.is_ascii(b'\xe2'))
|
||||
|
||||
def test_is_ascii_string(self):
|
||||
self.assertFalse(utils.is_ascii(u'\u2665'))
|
||||
|
||||
|
||||
class NoUniqueMatch(Exception):
|
||||
pass
|
||||
|
|
|
@ -324,9 +324,10 @@ def get_password(stdin, prompt=None, confirm=True):
|
|||
|
||||
def is_ascii(string):
|
||||
try:
|
||||
string.decode('ascii')
|
||||
(string.decode('ascii') if isinstance(string, bytes)
|
||||
else string.encode('ascii'))
|
||||
return True
|
||||
except UnicodeDecodeError:
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
return False
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue