Skip to content

Commit

Permalink
Make it a bit harder to run into the LC_ALL thing
Browse files Browse the repository at this point in the history
This behavior is stupid. Respecting LC_ALL, or anything else for that
matter, over the encoding fucking noted in the fucking file is a bad
decision, and someone should feel bad. I don't know why it makes things
break in the specific and bizarre way it does, but it does, and there's
no possible good reason for it.

Closes #984. Fuck.
  • Loading branch information
embolalia committed Jan 17, 2016
1 parent 902e715 commit b73fc6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/sopel.service
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ExecStart=/usr/bin/sopel -c /etc/sopel.cfg
Restart=on-failure
RestartPreventExitStatus=2
RestartSec=30
Environment=LC_ALL=en_US.UTF-8

[Install]
WantedBy=multi-user.target
15 changes: 13 additions & 2 deletions sopel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# coding=utf-8
# ASCII ONLY IN THIS FILE THOUGH!!!!!!!
# Python does some stupid bullshit of respecting LC_ALL over the encoding on the
# file, so in order to undo Python's ridiculous fucking idiocy, we have to have
# our own check.

# Copyright 2008, Sean B. Palmer, inamidst.com
# Copyright 2012, Elsie Powell, http://embolalia.com
# Copyright © 2012, Elad Alfassa <[email protected]>
# Copyright 2012, Elad Alfassa <[email protected]>
#
# Licensed under the Eiffel Forum License 2.

from __future__ import unicode_literals, absolute_import, print_function, division
import os
import sys
if hasattr(os, "getenv") and os.getenv("LC_ALL") == "C":

This comment has been minimized.

Copy link
@elad661

elad661 Jan 17, 2016

Contributor

It might be safer to use locale.getlocale() and then check if the second part of the tuple is UTF-8, since python3 will run into issues when the locale encoding is not UTF8. There are a bunch of non-unicode locales that a Linux system (for example) can use, and you can type locale -a | grep \. | grep -v utf8 in your console to list all of the ones known to your version of libc.

By default, even on a normal environment, LC_ALL is unset, and then the value of LANG is is used. If both LC_ALL and LANG is unset, then the value of one of the other LC_(something) env vars is used (you can see them all by typing locale in your console).

If all of them are unset (for example if you type unset LANG, which resets all the others) the locale will change to "POSIX" (which is, I think, equivalent to "C") and that will cause problems.

print('WARNING!!! LC_ALL is set to "C", which makes Python do stupid '
'things. If you get strange errors, please unset it, or set it to '
'something like "en_US.UTF-8".', file=sys.stderr)


from collections import namedtuple
import os
import re
import time
import traceback
Expand Down

0 comments on commit b73fc6a

Please sign in to comment.