From 141dacefe659df6000ffea35e0df691bb20c80d7 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Tue, 3 Jun 2014 19:14:46 +0000 Subject: [PATCH] PR/357: flake8 warning cleanups --- python/magic.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/python/magic.py b/python/magic.py index b893693e..3c7aa100 100644 --- a/python/magic.py +++ b/python/magic.py @@ -8,10 +8,11 @@ import ctypes from ctypes import * from ctypes.util import find_library + def _init(): """ Loads the shared library through ctypes and returns a library - L{ctypes.CDLL} instance + L{ctypes.CDLL} instance """ return ctypes.cdll.LoadLibrary(find_library('magic')) @@ -46,6 +47,7 @@ MAGIC_NO_CHECK_ENCODING = NO_CHECK_ENCODING = 2097152 MAGIC_NO_CHECK_BUILTIN = NO_CHECK_BUILTIN = 4173824 + class magic_set(Structure): pass magic_set._fields_ = [] @@ -99,6 +101,7 @@ _errno = _libraries['magic'].magic_errno _errno.restype = c_int _errno.argtypes = [magic_t] + class Magic(object): def __init__(self, ms): self._magic_t = ms @@ -115,7 +118,7 @@ class Magic(object): as a filename or None if an error occurred and the MAGIC_ERROR flag is set. A call to errno() will return the numeric error code. """ - try: # attempt python3 approach first + try: # attempt python3 approach first if isinstance(filename, bytes): bi = filename else: @@ -136,7 +139,7 @@ class Magic(object): as a buffer or None if an error occurred and the MAGIC_ERROR flag is set. A call to errno() will return the numeric error code. """ - try: # attempt python3 approach first + try: # attempt python3 approach firstg return str(_buffer(self._magic_t, buf, len(buf)), 'utf-8') except: return _buffer(self._magic_t, buf, len(buf)) @@ -146,16 +149,16 @@ class Magic(object): Returns a textual explanation of the last error or None if there was no error. """ - try: # attempt python3 approach first + try: # attempt python3 approach first return str(_error(self._magic_t), 'utf-8') except: return _error(self._magic_t) - + def setflags(self, flags): """ - Set flags on the magic object which determine how magic checking behaves; - a bitwise OR of the flags described in libmagic(3), but without the MAGIC_ - prefix. + Set flags on the magic object which determine how magic checking + behaves; a bitwise OR of the flags described in libmagic(3), but + without the MAGIC_ prefix. Returns -1 on systems that don't support utime(2) or utimes(2) when PRESERVE_ATIME is set. @@ -164,10 +167,10 @@ class Magic(object): def load(self, filename=None): """ - Must be called to load entries in the colon separated list of database files - passed as argument or the default database file if no argument before - any magic queries can be performed. - + Must be called to load entries in the colon separated list of database + files passed as argument or the default database file if no argument + before any magic queries can be performed. + Returns 0 on success and -1 on failure. """ return _load(self._magic_t, filename) @@ -199,7 +202,7 @@ class Magic(object): Returns 0 on success and -1 on failure. """ return _list(self._magic_t, dbs) - + def errno(self): """ Returns a numeric error code. If return value is 0, an internal @@ -209,6 +212,7 @@ class Magic(object): """ return _errno(self._magic_t) + def open(flags): """ Returns a magic object on success and None on failure. -- 2.40.0