Tightened locale checks

Consider the case when locale is manually initalized with a non-string
value, and the case when python's getdefaultlocale() returns None
This commit is contained in:
Domenico Iezzi 2017-11-14 11:22:19 +01:00
parent 1cece7d3ff
commit 12109621a6
No known key found for this signature in database
GPG Key ID: 7AC94D5DDA2FB7EE

View File

@ -54,8 +54,13 @@ class DeviceBuilder(object):
self.device[key] = value
def setLocale(self, locale):
if locale is None:
# test if provided locale is valid
if locale is None or type(locale) is not str:
# try to fetch it from system
locale = getdefaultlocale()[0]
# getdefaultlocale may return None, we need another check
if locale is None:
locale = ''
# check if locale matches the structure of a common
# value like "en_US"