Merge pull request #298 from michael-lazar/unset_locale

Unset locale
This commit is contained in:
Michael Lazar
2016-09-11 23:13:54 -07:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -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__)

View File

@@ -331,7 +331,7 @@ class Page(object):
if os.getenv('DISPLAY'):
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()
if self.reddit.user is not None: