[Spambayes] [ spambayes-Bugs-725466 ] Include a proper locale fix
in Options.py
SourceForge.net
noreply at sourceforge.net
Sat May 10 12:35:18 EDT 2003
Bugs item #725466, was opened at 2003-04-22 16:07
Message generated for change (Comment added) made by mhammond
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=498103&aid=725466&group_id=61702
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tony Meyer (anadelonbrin)
>Assigned to: Mark Hammond (mhammond)
Summary: Include a proper locale fix in Options.py
Initial Comment:
When reading the options, the float() call fails when the
locale is a language that uses a ',' for a separator
instead of '.'. This is hack-fixed in Outlook, but needs to
be fixed in general.
I imagine that there must be some sort of locale call that
will convert between the current locale and English, and
that this should be called as the option is set.
Anyway, I'll get to this when I can.
----------------------------------------------------------------------
>Comment By: Mark Hammond (mhammond)
Date: 2003-05-11 04:35
Message:
Logged In: YES
user_id=14198
Damn. IIRC, MAPI also changes the cwd. I guess the
solution may be the same - check the locale before setting,
and reset explicitly afterwards. It would be great if you
can check this while you are still setup to test, but
otherwise it can stay on my todo list :)
----------------------------------------------------------------------
Comment By: Tony Meyer (anadelonbrin)
Date: 2003-05-09 13:23
Message:
Logged In: YES
user_id=552329
Ok, I did more digging. The locale set in addin.py isn't
enough. This line in msgstore.py screws up the locale:
self.session = mapi.MAPILogonEx(0, None, None,
logonFlags)
(it's in the __init__ of MAPIMsgStore; my line numbers are all
screwed up).
(by 'screws up the locale', I mean that math.log(2) returns a
number with a '.' decimal separator before it, and a ',' decimal
separator afterwards).
I'll leave it to Mark to figure out what should be done.
----------------------------------------------------------------------
Comment By: Tony Meyer (anadelonbrin)
Date: 2003-05-09 13:15
Message:
Logged In: YES
user_id=552329
Ok, forget that, I've found a way I can reproduce a similar
error.
This is definately Outlook specific, and definately cannot be
fixed in the spambayes code, except by changing the locale
to 'en' or 'c', or something similar.
Ignoring spambayes completely, and using the demo outlook
plugin that comes with the win32com extensions, I printed
out the results of math.log(2). This should be "0.69314718056
" and not "0,69314718056". I made this print statement
pretty much every second line. When adding, it always gives
the correct answer. As soon as Outlook is started up, it
gives the wrong answer.
It's beyond me whether this is something that the win32com
stuff does (although importing the extensions doesn't cause
it), or if it's something that Outlook does, somehow. No
doubt you can answer that, Mark? ;)
Anyway, unless a change to the win32com stuff occurs, this
will have to remain in the spambayes Outlook code. (The
options stuff is a separate problem, and my fix for that should
work). It doesn't need to be outside the Outlook code though.
----------------------------------------------------------------------
Comment By: Tony Meyer (anadelonbrin)
Date: 2003-05-09 12:22
Message:
Logged In: YES
user_id=552329
What I don't understand is why I can't reproduce this error. If I
make the same addition to manager.py, but use 'german'[1]
as the locale, everything still works. (It also still works if I
make the change in addin.py where the other locale set is,
and also if I change the locale to german in the windows
control panel).
In addition, why does the import from PythonWin work?
Surely this means (as mentioned) that something else that is
imported is screwing up the locale setting before random gets
imported - but then, shouldn't it do this on my machine, too?
Googling on this (NV_MAGICCONST) brings up lots of
instances of the problem, but nothing in the way of a solution
apart from setting the locale to 'en' or 'c' before the random
import. This really doesn't seem like the correct solution.
I really am tempted to try my luck with c.l.p for a solution, if
there aren't any more ideas here.
[1] I can't set to "de_DE", I get a locale not supported
error. "german" does use ',' as the decimal separator, so it
should be the same, though.
----------------------------------------------------------------------
Comment By: Stefan Gründel (sgruendel)
Date: 2003-05-09 03:59
Message:
Logged In: YES
user_id=671479
Ok, I've got it working by setting the locale in the constructor
of class BayesManager (manager.py):
[...]
self.config_filename = config_base
+ "_configuration.pck"
print "locale: ", locale.getlocale()
print "default locale: ", locale.getdefaultlocale()
locale.setlocale(locale.LC_NUMERIC, "en")
# First read the configuration file.
[...]
Locale/default locale are both de_DE for me.
----------------------------------------------------------------------
Comment By: Stefan Gründel (sgruendel)
Date: 2003-05-09 03:45
Message:
Logged In: YES
user_id=671479
>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, "en")
'English_United States.1252'
>>> import random
>>>
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2003-05-07 20:49
Message:
Logged In: YES
user_id=14198
What happens if you go into Pythonwin/IDLE, execute the
locale call mentioned, then import that module?
>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, "en")
----------------------------------------------------------------------
Comment By: Stefan Gründel (sgruendel)
Date: 2003-05-07 19:42
Message:
Logged In: YES
user_id=671479
The import works fine both in IDLE and PythonWin. I suspect
the handling of floats is somehow broken by something
loaded by Outlook or Python Windows Extensions. But then I
don't really know enough about the architecture to make
educated guesses ...
Anyway I wonder why float handling at this low level seems to
be locale dependent? Parsing text and converting to float is
ok to be locale depedent, but doing calculations?
----------------------------------------------------------------------
Comment By: Tony Meyer (anadelonbrin)
Date: 2003-05-07 09:37
Message:
Logged In: YES
user_id=552329
This makes me wonder if the locale just needs to be set, but
that seems too heavy-handed and ugly, really.
What happens if you just execute
>>> import random
from the interpreter (e.g. in PythonWin or IDLE)?
I suspect that you'll get the same trace, in which case this
really should be fixed in random.py, not in Spambayes
(although it would be easy enough to throw together a hack
for it).
----------------------------------------------------------------------
Comment By: Stefan Gründel (sgruendel)
Date: 2003-05-07 00:18
Message:
Logged In: YES
user_id=671479
It seems like it's not enough to fix Options.py only. I did this
and then got the following error:
Traceback (most recent call last):
File "D:\dev\Python22\lib\site-
packages\win32com\universal.py", line 170, in dispatch
retVal = ob._InvokeEx_(meth.dispid, 0, meth.invkind, args,
None, None)
File "D:\dev\Python22\lib\site-
packages\win32com\server\policy.py", line 322, in _InvokeEx_
return self._invokeex_(dispid, lcid, wFlags, args, kwargs,
serviceProvider)
File "D:\dev\Python22\lib\site-
packages\win32com\server\policy.py", line 601, in _invokeex_
return DesignatedWrapPolicy._invokeex_( self, dispid, lcid,
wFlags, args, kwArgs, serviceProvider)
File "D:\dev\Python22\lib\site-
packages\win32com\server\policy.py", line 541, in _invokeex_
return apply(func, args)
File "D:\util\spambayes-1.0a2\Outlook2000\addin.py", line
611, in OnConnection
self.manager = manager.GetManager(application)
File "D:\util\spambayes-1.0a2\Outlook2000\manager.py",
line 335, in GetManager
_mgr = BayesManager(outlook=outlook, verbose=verbose)
File "D:\util\spambayes-1.0a2\Outlook2000\manager.py",
line 79, in __init__
import_core_spambayes_stuff(self.ini_filename)
File "D:\util\spambayes-1.0a2\Outlook2000\manager.py",
line 53, in import_core_spambayes_stuff
from spambayes.tokenizer import tokenize
File "D:\util\spambayes-1.0a2\spambayes\tokenizer.py",
line 7, in ?
import email.Message
File "D:\dev\Python22\Lib\email\Message.py", line 14, in ?
from email import Utils
File "D:\dev\Python22\Lib\email\Utils.py", line 10, in ?
import random
File "D:\dev\Python22\Lib\random.py", line 93, in ?
_verify('NV_MAGICCONST', NV_MAGICCONST,
1.71552776992141)
File "D:\dev\Python22\Lib\random.py", line 88, in _verify
raise ValueError(
exceptions.ValueError: computed value for
NV_MAGICCONST deviates too much (computed 2,82843,
expected 1)
Obviously random.py uses ',' too! I'm using german
Windows/Outlook, if I can be of any help in testing, just drop
me a mail.
----------------------------------------------------------------------
Comment By: Tony Meyer (anadelonbrin)
Date: 2003-04-24 16:30
Message:
Logged In: YES
user_id=552329
Options.py now uses locale.atoi and locale.atof to convert
options. I *think* this will solve this problem, but I'm not
100%.
If someone could do some testing, that would be great. I'm
leaving open until I'm sure it's done.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=498103&aid=725466&group_id=61702
More information about the Spambayes
mailing list