Changeset 60 for python


Ignore:
Timestamp:
Oct 22, 2010, 10:46:09 PM (15 years ago)
Author:
Yuri Dario
Message:

python: use current codepage as charset in locale settings.

Location:
python/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • python/trunk/Lib/gettext.py

    r2 r60  
    150150    else:
    151151        codeset = ''
     152       
     153    # use new os2 code to get current codepage
     154    if pos == -1 and os.name == "os2":
     155        import _locale
     156        codeset = _locale._getdefaultlocale()[1]
     157        mask |= COMPONENT_CODESET
     158
    152159    pos = locale.find('_')
    153160    if pos >= 0:
  • python/trunk/Lib/locale.py

    r2 r60  
    342342        encoding = ''
    343343
     344    if sys.platform[:3] == "os2":
     345        import _locale
     346        langname, encoding = _locale._getdefaultlocale()
     347        langname = langname.replace('_euro', '')
     348
    344349    # First lookup: fullname (possibly with encoding)
    345350    norm_encoding = encoding.replace('-', '')
     
    523528    _setlocale(category, _build_localename(getdefaultlocale()))
    524529
    525 if sys.platform in ('win32', 'darwin', 'mac'):
     530if sys.platform in ('win32', 'darwin', 'mac', 'os2knix'):
    526531    # On Win32, this will return the ANSI code page
    527532    # On the Mac, it should return the system encoding;
  • python/trunk/Modules/_localemodule.c

    r2 r60  
    4040#define WIN32_LEAN_AND_MEAN
    4141#include <windows.h>
     42#endif
     43
     44#if defined(__KLIBC__)
     45#define INCL_DOS
     46#define INCL_DOSERRORS
     47#include <os2.h>
    4248#endif
    4349
     
    445451#endif
    446452
     453#if defined(__KLIBC__)
     454static PyObject*
     455PyLocale_getdefaultlocale(PyObject* self)
     456{
     457    char encoding[100];
     458    char locale[100];
     459    ULONG cp[3];
     460    ULONG cplen;
     461
     462    strcpy( locale, "");
     463    if (getenv("LANG"))
     464        strcpy( locale, getenv("LANG"));
     465
     466    strcpy( encoding, "");
     467    if (DosQueryCp (sizeof (cp), cp, &cplen) == NO_ERROR)
     468        PyOS_snprintf(encoding, sizeof(encoding), "CP%u", cp[0]);
     469
     470    return Py_BuildValue("ss", locale, encoding);
     471}
     472#endif
     473
    447474#ifdef HAVE_LANGINFO_H
    448475#define LANGINFO(X) {#X, X}
     
    690717  {"strxfrm", (PyCFunction) PyLocale_strxfrm,
    691718   METH_VARARGS, strxfrm__doc__},
    692 #if defined(MS_WINDOWS) || defined(__APPLE__)
     719#if defined(MS_WINDOWS) || defined(__APPLE__) || defined(__KLIBC__)
    693720  {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
    694721#endif
Note: See TracChangeset for help on using the changeset viewer.