Bug in wx/_core.py about locale

Victor Stinner victor.stinner at haypocalc.com
Tue Dec 5 07:29:35 PST 2006


Hi,

Someone reported me an error in wxPython:

File "(...)\wx-2.7.2-msw-unicode\wx\_core.py", line 13684, in <module>
   default = locale.getdefaultlocale()[1]
AttributeError: 'module' object has no attribute 'getdefaultlocale'

You should replace the except by:
   except (ValueError, LookupError, TypeError, AttributeError):

---

To get the locale, I'm using:

def getTerminalCharset():
    """
    Guess terminal charset using differents tests:
    1. Try locale.getpreferredencoding()
    2. Try locale.nl_langinfo(CODESET)
    3. Try sys.stdout.encoding
    4. Otherwise, returns "ASCII"

    WARNING: Call initLocale() before calling this function, or:
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, "")
    """

    # (1) Try locale.getpreferredencoding()
    try:
        charset = locale.getpreferredencoding()
        if charset:
            return charset
    except (locale.Error, AttributeError):
        pass

    # (2) Try locale.nl_langinfo(CODESET)
    try:
        charset = locale.nl_langinfo(locale.CODESET)
        if charset:
            return charset
    except (locale.Error, AttributeError):
        pass

    # (3) Try sys.stdout.encoding
    if hasattr(sys.stdout, "encoding") and sys.stdout.encoding:
        return sys.stdout.encoding

    # (4) Otherwise, returns "ASCII"
    return "ASCII"

---

For information, I'm working on:
  http://hachoir.org/wiki/hachoir-wx

Haypo
PS: Please add my email in CC: to your answers.
-- 
Victor Stinner aka haypo
http://hachoir.org/




More information about the wxpython-dev mailing list