Skip to content

Commit c61819d

Browse files
author
Domenico Iezzi
committed
Fix #22
Now gpapi checks if the locale retrieved from system or provided by the user is valid. In case it's invalid, default to en_US.
1 parent ac2d07a commit c61819d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

gpapi/config.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from os import path
44
from sys import version_info
55
from locale import getdefaultlocale
6+
from re import match
67

78
VERSION = version_info[0]
89
if VERSION == 2:
@@ -48,11 +49,20 @@ class DeviceBuilder(object):
4849

4950
def __init__(self, device):
5051
self.device = {}
51-
self.locale = getdefaultlocale()[0]
5252
self.timezone = "Europe/Berlin"
5353
for (key, value) in config.items(device):
5454
self.device[key] = value
5555

56+
def setLocale(self, locale):
57+
if locale is None:
58+
locale = getdefaultlocale()[0]
59+
60+
# check if locale matches the structure of a common
61+
# value like "en_US"
62+
if match(r'[a-z]{2}\_[A-Z]{2}', locale) is None:
63+
locale = 'en_US'
64+
self.locale = locale
65+
5666
def getUserAgent(self):
5767
return ("Android-Finsky/8.1.72.S-all [6] [PR] 165478484 ("
5868
"api=3"

gpapi/googleplay.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def __init__(self, debug=False, device_codename='bacon',
5252
self.gsfId = None
5353
self.debug = debug
5454
self.deviceBuilder = config.DeviceBuilder(device_codename)
55-
if locale is not None:
56-
self.deviceBuilder.locale = locale
55+
self.deviceBuilder.setLocale(locale)
5756
if timezone is not None:
5857
self.deviceBuilder.timezone = timezone
5958
if sim_operator is not None:

0 commit comments

Comments
 (0)