Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*pyc
fabfile.py
*swp
12 changes: 11 additions & 1 deletion command-not-found
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ try:
import gettext
import locale
import sys
import os
from optparse import OptionParser

from CommandNotFound.util import crash_guard
Expand All @@ -26,7 +27,16 @@ def enable_i18n():
if sys.version < '3':
kwargs["unicode"] = True
cnf.install(**kwargs)
locale.setlocale(locale.LC_ALL, '')

try:
locale.setlocale(locale.LC_ALL, '')
except locale.Error as exc:
# Fixing the case when remote system sends incorrect LC_CTYPE via SSH
if os.environ['LC_CTYPE'] == 'UTF-8': # Mac OS X
# Set the locale based on LANG environmental variable
locale.setlocale(locale.LC_ALL, os.environ['LANG'].split('.'))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do os.environ.get("LANG", "some default") to be extra paranoid.

Why do you split() it on the '.' character? That will return an array, did you want to get the first component of that?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do os.environ.get("LANG", "some default") to be extra paranoid.

Makes sense

Why do you split() it on the '.' character? That will return an array, did you want to get the first component of that?

No, but you're right — there's no need to do a split. I was a bit confused by example in documentation, where setlocale is called with a tuple ("en_us", "UTF-8") as a second argument, but a string is okay too.

Fixing that in next commit.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the spec says you can put some kind of expressions there, like en_US.UTF-8;fr_FR.UTF-8 for example, I think it's best to minimize our need to parse that

else:
raise exc


def fix_sys_argv(encoding=None):
Expand Down