Skip to content

Commit

Permalink
Tightened locale checks
Browse files Browse the repository at this point in the history
Consider the case when locale is manually initalized with a non-string
value, and the case when python's getdefaultlocale() returns None
  • Loading branch information
Domenico Iezzi committed Nov 14, 2017
1 parent 1cece7d commit 1210962
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gpapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ def __init__(self, device):
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"
Expand Down

0 comments on commit 1210962

Please sign in to comment.