[Spambayes] [ spambayes-Bugs-725466 ] Include a proper locale fix in Options.py

SourceForge.net noreply at sourceforge.net
Thu May 8 11:59:25 EDT 2003


Bugs item #725466, was opened at 2003-04-22 08:07
Message generated for change (Comment added) made by sgruendel
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: Tony Meyer (anadelonbrin)
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: Stefan Gründel (sgruendel)
Date: 2003-05-08 19: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-08 19: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 12: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 11: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 01: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-06 16: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 08: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