[Pkg-privacy-commits] [mat] 06/68: SImplification and documentation of `create_class_file()`

Sascha Steinbiss sascha at steinbiss.name
Sun Jan 3 12:32:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

sascha-guest pushed a commit to branch master
in repository mat.

commit c9465c4e92f2dd4cd29da26f0ed93c918b0498ba
Author: jvoisin <julien.voisin at dustri.org>
Date:   Tue Nov 3 14:53:04 2015 +0100

    SImplification and documentation of `create_class_file()`
---
 libmat/mat.py | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/libmat/mat.py b/libmat/mat.py
index decbbed..df607a5 100644
--- a/libmat/mat.py
+++ b/libmat/mat.py
@@ -113,10 +113,10 @@ class XMLParser(xml.sax.handler.ContentHandler):
 
 
 def secure_remove(filename):
-    """ Securely remove the file
+    """ Securely remove $filename
+    :param str filename: File to be removed
     """
-    # I want the file removed, even if it's read-only
-    try:
+    try:  # I want the file removed, even if it's read-only
         os.chmod(filename, 220)
     except OSError:
         logging.error('Unable to add write rights to %s' % filename)
@@ -145,17 +145,17 @@ def secure_remove(filename):
 def create_class_file(name, backup, **kwargs):
     """ Return a $FILETYPEStripper() class,
         corresponding to the filetype of the given file
+
+        :param str name: name of the file to be parsed
+        :param bool backup: shell the file be backuped?
     """
     if not os.path.isfile(name):  # check if the file exists
         logging.error('%s is not a valid file' % name)
         return None
-
-    if not os.access(name, os.R_OK):  # check read permissions
+    elif not os.access(name, os.R_OK):  # check read permissions
         logging.error('%s is is not readable' % name)
         return None
-
-    if not os.path.getsize(name):
-        # check if the file is not empty (hachoir crash on empty files)
+    elif not os.path.getsize(name):  # check if the file is not empty (hachoir crash on empty files)
         logging.error('%s is empty' % name)
         return None
 
@@ -168,15 +168,11 @@ def create_class_file(name, backup, **kwargs):
     if not parser:
         logging.info('Unable to parse %s with hachoir' % filename)
 
-    mime = mimetypes.guess_type(filename)[0]
+    mime = mimetypes.guess_type(name)[0]
     if not mime:
         logging.info('Unable to find mimetype of %s' % filename)
         return None
 
-    if mime == 'application/zip':  # some formats are zipped stuff
-        if mimetypes.guess_type(name)[0]:
-            mime = mimetypes.guess_type(name)[0]
-
     if mime.startswith('application/vnd.oasis.opendocument'):
         mime = 'application/opendocument'  # opendocument fileformat
     elif mime.startswith('application/vnd.openxmlformats-officedocument'):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/mat.git



More information about the Pkg-privacy-commits mailing list