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.
This commit is contained in:
Domenico Iezzi 2017-11-13 11:44:15 +01:00
parent ac2d07a8c9
commit c61819d00b
No known key found for this signature in database
GPG Key ID: 7AC94D5DDA2FB7EE
2 changed files with 12 additions and 3 deletions

View File

@ -3,6 +3,7 @@ from time import time
from os import path
from sys import version_info
from locale import getdefaultlocale
from re import match
VERSION = version_info[0]
if VERSION == 2:
@ -48,11 +49,20 @@ class DeviceBuilder(object):
def __init__(self, device):
self.device = {}
self.locale = getdefaultlocale()[0]
self.timezone = "Europe/Berlin"
for (key, value) in config.items(device):
self.device[key] = value
def setLocale(self, locale):
if locale is None:
locale = getdefaultlocale()[0]
# 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:
locale = 'en_US'
self.locale = locale
def getUserAgent(self):
return ("Android-Finsky/8.1.72.S-all [6] [PR] 165478484 ("
"api=3"

View File

@ -52,8 +52,7 @@ class GooglePlayAPI(object):
self.gsfId = None
self.debug = debug
self.deviceBuilder = config.DeviceBuilder(device_codename)
if locale is not None:
self.deviceBuilder.locale = locale
self.deviceBuilder.setLocale(locale)
if timezone is not None:
self.deviceBuilder.timezone = timezone
if sim_operator is not None: