Ran update_copyright.py which updated hooke.util.encoding
[hooke.git] / hooke / util / encoding.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 """Define useful encoding-extraction functions.
20 """
21
22 import locale
23 import sys
24
25
26 def get_encoding():
27     """Guess a useful input/output/filesystem encoding.
28
29     Maybe we need seperate encodings for input/output and filesystem?
30     Hmm.
31     """
32     encoding = locale.getpreferredencoding() or sys.getdefaultencoding()
33     if sys.platform != 'win32' or sys.version_info[:2] > (2, 3):
34         encoding = locale.getlocale(locale.LC_TIME)[1] or encoding
35         # Python 2.3 on windows doesn't know about 'XYZ' alias for 'cpXYZ'
36     return encoding
37
38 def get_input_encoding():
39     "Guess the input encoding."
40     return get_encoding()
41
42 def get_output_encoding():
43     "Guess the output encoding."
44     return get_encoding()
45
46 def get_filesystem_encoding():
47     "Guess the filesystem encoding."
48     return get_encoding()