Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Modules/_localemodule.c

    r60 r391  
    3333#endif
    3434
    35 #if defined(__APPLE__)
    36 #include <CoreFoundation/CoreFoundation.h>
    37 #endif
    38 
    3935#if defined(MS_WINDOWS)
    4036#define WIN32_LEAN_AND_MEAN
     
    6965
    7066    if (s[0] == '\0')
    71         /* empty string: no grouping at all */
    72         return PyList_New(0);
     67    /* empty string: no grouping at all */
     68    return PyList_New(0);
    7369
    7470    for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)
     
    174170        return NULL;
    175171
     172#if defined(MS_WINDOWS)
     173    if (category < LC_MIN || category > LC_MAX)
     174    {
     175        PyErr_SetString(Error, "invalid locale category");
     176        return NULL;
     177    }
     178#endif
     179
    176180    if (locale) {
    177         /* set locale */
    178         result = setlocale(category, locale);
    179         if (!result) {
    180             /* operation failed, no setting was changed */
    181             PyErr_SetString(Error, "unsupported locale setting");
    182             return NULL;
    183         }
    184         result_object = PyString_FromString(result);
    185         if (!result_object)
    186             return NULL;
    187         /* record changes to LC_CTYPE */
    188         if (category == LC_CTYPE || category == LC_ALL)
    189             fixup_ulcase();
     181    /* set locale */
     182    result = setlocale(category, locale);
     183    if (!result) {
     184        /* operation failed, no setting was changed */
     185        PyErr_SetString(Error, "unsupported locale setting");
     186        return NULL;
     187    }
     188    result_object = PyString_FromString(result);
     189    if (!result_object)
     190        return NULL;
     191    /* record changes to LC_CTYPE */
     192    if (category == LC_CTYPE || category == LC_ALL)
     193        fixup_ulcase();
    190194        /* things that got wrong up to here are ignored */
    191195        PyErr_Clear();
    192196    } else {
    193         /* get locale */
     197    /* get locale */
    194198        result = setlocale(category, NULL);
    195199        if (!result) {
     
    279283#if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)
    280284    char *s1,*s2;
    281    
     285
    282286    if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
    283287        return NULL;
     
    287291    wchar_t *ws1 = NULL, *ws2 = NULL;
    288292    int rel1 = 0, rel2 = 0, len1, len2;
    289    
     293
    290294    if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
    291295        return NULL;
     
    300304    /* Convert the non-unicode argument to unicode. */
    301305    if (!PyUnicode_Check(os1)) {
    302         os1 = PyUnicode_FromObject(os1);
    303         if (!os1)
    304             return NULL;
     306    os1 = PyUnicode_FromObject(os1);
     307    if (!os1)
     308        return NULL;
    305309        rel1 = 1;
    306310    }
     
    312316            }
    313317            return NULL;
    314         } 
     318        }
    315319        rel2 = 1;
    316320    }
     
    419423#endif
    420424
    421 #if defined(__APPLE__)
    422 /*
    423 ** Find out what the current script is.
    424 ** Donated by Fredrik Lundh.
    425 */
    426 static char *mac_getscript(void)
    427 {
    428     CFStringEncoding enc = CFStringGetSystemEncoding();
    429     static CFStringRef name = NULL;
    430     /* Return the code name for the encodings for which we have codecs. */
    431     switch(enc) {
    432     case kCFStringEncodingMacRoman: return "mac-roman";
    433     case kCFStringEncodingMacGreek: return "mac-greek";
    434     case kCFStringEncodingMacCyrillic: return "mac-cyrillic";
    435     case kCFStringEncodingMacTurkish: return "mac-turkish";
    436     case kCFStringEncodingMacIcelandic: return "mac-icelandic";
    437     /* XXX which one is mac-latin2? */
    438     }
    439     if (!name) {
    440         /* This leaks an object. */
    441         name = CFStringConvertEncodingToIANACharSetName(enc);
    442     }
    443     return (char *)CFStringGetCStringPtr(name, 0);
    444 }
    445 
    446 static PyObject*
    447 PyLocale_getdefaultlocale(PyObject* self)
    448 {
    449     return Py_BuildValue("Os", Py_None, mac_getscript());
    450 }
    451 #endif
    452 
    453425#if defined(__KLIBC__)
    454426static PyObject*
     
    475447#define LANGINFO(X) {#X, X}
    476448static struct langinfo_constant{
    477         char* name;
    478         int value;
    479 } langinfo_constants[] = 
     449    char* name;
     450    int value;
     451} langinfo_constants[] =
    480452{
    481453    /* These constants should exist on any langinfo implementation */
     
    590562    int item, i;
    591563    if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
    592         return NULL;
     564    return NULL;
    593565    /* Check whether this is a supported constant. GNU libc sometimes
    594566       returns numeric values in the char* return value, which would
     
    615587PyIntl_gettext(PyObject* self, PyObject *args)
    616588{
    617         char *in;
    618         if (!PyArg_ParseTuple(args, "s", &in))
    619                 return 0;
    620         return PyString_FromString(gettext(in));
     589    char *in;
     590    if (!PyArg_ParseTuple(args, "s", &in))
     591        return 0;
     592    return PyString_FromString(gettext(in));
    621593}
    622594
     
    628600PyIntl_dgettext(PyObject* self, PyObject *args)
    629601{
    630         char *domain, *in;
    631         if (!PyArg_ParseTuple(args, "zs", &domain, &in))
    632                 return 0;
    633         return PyString_FromString(dgettext(domain, in));
     602    char *domain, *in;
     603    if (!PyArg_ParseTuple(args, "zs", &domain, &in))
     604        return 0;
     605    return PyString_FromString(dgettext(domain, in));
    634606}
    635607
     
    641613PyIntl_dcgettext(PyObject *self, PyObject *args)
    642614{
    643         char *domain, *msgid;
    644         int category;
    645         if (!PyArg_ParseTuple(args, "zsi", &domain, &msgid, &category))
    646                 return 0;
    647         return PyString_FromString(dcgettext(domain,msgid,category));
     615    char *domain, *msgid;
     616    int category;
     617    if (!PyArg_ParseTuple(args, "zsi", &domain, &msgid, &category))
     618        return 0;
     619    return PyString_FromString(dcgettext(domain,msgid,category));
    648620}
    649621
     
    655627PyIntl_textdomain(PyObject* self, PyObject* args)
    656628{
    657         char *domain;
    658         if (!PyArg_ParseTuple(args, "z", &domain))
    659                 return 0;
    660         domain = textdomain(domain);
    661         if (!domain) {
    662                 PyErr_SetFromErrno(PyExc_OSError);
    663                 return NULL;
    664         }
    665         return PyString_FromString(domain);
     629    char *domain;
     630    if (!PyArg_ParseTuple(args, "z", &domain))
     631        return 0;
     632    domain = textdomain(domain);
     633    if (!domain) {
     634        PyErr_SetFromErrno(PyExc_OSError);
     635        return NULL;
     636    }
     637    return PyString_FromString(domain);
    666638}
    667639
     
    673645PyIntl_bindtextdomain(PyObject* self,PyObject*args)
    674646{
    675         char *domain, *dirname;
    676         if (!PyArg_ParseTuple(args, "sz", &domain, &dirname))
    677                 return 0;
    678         if (!strlen(domain)) {
    679                 PyErr_SetString(Error, "domain must be a non-empty string");
    680                 return 0;
    681         }
    682         dirname = bindtextdomain(domain, dirname);
    683         if (!dirname) {
    684                 PyErr_SetFromErrno(PyExc_OSError);
    685                 return NULL;
    686         }
    687         return PyString_FromString(dirname);
     647    char *domain, *dirname;
     648    if (!PyArg_ParseTuple(args, "sz", &domain, &dirname))
     649        return 0;
     650    if (!strlen(domain)) {
     651        PyErr_SetString(Error, "domain must be a non-empty string");
     652        return 0;
     653    }
     654    dirname = bindtextdomain(domain, dirname);
     655    if (!dirname) {
     656        PyErr_SetFromErrno(PyExc_OSError);
     657        return NULL;
     658    }
     659    return PyString_FromString(dirname);
    688660}
    689661
     
    696668PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
    697669{
    698         char *domain,*codeset;
    699         if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
    700                 return NULL;
    701         codeset = bind_textdomain_codeset(domain, codeset);
    702         if (codeset)
    703                 return PyString_FromString(codeset);
    704         Py_RETURN_NONE;
     670    char *domain,*codeset;
     671    if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
     672        return NULL;
     673    codeset = bind_textdomain_codeset(domain, codeset);
     674    if (codeset)
     675        return PyString_FromString(codeset);
     676    Py_RETURN_NONE;
    705677}
    706678#endif
     
    709681
    710682static struct PyMethodDef PyLocale_Methods[] = {
    711   {"setlocale", (PyCFunction) PyLocale_setlocale, 
     683  {"setlocale", (PyCFunction) PyLocale_setlocale,
    712684   METH_VARARGS, setlocale__doc__},
    713   {"localeconv", (PyCFunction) PyLocale_localeconv, 
     685  {"localeconv", (PyCFunction) PyLocale_localeconv,
    714686   METH_NOARGS, localeconv__doc__},
    715   {"strcoll", (PyCFunction) PyLocale_strcoll, 
     687  {"strcoll", (PyCFunction) PyLocale_strcoll,
    716688   METH_VARARGS, strcoll__doc__},
    717   {"strxfrm", (PyCFunction) PyLocale_strxfrm, 
     689  {"strxfrm", (PyCFunction) PyLocale_strxfrm,
    718690   METH_VARARGS, strxfrm__doc__},
    719 #if defined(MS_WINDOWS) || defined(__APPLE__) || defined(__KLIBC__)
     691#if defined(MS_WINDOWS) || defined(__KLIBC__)
    720692  {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
    721693#endif
     
    739711   METH_VARARGS, bind_textdomain_codeset__doc__},
    740712#endif
    741 #endif 
     713#endif
    742714  {NULL, NULL}
    743715};
     
    753725    m = Py_InitModule("_locale", PyLocale_Methods);
    754726    if (m == NULL)
    755         return;
     727    return;
    756728
    757729    d = PyModule_GetDict(m);
     
    800772#ifdef HAVE_LANGINFO_H
    801773    for (i = 0; langinfo_constants[i].name; i++) {
    802             PyModule_AddIntConstant(m, langinfo_constants[i].name,
    803                                     langinfo_constants[i].value);
    804     }
    805 #endif
    806 }
    807 
    808 /* 
     774        PyModule_AddIntConstant(m, langinfo_constants[i].name,
     775                                langinfo_constants[i].value);
     776    }
     777#endif
     778}
     779
     780/*
    809781Local variables:
    810782c-basic-offset: 4
Note: See TracChangeset for help on using the changeset viewer.