diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-11-26 09:05:36 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-11-26 09:05:36 (GMT) |
commit | 52ea7e9244f673602a32beb4c0489bfdd59cb1d4 (patch) | |
tree | 0823ce987fa7a9e886814bbeb3cebb1122e27d73 | |
parent | 318b7b920d818f7da7040cbc5cc4696415eab7cc (diff) | |
download | cpython-52ea7e9244f673602a32beb4c0489bfdd59cb1d4.zip cpython-52ea7e9244f673602a32beb4c0489bfdd59cb1d4.tar.gz cpython-52ea7e9244f673602a32beb4c0489bfdd59cb1d4.tar.bz2 |
Patch #632973: Implement _getdefaultlocale for OS X.
-rw-r--r-- | Modules/_localemodule.c | 6 | ||||
-rw-r--r-- | Python/mactoolboxglue.c | 21 |
2 files changed, 19 insertions, 8 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index ab86fa4..4b654d5 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -30,7 +30,7 @@ This software comes with no warranty. Use at your own risk. #include <windows.h> #endif -#ifdef macintosh +#if __APPLE__ #include "macglue.h" #endif @@ -400,7 +400,7 @@ PyLocale_getdefaultlocale(PyObject* self) } #endif -#if defined(macintosh) +#if defined(__APPLE__) static PyObject* PyLocale_getdefaultlocale(PyObject* self) { @@ -627,7 +627,7 @@ static struct PyMethodDef PyLocale_Methods[] = { METH_VARARGS, strcoll__doc__}, {"strxfrm", (PyCFunction) PyLocale_strxfrm, METH_VARARGS, strxfrm__doc__}, -#if defined(MS_WINDOWS) || defined(macintosh) +#if defined(MS_WINDOWS) || defined(__APPLE__) {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS}, #endif #ifdef HAVE_LANGINFO_H diff --git a/Python/mactoolboxglue.c b/Python/mactoolboxglue.c index fc1d1af..6d39d57 100644 --- a/Python/mactoolboxglue.c +++ b/Python/mactoolboxglue.c @@ -38,11 +38,22 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. char *PyMac_getscript() { #if TARGET_API_MAC_OSX - /* We cannot use GetSysFont because it requires the window manager - ** There are other APIs to query the default 8 bit encoding, but - ** I don't know about them (yet). - */ - return "ascii"; + CFStringEncoding enc = CFStringGetSystemEncoding(); + static CFStringRef name = NULL; + /* Return the code name for the encodings for which we have codecs. */ + switch(enc) { + case kCFStringEncodingMacRoman: return "mac-roman"; + case kCFStringEncodingMacGreek: return "mac-greek"; + case kCFStringEncodingMacCyrillic: return "mac-cyrillic"; + case kCFStringEncodingMacTurkish: return "mac-turkish"; + case kCFStringEncodingMacIcelandic: return "mac-icelandic"; + /* XXX which one is mac-latin2? */ + } + if (!name) { + /* This leaks a an object. */ + name = CFStringConvertEncodingToIANACharSetName(enc); + } + return CFStringGetCStringPtr(name, 0); #else int font, script, lang; font = 0; |