Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52ea7e9

Browse files
committed
Patch #632973: Implement _getdefaultlocale for OS X.
1 parent 318b7b9 commit 52ea7e9

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

Modules/_localemodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This software comes with no warranty. Use at your own risk.
3030
#include <windows.h>
3131
#endif
3232

33-
#ifdef macintosh
33+
#if __APPLE__
3434
#include "macglue.h"
3535
#endif
3636

@@ -400,7 +400,7 @@ PyLocale_getdefaultlocale(PyObject* self)
400400
}
401401
#endif
402402

403-
#if defined(macintosh)
403+
#if defined(__APPLE__)
404404
static PyObject*
405405
PyLocale_getdefaultlocale(PyObject* self)
406406
{
@@ -627,7 +627,7 @@ static struct PyMethodDef PyLocale_Methods[] = {
627627
METH_VARARGS, strcoll__doc__},
628628
{"strxfrm", (PyCFunction) PyLocale_strxfrm,
629629
METH_VARARGS, strxfrm__doc__},
630-
#if defined(MS_WINDOWS) || defined(macintosh)
630+
#if defined(MS_WINDOWS) || defined(__APPLE__)
631631
{"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
632632
#endif
633633
#ifdef HAVE_LANGINFO_H

Python/mactoolboxglue.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3838
char *PyMac_getscript()
3939
{
4040
#if TARGET_API_MAC_OSX
41-
/* We cannot use GetSysFont because it requires the window manager
42-
** There are other APIs to query the default 8 bit encoding, but
43-
** I don't know about them (yet).
44-
*/
45-
return "ascii";
41+
CFStringEncoding enc = CFStringGetSystemEncoding();
42+
static CFStringRef name = NULL;
43+
/* Return the code name for the encodings for which we have codecs. */
44+
switch(enc) {
45+
case kCFStringEncodingMacRoman: return "mac-roman";
46+
case kCFStringEncodingMacGreek: return "mac-greek";
47+
case kCFStringEncodingMacCyrillic: return "mac-cyrillic";
48+
case kCFStringEncodingMacTurkish: return "mac-turkish";
49+
case kCFStringEncodingMacIcelandic: return "mac-icelandic";
50+
/* XXX which one is mac-latin2? */
51+
}
52+
if (!name) {
53+
/* This leaks a an object. */
54+
name = CFStringConvertEncodingToIANACharSetName(enc);
55+
}
56+
return CFStringGetCStringPtr(name, 0);
4657
#else
4758
int font, script, lang;
4859
font = 0;

0 commit comments

Comments
 (0)