Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'win32': 0.03; 'skip:[ 20': 0.04; 'output': 0.05; 'subject:Python': 0.06; 'subject:bug': 0.07; 'url:msdn': 0.07; 'imho.': 0.09; 'lawrence': 0.09; 'locale': 0.09; 'none)': 0.09; 'polish': 0.09; 'subject:2.7': 0.09; 'python': 0.11; 'bug': 0.12; 'suggest': 0.14; '2.7': 0.14; 'windows': 0.15; '(none,': 0.16; '3.3,': 0.16; '__future__': 0.16; 'collections': 0.16; 'czech': 0.16; 'finnish': 0.16; 'inc.)': 0.16; 'incorrect': 0.16; 'italian': 0.16; 'language)': 0.16; 'subject:)?': 0.16; 'subject:3.3': 0.16; 'tuple': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; 'have:': 0.19; 'seems': 0.21; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'skip:l 30': 0.24; 'tracker': 0.26; 'skip:" 20': 0.27; 'header:In-Reply- To:1': 0.27; 'record': 0.27; 'to:2**1': 0.27; 'unix': 0.29; 'skip:g 30': 0.30; 'skip:( 20': 0.30; "skip:' 10": 0.31; '"")': 0.31; 'loads': 0.31; 'portuguese': 0.31; 'sep': 0.31; 'though.': 0.31; 'checked': 0.32; 'languages': 0.32; 'skip:c 30': 0.32; 'open': 0.33; '-----': 0.33; 'bugs': 0.33; 'monday,': 0.33; 'maybe': 0.34; 'skip:d 20': 0.34; 'subject: (': 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'german': 0.35; 'there': 0.35; '8bit%:9': 0.36; 'right?': 0.36; 'doing': 0.36; 'useful': 0.36; 'hi,': 0.36; 'reports': 0.37; 'url:microsoft': 0.37; 'email addr:python.org': 0.37; 'expected': 0.38; 'sometimes': 0.38; 'others.': 0.38; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'issue': 0.38; 'little': 0.38; 'does': 0.39; 'subject:': 0.39; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'received:67.195': 0.60; 'received:98.137': 0.60; 'french': 0.61; 're:': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'email name:python-list': 0.65; 'here': 0.66; 'header:Reply-To:1': 0.67; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'url:en-us': 0.68; 'results': 0.69; 'url:%1': 0.72; 'russian': 0.74; '2015': 0.84; '3.4': 0.84; 'bug!': 0.84; 'greek': 0.84; 'more?': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'to:addr:yahoo.co.uk': 0.84; '2013,': 0.91; 'dutch': 0.91; 'norwegian': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1423514331; bh=hAYFb/tFxFjOAsOXHz8+HVOgJ+SLROjix/sZ2x0eZUQ=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=c9DdYqRbhR+f4/QQpGB4PqRFo3Ny7QZwjDV7CaSii5CvXrVfJLxQ/wCAqllkK4U33gGpAVupbglJBmncvpczOtuFwkkQYvH8x2U1OA4CvIiawiE60XuwR8DptSVQUGfxuIbTTU3nWB97bHb2PjmzCB3yfrYJeg3OnVriKzLXABx8snEAB0q9ZJoi33Qu29RK0ldeVAks8Fl3lshPW5yImx2FoXLld6mpNmxcoaA1yOhD54+QnZnjlEqORURgpFbVugtZKIcr3Jh/5gPWt+oVBXpE0RTqLuROv4G1E6D63EFoa8NmRM9LF6N68k8pVMM72GIEAwBDj0ErN4Ksnu7beQ== X-Yahoo-Newman-Property: ymail-4 X-Yahoo-Newman-Id: 281608.78298.bm@omp1046.mail.gq1.yahoo.com X-YMail-OSG: ClE1N84VM1mSlR3hwuNWGuEUfv6WPbfW7hxaMH6H2oGunTU1m3rSdQg4Z73P7pO oF9wZbpZr0nwmkqb9_hCz0aZnqPe_HyeE2jHsFugzTQrbt0_d6o7MShime9sv5wy4cAvdAuFWboc lhQJ2D5RD4866z0zR9K00bYg8MTqBrJ2yy0q7.OEKf21U2KNj7aiGmECpp8aD4C0I8EpH49po3kQ LAX7ezobE6A0pJ2uVJFb6mxO1BFphnFFebMDC3puJ0S5aNQsTHUk3ELmT7NMsSCnyjQiZTbGK.eY 93usIpZGCP0.9iO36.AQiWwr2mInA.Bok6xbuKZf.GPYXGR14J4WnL7VL9Ihj5uF3Gq3Pexy9tUh CUj2w8RFoatmYw22WtySL2oF9JGY_or4VwUytvyyJeenFRr.p_B7fYZuB_pDKw2sZEWibgBW0M0p tj4Koz968B0QZMfoEKA0wgqtDlBtP6fLuPyPjt3tDIokmMja368VOzGdmj891wFA6SQR6mIkWChL W.lQBcWD5rK0a9l6u09gkziNVQ4C.TqWas0xCqFcoAfgtAuh35vqJfS1vnjVEMqEyuG8JQGtUAQf _W_6GQ4ayjMbc0Y6874qOAQfBTBfrTZvOY1BWhWG6xpRfqisfDdIfv4IW0MqzAm_a3XTgoVT2JxE 26ADr7iM- Date: Mon, 9 Feb 2015 20:35:49 +0000 (UTC) From: Albert-Jan Roskam To: Mark Lawrence , "python-list@python.org" In-Reply-To: References: Subject: Re: locale bug in Python 2.7, 3.3, 3.4 (Win7 64)? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Albert-Jan Roskam List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 168 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423514509 news.xs4all.nl 2908 [2001:888:2000:d::a6]:46664 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85402 ----- Original Message ----- > From: Mark Lawrence > To: python-list@python.org > Cc:=20 > Sent: Monday, February 9, 2015 5:02 PM > Subject: Re: locale bug in Python 2.7, 3.3, 3.4 (Win7 64)? >=20 > On 09/02/2015 15:43, Albert-Jan Roskam wrote: >> Hi, >>=20 >> In the locale module we have: >> * setlocale, the setter that also returns something >> * getlocale, the getter that returns the OS-specific locale tuple=20 > (supposedly!) >>=20 >> * getdefaultlocale, the getter that always returns a unix locale tuple >>=20 >> Why are the getlocale() results below sometimes windows-like, sometimes= =20 > unix-like? >> It seems that I need to use setlocale(), with only the 'category'=20 > parameter, right? >>=20 >>=20 >> ActivePython 3.3.2.0 (ActiveState Software Inc.) based on >> Python 3.3.2 (default, Sep 16 2013, 23:11:39) [MSC v.1600 64 bit (AMD64= )]=20 > on win32 >> Type "help", "copyright", "credits" or=20 > "license" for more information. >>>>> import locale >>>>> locale.getlocale() >> (None, None) # because setocale has not been called yet >>=20 >>=20 >> # works as expected >>=20 >>>>> locale.setlocale(locale.LC_ALL, "") >> 'Dutch_Netherlands.1252' >>>>> locale.getlocale() >> ('Dutch_Netherlands', '1252') >>=20 >> # bug!>>> locale.setlocale(locale.LC_ALL, "german") >> 'German_Germany.1252' >>>>> locale.getlocale() >> ('de_DE', 'cp1252') # incorect, unix-like! >>=20 >>=20 >>>>> locale.setlocale(locale.LC_ALL,=20 > "German_Germany.1252") >> 'German_Germany.1252' >>>>> locale.getlocale() >> ('de_DE', 'cp1252') # incorect, unix-like! >>=20 >>=20 >> # bug! >>=20 >>>>> locale.setlocale(locale.LC_ALL, "spanish") >> 'Spanish_Spain.1252' >>>>> locale.getlocale() >> ('es_ES', 'cp1252') # incorect, unix-like! >>=20 >>=20 >> # works as expected >>>>> locale.setlocale(locale.LC_ALL, "italian") >> 'Italian_Italy.1252' >>>>> locale.getlocale() >> ('Italian_Italy', '1252') # correct! >>=20 >>=20 >> # ... maybe more? >>=20 >>=20 >> Regards, >>=20 >> Albert-Jan >>=20 >=20 > There have been loads of bug reports on the issue tracker about locales.= =20 > I suggest that you take a look to see if there is an open issue about= =20 > this problem. Hi Mark -Thanks! I checked the bug tracker. Lots of locale-related bugs ind= eed. I couldn't find this one though. Strange because what I am doing does = not seem exotic at all. French, German, Portuguese and Spanish getlocale re= sults are incorrect IMHO. Below is little check + output here in case it mi= ght be useful for others. This is with Python 3.4, 3.3 and 2.7 on Windows 7= 64. from __future__ import print_function import locale import collections import pprint #https://msdn.microsoft.com/en-us/library/39cwe7zf%28v=3Dvs.80%29.aspx languages =3D ("chinese czech danish dutch english finnish french german gr= eek " "hungarian icelandic italian japanese korean norwegian polish = " "portuguese russian slovak spanish swedish turkish") d =3D collections.defaultdict(list) t =3D collections.namedtuple("Locale", "lang setlocale getlocale") for language in languages.split(): sloc =3D locale.setlocale(locale.LC_ALL, language) gloc =3D locale.getlocale() record =3D t(language, sloc, gloc) if gloc[0][2] =3D=3D "_": d["unix-like"].append(record) else: d["windows-like"].append(record) =20 pprint.pprint(dict(d)) n:\>C:\Miniconda3\python.exe N:\temp\loc.py {'unix-like': [Locale(lang=3D'french', setlocale=3D'French_France.1252', ge= tlocale=3D('fr_FR', 'cp1252')), Locale(lang=3D'german', setlocale=3D'German_Germany.1252', g= etlocale=3D('de_DE', 'cp1252')), Locale(lang=3D'portuguese', setlocale=3D'Portuguese_Brazil.1= 252', getlocale=3D('pt_BR', 'cp1252')), Locale(lang=3D'spanish', setlocale=3D'Spanish_Spain.1252', g= etlocale=3D('es_ES', 'cp1252'))], 'windows-like': [Locale(lang=3D'chinese', setlocale=3D"Chinese (Simplified= )_People's Republic of China.936", getlocale=3D("Chinese (Simplified)_Peopl= e's Republic of China", '936')), Locale(lang=3D'czech', setlocale=3D'Czech_Czech Republic.= 1250', getlocale=3D('Czech_Czech Republic', '1250')), Locale(lang=3D'danish', setlocale=3D'Danish_Denmark.1252'= , getlocale=3D('Danish_Denmark', '1252')), Locale(lang=3D'dutch', setlocale=3D'Dutch_Netherlands.125= 2', getlocale=3D('Dutch_Netherlands', '1252')), Locale(lang=3D'english', setlocale=3D'English_United Stat= es.1252', getlocale=3D('English_United States', '1252')), Locale(lang=3D'finnish', setlocale=3D'Finnish_Finland.125= 2', getlocale=3D('Finnish_Finland', '1252')), Locale(lang=3D'greek', setlocale=3D'Greek_Greece.1253', g= etlocale=3D('Greek_Greece', '1253')), Locale(lang=3D'hungarian', setlocale=3D'Hungarian_Hungary= .1250', getlocale=3D('Hungarian_Hungary', '1250')), Locale(lang=3D'icelandic', setlocale=3D'Icelandic_Iceland= .1252', getlocale=3D('Icelandic_Iceland', '1252')), Locale(lang=3D'italian', setlocale=3D'Italian_Italy.1252'= , getlocale=3D('Italian_Italy', '1252')), Locale(lang=3D'japanese', setlocale=3D'Japanese_Japan.932= ', getlocale=3D('Japanese_Japan', '932')), Locale(lang=3D'korean', setlocale=3D'Korean_Korea.949', g= etlocale=3D('Korean_Korea', '949')), Locale(lang=3D'norwegian', setlocale=3D'Norwegian (Bokm= =C3=A5l)_Norway.1252', getlocale=3D('Norwegian (Bokm=C3=A5l)_Norway', '1252= ')), Locale(lang=3D'polish', setlocale=3D'Polish_Poland.1250',= getlocale=3D('Polish_Poland', '1250')), Locale(lang=3D'russian', setlocale=3D'Russian_Russia.1251= ', getlocale=3D('Russian_Russia', '1251')), Locale(lang=3D'slovak', setlocale=3D'Slovak_Slovakia.1250= ', getlocale=3D('Slovak_Slovakia', '1250')), Locale(lang=3D'swedish', setlocale=3D'Swedish_Sweden.1252= ', getlocale=3D('Swedish_Sweden', '1252')), Locale(lang=3D'turkish', setlocale=3D'Turkish_Turkey.1254= ', getlocale=3D('Turkish_Turkey', '1254'))]}