Added check for unset locale.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -40,8 +41,6 @@ def main():
|
|||||||
# These ones get triggered even when capturing warnings is turned on
|
# These ones get triggered even when capturing warnings is turned on
|
||||||
warnings.simplefilter('ignore', ResourceWarning) #pylint:disable=E0602
|
warnings.simplefilter('ignore', ResourceWarning) #pylint:disable=E0602
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
|
||||||
|
|
||||||
# Set the terminal title
|
# Set the terminal title
|
||||||
if os.getenv('DISPLAY'):
|
if os.getenv('DISPLAY'):
|
||||||
title = 'rtv {0}'.format(__version__)
|
title = 'rtv {0}'.format(__version__)
|
||||||
@@ -103,6 +102,15 @@ def main():
|
|||||||
# Add an empty handler so the logger doesn't complain
|
# Add an empty handler so the logger doesn't complain
|
||||||
logging.root.addHandler(logging.NullHandler())
|
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
|
# Construct the reddit user agent
|
||||||
user_agent = docs.AGENT.format(version=__version__)
|
user_agent = docs.AGENT.format(version=__version__)
|
||||||
|
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ class Page(object):
|
|||||||
|
|
||||||
if os.getenv('DISPLAY'):
|
if os.getenv('DISPLAY'):
|
||||||
title += ' - rtv {0}'.format(__version__)
|
title += ' - rtv {0}'.format(__version__)
|
||||||
sys.stdout.write('\x1b]2;{0}\x07'.format(title))
|
sys.stdout.write('\x1b]2;{0}\x07'.format(self.term.clean(title)))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
if self.reddit.user is not None:
|
if self.reddit.user is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user