
python ../lib/test/regrtest.py test___all__
test___all__ test test___all__ crashed -- exceptions.AttributeError: 'locale' module has no attribute 'LC_MESSAGES' And indeed it does not:
python Python 2.1a1 (#9, Jan 24 2001, 04:40:55) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import locale dir(locale) ['CHAR_MAX', 'Error', 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_build_localename', '_group', '_parse_localename', '_print_locale', '_setlocale', '_test', 'atof', 'atoi', 'encoding_alias', 'format', 'getdefaultlocale', 'getlocale', 'locale_alias', 'localeconv', 'normalize', 'resetlocale', 'setlocale', 'str', 'strcoll', 'string', 'strxfrm', 'sys', 'windows_locale']
Nor is LC_MESSAGES std C (the other LC_XXX guys are). I pin the blame on from _locale import * in locale.py -- who knows what that's supposed to export? Certainly not Skip <wink>.

Tim> Nevermind; checked in a hack to stop the error on Windows. Probably should file a bug report (if you haven't already) so the root problem isn't forgotten because the hack obscures it. I see this code in localemodule.c: #ifdef LC_MESSAGES x = PyInt_FromLong(LC_MESSAGES); PyDict_SetItemString(d, "LC_MESSAGES", x); Py_XDECREF(x); #endif /* LC_MESSAGES */ Martin, looks like this module is your baby. Care to hazard a guess about whether LC_MESSAGES should always or never be there? Skip

Skip wrote:
Probably should file a bug report (if you haven't already) so the root problem isn't forgotten because the hack obscures it. I see this code in localemodule.c:
#ifdef LC_MESSAGES x = PyInt_FromLong(LC_MESSAGES); PyDict_SetItemString(d, "LC_MESSAGES", x); Py_XDECREF(x); #endif /* LC_MESSAGES */
Martin, looks like this module is your baby. Care to hazard a guess about whether LC_MESSAGES should always or never be there?
I think the correct answer is "sometimes": ANSI C mandates LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, and LC_TIME Unix mandates LC_ALL, LC_COLLATE,LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME in other words, if it's supported, it should be exposed by the Python bindings. Cheers /F

Fredrik> I think the correct answer is "sometimes": Fredrik> ANSI C mandates LC_ALL, LC_COLLATE, LC_CTYPE, Fredrik> LC_MONETARY, LC_NUMERIC, and LC_TIME Fredrik> Unix mandates LC_ALL, LC_COLLATE,LC_CTYPE, Fredrik> LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and Fredrik> LC_TIME Fredrik> in other words, if it's supported, it should be exposed by Fredrik> the Python bindings. Then this suggests that either Tim's hack is the correct fix (leave it out because we can't rely on it always being there) or I should add it to __all__ at the bottom of the file if and only if it's present in the module's namespace. Skip

Fredrik> I think the correct answer is "sometimes":
Fredrik> ANSI C mandates LC_ALL, LC_COLLATE, LC_CTYPE, Fredrik> LC_MONETARY, LC_NUMERIC, and LC_TIME
Fredrik> Unix mandates LC_ALL, LC_COLLATE,LC_CTYPE, Fredrik> LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and Fredrik> LC_TIME
Fredrik> in other words, if it's supported, it should be exposed by Fredrik> the Python bindings.
Then this suggests that either Tim's hack is the correct fix (leave it out because we can't rely on it always being there) or I should add it to __all__ at the bottom of the file if and only if it's present in the module's namespace.
The latter. --Guido van Rossum (home page: http://www.python.org/~guido/)

[Skip]
Then this suggests that either Tim's hack is the correct fix (leave it out because we can't rely on it always being there) or I should add it to __all__ at the bottom of the file if and only if it's present in the module's namespace.
What you suggest at the end *is* the hack I checked in. That is, it's already done. The existence of LC_MESSAGES is clearly platform-specific; if anyone can say for sure a priori *which* platforms it's available on, tell Fred Drake so he can update the docs accordingly.

On Wed, 24 Jan 2001 16:11:33 +0100, "Fredrik Lundh" <fredrik@effbot.org> wrote:
I think the correct answer is "sometimes":
ANSI C mandates LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, and LC_TIME
Unix mandates LC_ALL, LC_COLLATE,LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME
in other words, if it's supported, it should be exposed by the Python bindings.
In that case, the __all__ attribute in the module has to be calculated dynamically. Say, adding code like try: LC_MESSAGES except NameError: pass else: __all__.append('LC_MESSAGES') Ditto for anything else. Should I check in a patch? -- Moshe Zadka <sig@zadka.site.co.il> This is a signature anti-virus. Please stop the spread of signature viruses! Fingerprint: 4BD1 7705 EEC0 260A 7F21 4817 C7FC A636 46D0 1BD6

Moshe> In that case, the __all__ attribute in the module has to be Moshe> calculated dynamically. Say, adding code like No need. I've already got this exact change in my local copy and I'll be adding a few more __all__ lists later today. Skip

Hi, Skip Montanaro:
Tim> Nevermind; checked in a hack to stop the error on Windows.
Probably should file a bug report (if you haven't already) so the root problem isn't forgotten because the hack obscures it. I see this code in localemodule.c:
#ifdef LC_MESSAGES x = PyInt_FromLong(LC_MESSAGES); PyDict_SetItemString(d, "LC_MESSAGES", x); Py_XDECREF(x); #endif /* LC_MESSAGES */
Martin, looks like this module is your baby. Care to hazard a guess about whether LC_MESSAGES should always or never be there?
AFAI found out, LC_MESSAGES was added to the POSIX "standard" in Posix.2. Non-posix2 compatible systems probably miss the proper functionality behind 'setlocale()'. So the best solution would be to add a clever emulation/approximation of this feature, if the underlying platform (here windows) doesn't provide it. This would require to wrap 'setlocale()'. But I'm not sure how to emulate for example 'setlocale(LC_MESSAGES, 'DE_de') on a Windows box. May be it is impossible to achieve. What I would love to see is that the typical query 'setlocale(LC_MESSAGES)' would return 'DE_de' on a Box running for example the german version of Windows or MacOS. This would eliminate the need for ugly language selection menus on these platforms in a portable fashion. Regards, Peter

[Peter Funk]
... AFAI found out, LC_MESSAGES was added to the POSIX "standard" in Posix.2.
FYI, it appears that C99 declined to adopt this extension to C89, but don't know why (the C99 Rationale doesn't mention it). That means the vendors who don't already support it can (well, *will*) use the new C99 std as "a reason" to continue leaving it out.

Tim> Nor is LC_MESSAGES std C (the other LC_XXX guys are). Tim> I pin the blame on Tim> from _locale import * Tim> in locale.py -- who knows what that's supposed to export? Tim> Certainly not Skip <wink>. Was that a roundabout way of complimenting me for having found a bug? ;-) Skip
participants (6)
-
Fredrik Lundh
-
Guido van Rossum
-
Moshe Zadka
-
pf@artcom-gmbh.de
-
Skip Montanaro
-
Tim Peters