Skip to content

Commit

Permalink
Introduced new exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Domenico Iezzi committed Jul 15, 2018
1 parent e84a0d7 commit a83c2ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions gpapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
config.read(filepath)


class InvalidLocaleError(Exception):
pass

class InvalidTimezoneError(Exception):
pass


def getDevicesCodenames():
"""Returns a list containing devices codenames"""
return config.sections()
Expand All @@ -51,19 +58,19 @@ def __init__(self, device):
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):
Expand Down
7 changes: 4 additions & 3 deletions gpapi/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def __init__(self, value):
def __str__(self):
return repr(self.value)

class SecurityCheckError(Exception):
pass


class GooglePlayAPI(object):
"""Google Play Unofficial API Class
Expand Down Expand Up @@ -217,9 +220,7 @@ def login(self, email=None, password=None, gsfId=None, authSubToken=None):
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.")
Expand Down

0 comments on commit a83c2ab

Please sign in to comment.