Added check for unset locale.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -40,8 +41,6 @@ def main():
|
||||
# These ones get triggered even when capturing warnings is turned on
|
||||
warnings.simplefilter('ignore', ResourceWarning) #pylint:disable=E0602
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
# Set the terminal title
|
||||
if os.getenv('DISPLAY'):
|
||||
title = 'rtv {0}'.format(__version__)
|
||||
@@ -103,6 +102,15 @@ def main():
|
||||
# Add an empty handler so the logger doesn't complain
|
||||
logging.root.addHandler(logging.NullHandler())
|
||||
|
||||
# Make sure the locale is UTF-8 for unicode support
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
|
||||
if not encoding or encoding.lower() != 'utf-8':
|
||||
text = ('System encoding was detected as (%s) instead of UTF-8'
|
||||
', falling back to ascii only mode' % encoding)
|
||||
warnings.warn(text)
|
||||
config['ascii'] = True
|
||||
|
||||
# Construct the reddit user agent
|
||||
user_agent = docs.AGENT.format(version=__version__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user