Skip to content

Commit a83c2ab

Browse files
author
Domenico Iezzi
committed
Introduced new exceptions
1 parent e84a0d7 commit a83c2ab

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

gpapi/config.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
config.read(filepath)
3030

3131

32+
class InvalidLocaleError(Exception):
33+
pass
34+
35+
class InvalidTimezoneError(Exception):
36+
pass
37+
38+
3239
def getDevicesCodenames():
3340
"""Returns a list containing devices codenames"""
3441
return config.sections()
@@ -51,19 +58,19 @@ def __init__(self, device):
5158
def set_locale(self, locale):
5259
# test if provided locale is valid
5360
if locale is None or type(locale) is not str:
54-
raise Exception('Wrong locale supplied')
61+
raise InvalidLocaleError()
5562

5663
# check if locale matches the structure of a common
5764
# value like "en_US"
5865
if match(r'[a-z]{2}\_[A-Z]{2}', locale) is None:
59-
raise Exception('Wrong locale supplied')
66+
raise InvalidLocaleError()
6067
self.locale = locale
6168

6269
def set_timezone(self, timezone):
6370
if timezone is None or type(timezone) is not str:
6471
timezone = self.device.get('timezone')
6572
if timezone is None:
66-
raise Exception('Wrong timezone supplied')
73+
raise InvalidTimezoneError()
6774
self.timezone = timezone
6875

6976
def getBaseHeaders(self):

gpapi/googleplay.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def __init__(self, value):
5353
def __str__(self):
5454
return repr(self.value)
5555

56+
class SecurityCheckError(Exception):
57+
pass
58+
5659

5760
class GooglePlayAPI(object):
5861
"""Google Play Unofficial API Class
@@ -217,9 +220,7 @@ def login(self, email=None, password=None, gsfId=None, authSubToken=None):
217220
ac2dmToken = params["auth"]
218221
elif "error" in params:
219222
if "NeedsBrowser" in params["error"]:
220-
raise LoginError("Security check is needed, try to visit "
221-
"https://accounts.google.com/b/0/DisplayUnlockCaptcha "
222-
"to unlock, or setup an app-specific password")
223+
raise SecurityCheckError()
223224
raise LoginError("server says: " + params["error"])
224225
else:
225226
raise LoginError("Auth token not found.")

0 commit comments

Comments
 (0)