mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 04:44:59 +00:00
Introduced new exceptions
This commit is contained in:
parent
e84a0d7db2
commit
a83c2abfbf
@ -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):
|
||||
|
@ -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.")
|
||||
|
Loading…
Reference in New Issue
Block a user