Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.03; 'default.': 0.07; 'definitions': 0.07; 'means,': 0.07; 'none)': 0.07; 'override': 0.07; 'predefined': 0.07; 'skip:/ 10': 0.07; 'python': 0.09; 'broken.': 0.09; 'explicitely': 0.09; 'imported': 0.09; 'linux.': 0.09; 'migration': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sure,': 0.09; "wouldn't": 0.11; 'subject:python': 0.11; '2.7': 0.13; 'library': 0.15; '(but': 0.15; 'behaviour.': 0.16; 'meanwhile': 0.16; 'mimetypes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'registry': 0.16; 'registry.': 0.16; 'smooth,': 0.16; 'subject:broken': 0.16; 'subject:windows': 0.16; 'such,': 0.16; 'suffixes': 0.16; 'thoughts?': 0.16; 'detect': 0.17; '(in': 0.18; 'windows': 0.19; 'code.': 0.20; 'issue.': 0.20; 'import': 0.21; '3.x': 0.22; 'somebody': 0.23; 'somewhere': 0.24; 'non': 0.24; 'url:bugs': 0.24; 'linux': 0.24; 'command': 0.24; 'allows': 0.25; 'least': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'ago': 0.27; 'wonder': 0.27; '3.0': 0.27; 'developing': 0.28; 'fixed': 0.28; 'header:X-Complaints-To:1': 0.28; 'lines': 0.28; 'behaviour': 0.29; 'relies': 0.29; 'types.': 0.29; 'workaround': 0.29; "i'm": 0.29; 'function': 0.30; 'compatible': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'anybody': 0.32; 'suggestion': 0.32; 'could': 0.32; 'print': 0.32; 'legacy': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'another': 0.33; 'wrong': 0.34; 'fail': 0.35; 'replaced': 0.35; 'expected': 0.35; 'there': 0.35; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'be.': 0.36; 'should': 0.36; 'possible': 0.37; 'two': 0.37; 'why': 0.37; 'rather': 0.37; 'fact': 0.38; 'some': 0.38; 'possible.': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'first': 0.61; 'between': 0.63; 'due': 0.66; 'fact,': 0.69; 'pleasure': 0.75; 'experiencing': 0.84; 'pcs': 0.84; 'migrating': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: mimetypes.guess_type broken in windows on py2.7 and python 3.X Date: Wed, 26 Sep 2012 10:54:34 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: unicorn.dungeon.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348649689 news.xs4all.nl 6988 [2001:888:2000:d::a6]:36454 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30169 Hi, I'm still experiencing the pleasure of migrating legacy code from Python 2.6. to 2.7 which I expected to be much less painful. (In fact migration on Linux is rather smooth, but Windows is another story) Let's take the simple command import mimetypes print mimetypes.guess_type('a.jpg') The result an old pythons ( 2.7) is ('image/jpeg', None) Ther result on non windows platform is for python 2.7 / 3.X is the same However. The result for 2.7 / 3.x on windows is now ('image/pjpeg', None) # pjpeg instead of jpeg On Windows many file suffixes will report wrong mime types. The problem is know for about two years. http://bugs.python.org/issue10551 The main reason is, that under wWindows default values are fetched from Python and then 'updated' mime-types are fetched from the Windows registry. The major problem is, that almost ALL windows PCs have BROKEN mime types. so the good predefined mime types are just replaced with broken MS mime types. I wonder how many applications, that will try to migrate to 2.7 / 3.0 will fail due to this incompatibility in the mimetypes library There is a workaround (but first people have to detect the problem and to find it): Add these two lines somewhere in your code BEFORE any other imported library might have called a mimetypes function import mimetypes mimetypes.init([]) I still wonder if it wouldn't be better to have the default behaviour of 2.7 / 3.0 on windows such, that all the users who're not aware of this issue will not have their code broken. My suggestion for windows would be to have following default behaviour: - !st read the mimetypes from the registry if possible - 2nd read the Python default mimetypes and override the 'broken' MS definitions Only if a user explicitely calls mimetypes.init() they would have differente behaviour. The new behaviour breaks portability of Python code between Windows and Linux and I think the attempt should be to be as cross platform as possible. and not to be. At least one of the reasons why I use pythin is, that it allows to be rather cross-platform An alternative suggestion could be to never read the registry or /etc/mimetypes by default. What would definitely be rather important is add a big warning in the documentation and a recommendation of how to write cross platform compatible code. Somebody developing on Linux might not even know, that the code will not work on windows jsst because of this tiny issue. The unfortunate fact, that this issue was not fixed two years ago means, that perhaps meanwhile some code is out, that relies on the current behaviour. However I'm not sure, that anybody relies on the fact, that code will not work the same way on windows and on Linux. Any thoughts?