mirror of
https://github.com/caronc/apprise.git
synced 2025-01-01 03:29:53 +01:00
ValueError unknown locale error fix (#128)
This commit is contained in:
parent
92523f191b
commit
e7ba4c03df
@ -30,6 +30,7 @@ import contextlib
|
|||||||
from os.path import join
|
from os.path import join
|
||||||
from os.path import dirname
|
from os.path import dirname
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
|
from .logger import logger
|
||||||
|
|
||||||
# Define our translation domain
|
# Define our translation domain
|
||||||
DOMAIN = 'apprise'
|
DOMAIN = 'apprise'
|
||||||
@ -207,6 +208,16 @@ class AppriseLocale(object):
|
|||||||
# Detect language
|
# Detect language
|
||||||
lang = locale.getdefaultlocale()[0]
|
lang = locale.getdefaultlocale()[0]
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
# This occurs when an invalid locale was parsed from the
|
||||||
|
# environment variable. While we still return None in this
|
||||||
|
# case, we want to better notify the end user of this. Users
|
||||||
|
# receiving this error should check their environment
|
||||||
|
# variables.
|
||||||
|
logger.warning(
|
||||||
|
'Language detection failure / {}'.format(str(e)))
|
||||||
|
return None
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# None is returned if the default can't be determined
|
# None is returned if the default can't be determined
|
||||||
# we're done in this case
|
# we're done in this case
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
|
import os
|
||||||
import mock
|
import mock
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
@ -169,6 +170,16 @@ def test_detect_language_windows_users():
|
|||||||
# Detect french language
|
# Detect french language
|
||||||
assert AppriseLocale.AppriseLocale.detect_language() == 'fr'
|
assert AppriseLocale.AppriseLocale.detect_language() == 'fr'
|
||||||
|
|
||||||
|
# The following unsets all enviroment vaiables and sets LC_CTYPE
|
||||||
|
# This was causing Python 2.7 to internally parse UTF-8 as an invalid
|
||||||
|
# locale and throw an uncaught ValueError
|
||||||
|
with environ(*list(os.environ.keys()), LC_CTYPE="UTF-8"):
|
||||||
|
assert AppriseLocale.AppriseLocale.detect_language() is None
|
||||||
|
|
||||||
|
# Test with absolutely no environment variables what-so-ever
|
||||||
|
with environ(*list(os.environ.keys())):
|
||||||
|
assert AppriseLocale.AppriseLocale.detect_language() is None
|
||||||
|
|
||||||
# Tidy
|
# Tidy
|
||||||
delattr(ctypes, 'windll')
|
delattr(ctypes, 'windll')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user