Changeset 391 for python/trunk/Modules/_localemodule.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/_localemodule.c
r60 r391 33 33 #endif 34 34 35 #if defined(__APPLE__)36 #include <CoreFoundation/CoreFoundation.h>37 #endif38 39 35 #if defined(MS_WINDOWS) 40 36 #define WIN32_LEAN_AND_MEAN … … 69 65 70 66 if (s[0] == '\0') 71 72 67 /* empty string: no grouping at all */ 68 return PyList_New(0); 73 69 74 70 for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++) … … 174 170 return NULL; 175 171 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 176 180 if (locale) { 177 178 179 180 181 182 183 184 185 186 187 188 189 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(); 190 194 /* things that got wrong up to here are ignored */ 191 195 PyErr_Clear(); 192 196 } else { 193 197 /* get locale */ 194 198 result = setlocale(category, NULL); 195 199 if (!result) { … … 279 283 #if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE) 280 284 char *s1,*s2; 281 285 282 286 if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2)) 283 287 return NULL; … … 287 291 wchar_t *ws1 = NULL, *ws2 = NULL; 288 292 int rel1 = 0, rel2 = 0, len1, len2; 289 293 290 294 if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2)) 291 295 return NULL; … … 300 304 /* Convert the non-unicode argument to unicode. */ 301 305 if (!PyUnicode_Check(os1)) { 302 303 304 306 os1 = PyUnicode_FromObject(os1); 307 if (!os1) 308 return NULL; 305 309 rel1 = 1; 306 310 } … … 312 316 } 313 317 return NULL; 314 } 318 } 315 319 rel2 = 1; 316 320 } … … 419 423 #endif 420 424 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 #endif452 453 425 #if defined(__KLIBC__) 454 426 static PyObject* … … 475 447 #define LANGINFO(X) {#X, X} 476 448 static struct langinfo_constant{ 477 478 479 } langinfo_constants[] = 449 char* name; 450 int value; 451 } langinfo_constants[] = 480 452 { 481 453 /* These constants should exist on any langinfo implementation */ … … 590 562 int item, i; 591 563 if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item)) 592 564 return NULL; 593 565 /* Check whether this is a supported constant. GNU libc sometimes 594 566 returns numeric values in the char* return value, which would … … 615 587 PyIntl_gettext(PyObject* self, PyObject *args) 616 588 { 617 618 619 620 589 char *in; 590 if (!PyArg_ParseTuple(args, "s", &in)) 591 return 0; 592 return PyString_FromString(gettext(in)); 621 593 } 622 594 … … 628 600 PyIntl_dgettext(PyObject* self, PyObject *args) 629 601 { 630 631 632 633 602 char *domain, *in; 603 if (!PyArg_ParseTuple(args, "zs", &domain, &in)) 604 return 0; 605 return PyString_FromString(dgettext(domain, in)); 634 606 } 635 607 … … 641 613 PyIntl_dcgettext(PyObject *self, PyObject *args) 642 614 { 643 644 645 646 647 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)); 648 620 } 649 621 … … 655 627 PyIntl_textdomain(PyObject* self, PyObject* args) 656 628 { 657 658 659 660 661 662 663 664 665 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); 666 638 } 667 639 … … 673 645 PyIntl_bindtextdomain(PyObject* self,PyObject*args) 674 646 { 675 676 677 678 679 680 681 682 683 684 685 686 687 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); 688 660 } 689 661 … … 696 668 PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args) 697 669 { 698 699 700 701 702 703 704 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; 705 677 } 706 678 #endif … … 709 681 710 682 static struct PyMethodDef PyLocale_Methods[] = { 711 {"setlocale", (PyCFunction) PyLocale_setlocale, 683 {"setlocale", (PyCFunction) PyLocale_setlocale, 712 684 METH_VARARGS, setlocale__doc__}, 713 {"localeconv", (PyCFunction) PyLocale_localeconv, 685 {"localeconv", (PyCFunction) PyLocale_localeconv, 714 686 METH_NOARGS, localeconv__doc__}, 715 {"strcoll", (PyCFunction) PyLocale_strcoll, 687 {"strcoll", (PyCFunction) PyLocale_strcoll, 716 688 METH_VARARGS, strcoll__doc__}, 717 {"strxfrm", (PyCFunction) PyLocale_strxfrm, 689 {"strxfrm", (PyCFunction) PyLocale_strxfrm, 718 690 METH_VARARGS, strxfrm__doc__}, 719 #if defined(MS_WINDOWS) || defined(__ APPLE__) || defined(__KLIBC__)691 #if defined(MS_WINDOWS) || defined(__KLIBC__) 720 692 {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS}, 721 693 #endif … … 739 711 METH_VARARGS, bind_textdomain_codeset__doc__}, 740 712 #endif 741 #endif 713 #endif 742 714 {NULL, NULL} 743 715 }; … … 753 725 m = Py_InitModule("_locale", PyLocale_Methods); 754 726 if (m == NULL) 755 727 return; 756 728 757 729 d = PyModule_GetDict(m); … … 800 772 #ifdef HAVE_LANGINFO_H 801 773 for (i = 0; langinfo_constants[i].name; i++) { 802 803 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 /* 809 781 Local variables: 810 782 c-basic-offset: 4
Note:
See TracChangeset
for help on using the changeset viewer.