Introduced new exceptions

This commit is contained in:
Domenico Iezzi 2018-07-15 17:09:31 +02:00
parent e84a0d7db2
commit a83c2abfbf
No known key found for this signature in database
GPG Key ID: D8CE73FC9E4393C3
2 changed files with 14 additions and 6 deletions

View File

@ -29,6 +29,13 @@ else:
config.read(filepath)
class InvalidLocaleError(Exception):
pass
class InvalidTimezoneError(Exception):
pass
def getDevicesCodenames():
"""Returns a list containing devices codenames"""
return config.sections()
@ -51,19 +58,19 @@ class DeviceBuilder(object):
def set_locale(self, locale):
# test if provided locale is valid
if locale is None or type(locale) is not str:
raise Exception('Wrong locale supplied')
raise InvalidLocaleError()
# check if locale matches the structure of a common
# value like "en_US"
if match(r'[a-z]{2}\_[A-Z]{2}', locale) is None:
raise Exception('Wrong locale supplied')
raise InvalidLocaleError()
self.locale = locale
def set_timezone(self, timezone):
if timezone is None or type(timezone) is not str:
timezone = self.device.get('timezone')
if timezone is None:
raise Exception('Wrong timezone supplied')
raise InvalidTimezoneError()
self.timezone = timezone
def getBaseHeaders(self):

View File

@ -53,6 +53,9 @@ class RequestError(Exception):
def __str__(self):
return repr(self.value)
class SecurityCheckError(Exception):
pass
class GooglePlayAPI(object):
"""Google Play Unofficial API Class
@ -217,9 +220,7 @@ class GooglePlayAPI(object):
ac2dmToken = params["auth"]
elif "error" in params:
if "NeedsBrowser" in params["error"]:
raise LoginError("Security check is needed, try to visit "
"https://accounts.google.com/b/0/DisplayUnlockCaptcha "
"to unlock, or setup an app-specific password")
raise SecurityCheckError()
raise LoginError("server says: " + params["error"])
else:
raise LoginError("Auth token not found.")