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

View File

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