1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
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.
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.
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/>.
19 """Define useful encoding-extraction functions.
27 """Guess a useful input/output/filesystem encoding.
29 Maybe we need seperate encodings for input/output and filesystem?
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'
38 def get_input_encoding():
39 "Guess the input encoding."
42 def get_output_encoding():
43 "Guess the output encoding."
46 def get_filesystem_encoding():
47 "Guess the filesystem encoding."