[Products.Silva][Emiliano D'Alterio] Added fix for "no magic fil...

[email protected] Fri, 18 Oct 2013 15:59:34 +0200
Newsgroups gmane.comp.web.zope.silva.cvs
Message-ID <[email protected]>
author:    Emiliano D'Alterio
date:      Fri Oct 18 15:58:44 2013 +0200
revision:  11868:f16b33bcedf6 in Products.Silva
branch:    2.4
details:   https://hg.infrae.com/Products.Silva?cmd=changeset;node=f16b33bcedf6
modified:  Products/Silva/File/mimetypes.py
added:     
removed:   
log:       Added fix for "no magic files loaded" error when using "file"
	version 5.15.


diffstat:

 Products/Silva/File/mimetypes.py |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (58 lines):

diff -r 794d9b8b8ad8 -r f16b33bcedf6 Products/Silva/File/mimetypes.py
--- a/Products/Silva/File/mimetypes.py	Mon Oct 14 16:08:20 2013 +0200
+++ b/Products/Silva/File/mimetypes.py	Fri Oct 18 15:58:44 2013 +0200
@@ -46,7 +46,7 @@
     def __init__(self, filename):
         self.encodings_map = mimetypes.encodings_map.copy()
         self.suffix_map = mimetypes.suffix_map.copy()
-        self.types_map = ({}, {}) # dict for (non-strict, strict)
+        self.types_map = ({}, {})  # dict for (non-strict, strict)
         self.types_map_inv = ({}, {})
         self.read(filename, True)
 
@@ -91,7 +91,7 @@
         # extra table for them.
         if guessed_extension is None:
             if (content_type in _ENCODING_MIMETYPE_TO_ENCODING and
-                content_encoding is None):
+                    content_encoding is None):
                 # Compression extension often are used with some other
                 # extension. Unfortunately, at this point we might have
                 # lost that other extension. The editor has to rename
@@ -107,7 +107,7 @@
         if extension is not None:
             basename += extension
         if (content_encoding is not None and
-            content_encoding in _CONTENT_ENCODING_EXT):
+                content_encoding in _CONTENT_ENCODING_EXT):
             basename += _CONTENT_ENCODING_EXT[content_encoding]
         if basename != original_name:
             asset.set_filename(basename)
@@ -160,8 +160,8 @@
     magic_error.argtypes = [magic_t]
 
     def error_check(result, func, args):
-        error = magic_error(args[0])
-        if error is not None:
+        if result is None:
+            error = magic_error(args[0])
             raise MagicException(error)
         return result
 
@@ -189,7 +189,7 @@
     magic_load.argtypes = [magic_t, c_char_p]
     magic_load.errcheck = error_check
 
-    MAGIC_MIME = 0x000010 # Return a mime string
+    MAGIC_MIME = 0x000010  # Return a mime string
     MAGIC_COMPRESS = 0x000004
     HAVE_MAGIC = True
 
@@ -253,6 +253,7 @@
             fd = open(filename)
             return self.buffer(fd.read(5))
 
+
 def MimeTypeClassifierFactory():
     zconf = getattr(getConfiguration(), 'product_config', {})
     config = zconf.get('silva', {})