# HG changeset patch # User Paul Boddie # Date 1481840748 -3600 # Node ID 4ef5d5e656c050d269771a1ebb876f8a921bc04f # Parent 1fc56d3a9ac851cc3221f0d34b232028d1dfdcae Added a getpreferredencoding function. diff -r 1fc56d3a9ac8 -r 4ef5d5e656c0 lib/locale.py --- a/lib/locale.py Thu Dec 15 23:25:10 2016 +0100 +++ b/lib/locale.py Thu Dec 15 23:25:48 2016 +0100 @@ -30,6 +30,32 @@ LC_MESSAGES = 5 LC_ALL = 6 +def getlocale(category=LC_CTYPE): + + "Return the locale value for 'category'." + + check_int(category) + return _getlocale(category) + +def getpreferredencoding(): + + "Return the encoding from the environment's locale." + + s = getlocale() + + try: + dot = s.index(".") + return s[dot+1:] + except ValueError: + return None + +def initlocale(category=LC_CTYPE): + + "Initialise the locale for 'category' from the environment." + + check_int(category) + return _setlocale(category, "") + def setlocale(category, value): "Set the locale for 'category' to 'value'." @@ -38,18 +64,4 @@ check_string(value) return _setlocale(category, value) -def getlocale(category=LC_CTYPE): - - "Return the locale value for 'category'." - - check_int(category) - return _getlocale(category) - -def initlocale(category=LC_CTYPE): - - "Initialise the locale for 'category' from the environment." - - check_int(category) - return _setlocale(category, "") - # vim: tabstop=4 expandtab shiftwidth=4