New submission from Kovid Goyal <ko...@kovidgoyal.net>:

Hi,
I am the primary developer of calibre (http:/calibre-ebook.com) and yesterday I 
released an upgrade of calibre based on python 2.7. Here is a small sampling of 
all the diverse errors that my users experienced, related to reading mimetypes 
from the registry:

1. Permission denied if running from non privileged account
Traceback (most recent call last):
File "site.py", line 103, in main
File "site.py", line 84, in run_entry_point
File "site-packages\calibre\__init__.py", line 31, in <module>
File "mimetypes.py", line 344, in add_type
File "mimetypes.py", line 355, in init
File "mimetypes.py", line 261, in read_windows_registry
WindowsError: [Error 5] Acceso denegado (Access not allowed)

The fix for this is to trap WindowsError and ignore it in mimetypes.py

2. Mishandling of encoding of registry entries

Traceback (most recent call last):      
  File "site.py", line 103, in main     
  File "site.py", line 84, in run_entry_point
  File "site-packages\calibre\__init__.py", line 31, in <module>                
                                
  File "mimetypes.py", line 344, in add_type                                    
                            
  File "mimetypes.py", line 355, in init                                        
                            
  File "mimetypes.py", line 260, in read_windows_registry                       
                            
  File "mimetypes.py", line 250, in enum_types                                  
                            
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe0 in position 0: invalid 
continuation byte

The fix for this is to change

except UnicodeEncodeError

to

except ValueError

3. python -c "import mimetypes; print mimetypes.guess_type('img.jpg')"
('image/pjpeg', None)

Where the output should have been

(image/jpeg', None)

The fix for this is to load the registry entries before the default entris 
defined in mimetypes.py


Of course, IMHO, the best possible fix is to simply remove the reading of 
mimetypes from the registry. But that is up to whoever maintains this module. 

Duplicate (less comprehensive) tickets ont his isuue in your traceker already 
are: 9291, 10490, 104314

If the maintainer of this module is unable to fix these issues, let me know and 
I will submit a patch, either removing _winreg or fixing the issues 
individually.

----------
components: Library (Lib)
messages: 122542
nosy: kovid
priority: normal
severity: normal
status: open
title: mimetypes reading from registry in windows completely broken
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10551>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to