[python-win32] Locale settings under python in windows.
Moof
moof at metamoof.net
Mon Oct 27 06:08:59 EST 2003
Hi there,
I'm currently trying to validate the input for a web form, the validator
for which is running under python 2.3 on windows (currently XP, but soon
2K). I'm validating text input, and trying something along the lines of:
namere = re.compile(u'''(?x) #verbose format
(?i) #ignore case
(?L) #Locale active -
#saves me defining accents, etc.
^ #start of string
[ #Start group
\w #all letters plus _
\ #space
\.,:' #some punctuation
Ἳ -/\\
\d #all digits
]+
$ #end of string
''')
and then rejecting the string if it does not match that regex. The thing
that gets me is \w. The Python 2.3 documentation specifies that \w will
include all letters in the current locale, which for me would be
('es_ES', 'cp1252') but it blatantly isn't:
>>> namere.match('hola')
<_sre.SRE_Match object at 0x01366918>
>>> namere.match('holá')
>>>
So a closer look reveals:
>>> locale.getlocale()
(None, None)
>>> locale.getdefaultlocale()
('es_ES', 'cp1252')
>>> locale.setlocale(locale.LC_CTYPE, locale.getdefaultlocale())
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\locale.py", line 381, in setlocale
return _setlocale(category, locale)
Error: locale setting not supported
Which basically buggers my regexp. How *can* I set locale, or how do I
get around this problem?
Moof
--
Giles Antonio Radford, a.k.a Moof
Sympathy, eupathy, and, currently, apathy coming to you at:
<http://metamoof.net/>
More information about the Python-win32
mailing list