|
 |
7ed636 |
From 7c122f3920f6ba6c4fb22f5b09dfb29a861396cb Mon Sep 17 00:00:00 2001
|
|
 |
7ed636 |
From: rpm-build <rpm-build>
|
|
 |
7ed636 |
Date: Fri, 16 Feb 2018 09:11:32 -0600
|
|
 |
7ed636 |
Subject: [PATCH] Removing magic.py
|
|
 |
7ed636 |
|
|
 |
7ed636 |
---
|
|
 |
7ed636 |
egg/insights/contrib/magic.py | 208 ------------------------------------------
|
|
 |
7ed636 |
1 file changed, 208 deletions(-)
|
|
 |
7ed636 |
delete mode 100644 egg/insights/contrib/magic.py
|
|
 |
7ed636 |
|
|
 |
7ed636 |
diff --git a/egg/insights/contrib/magic.py b/egg/insights/contrib/magic.py
|
|
 |
7ed636 |
deleted file mode 100644
|
|
 |
7ed636 |
index 8cb7130..0000000
|
|
 |
7ed636 |
--- a/egg/insights/contrib/magic.py
|
|
 |
7ed636 |
+++ /dev/null
|
|
 |
7ed636 |
@@ -1,208 +0,0 @@
|
|
 |
7ed636 |
-#!/usr/bin/env python
|
|
 |
7ed636 |
-'''
|
|
 |
7ed636 |
-Python bindings for libmagic
|
|
 |
7ed636 |
-'''
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-import ctypes
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-from ctypes import *
|
|
 |
7ed636 |
-from ctypes.util import find_library
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-def _init():
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Loads the shared library through ctypes and returns a library
|
|
 |
7ed636 |
- L{ctypes.CDLL} instance
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return ctypes.cdll.LoadLibrary(find_library('magic'))
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_libraries = {}
|
|
 |
7ed636 |
-_libraries['magic'] = _init()
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-# Flag constants for open and setflags
|
|
 |
7ed636 |
-MAGIC_NONE = NONE = 0
|
|
 |
7ed636 |
-MAGIC_DEBUG = DEBUG = 1
|
|
 |
7ed636 |
-MAGIC_SYMLINK = SYMLINK = 2
|
|
 |
7ed636 |
-MAGIC_COMPRESS = COMPRESS = 4
|
|
 |
7ed636 |
-MAGIC_DEVICES = DEVICES = 8
|
|
 |
7ed636 |
-MAGIC_MIME_TYPE = MIME_TYPE = 16
|
|
 |
7ed636 |
-MAGIC_CONTINUE = CONTINUE = 32
|
|
 |
7ed636 |
-MAGIC_CHECK = CHECK = 64
|
|
 |
7ed636 |
-MAGIC_PRESERVE_ATIME = PRESERVE_ATIME = 128
|
|
 |
7ed636 |
-MAGIC_RAW = RAW = 256
|
|
 |
7ed636 |
-MAGIC_ERROR = ERROR = 512
|
|
 |
7ed636 |
-MAGIC_MIME_ENCODING = MIME_ENCODING = 1024
|
|
 |
7ed636 |
-MAGIC_MIME = MIME = 1040
|
|
 |
7ed636 |
-MAGIC_APPLE = APPLE = 2048
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_COMPRESS = NO_CHECK_COMPRESS = 4096
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_TAR = NO_CHECK_TAR = 8192
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_SOFT = NO_CHECK_SOFT = 16384
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_APPTYPE = NO_CHECK_APPTYPE = 32768
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_ELF = NO_CHECK_ELF = 65536
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_TEXT = NO_CHECK_TEXT = 131072
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_CDF = NO_CHECK_CDF = 262144
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_TOKENS = NO_CHECK_TOKENS = 1048576
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_ENCODING = NO_CHECK_ENCODING = 2097152
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-MAGIC_NO_CHECK_BUILTIN = NO_CHECK_BUILTIN = 4173824
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-class magic_set(Structure):
|
|
 |
7ed636 |
- pass
|
|
 |
7ed636 |
-magic_set._fields_ = []
|
|
 |
7ed636 |
-magic_t = POINTER(magic_set)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_open = _libraries['magic'].magic_open
|
|
 |
7ed636 |
-_open.restype = magic_t
|
|
 |
7ed636 |
-_open.argtypes = [c_int]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_close = _libraries['magic'].magic_close
|
|
 |
7ed636 |
-_close.restype = None
|
|
 |
7ed636 |
-_close.argtypes = [magic_t]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_file = _libraries['magic'].magic_file
|
|
 |
7ed636 |
-_file.restype = c_char_p
|
|
 |
7ed636 |
-_file.argtypes = [magic_t, c_char_p]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_descriptor = _libraries['magic'].magic_descriptor
|
|
 |
7ed636 |
-_descriptor.restype = c_char_p
|
|
 |
7ed636 |
-_descriptor.argtypes = [magic_t, c_int]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_buffer = _libraries['magic'].magic_buffer
|
|
 |
7ed636 |
-_buffer.restype = c_char_p
|
|
 |
7ed636 |
-_buffer.argtypes = [magic_t, c_void_p, c_size_t]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_error = _libraries['magic'].magic_error
|
|
 |
7ed636 |
-_error.restype = c_char_p
|
|
 |
7ed636 |
-_error.argtypes = [magic_t]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_setflags = _libraries['magic'].magic_setflags
|
|
 |
7ed636 |
-_setflags.restype = c_int
|
|
 |
7ed636 |
-_setflags.argtypes = [magic_t, c_int]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_load = _libraries['magic'].magic_load
|
|
 |
7ed636 |
-_load.restype = c_int
|
|
 |
7ed636 |
-_load.argtypes = [magic_t, c_char_p]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_compile = _libraries['magic'].magic_compile
|
|
 |
7ed636 |
-_compile.restype = c_int
|
|
 |
7ed636 |
-_compile.argtypes = [magic_t, c_char_p]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_check = _libraries['magic'].magic_check
|
|
 |
7ed636 |
-_check.restype = c_int
|
|
 |
7ed636 |
-_check.argtypes = [magic_t, c_char_p]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-_errno = _libraries['magic'].magic_errno
|
|
 |
7ed636 |
-_errno.restype = c_int
|
|
 |
7ed636 |
-_errno.argtypes = [magic_t]
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-class Magic(object):
|
|
 |
7ed636 |
- def __init__(self, ms):
|
|
 |
7ed636 |
- self._magic_t = ms
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def close(self):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Closes the magic database and deallocates any resources used.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- _close(self._magic_t)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def file(self, filename):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Returns a textual description of the contents of the argument passed
|
|
 |
7ed636 |
- as a filename or None if an error occurred and the MAGIC_ERROR flag
|
|
 |
7ed636 |
- is set. A call to errno() will return the numeric error code.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- try: # attempt python3 approach first
|
|
 |
7ed636 |
- if isinstance(filename, bytes):
|
|
 |
7ed636 |
- bi = filename
|
|
 |
7ed636 |
- else:
|
|
 |
7ed636 |
- bi = bytes(filename, 'utf-8')
|
|
 |
7ed636 |
- return str(_file(self._magic_t, bi), 'utf-8')
|
|
 |
7ed636 |
- except:
|
|
 |
7ed636 |
- return _file(self._magic_t, filename.encode('utf-8'))
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def descriptor(self, fd):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Like the file method, but the argument is a file descriptor.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return _descriptor(self._magic_t, fd)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def buffer(self, buf):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Returns a textual description of the contents of the argument passed
|
|
 |
7ed636 |
- as a buffer or None if an error occurred and the MAGIC_ERROR flag
|
|
 |
7ed636 |
- is set. A call to errno() will return the numeric error code.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- try: # attempt python3 approach first
|
|
 |
7ed636 |
- return str(_buffer(self._magic_t, buf, len(buf)), 'utf-8')
|
|
 |
7ed636 |
- except:
|
|
 |
7ed636 |
- return _buffer(self._magic_t, buf, len(buf))
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def error(self):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Returns a textual explanation of the last error or None
|
|
 |
7ed636 |
- if there was no error.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- try: # attempt python3 approach first
|
|
 |
7ed636 |
- return str(_error(self._magic_t), 'utf-8')
|
|
 |
7ed636 |
- except:
|
|
 |
7ed636 |
- return _error(self._magic_t)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def setflags(self, flags):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Set flags on the magic object which determine how magic checking
|
|
 |
7ed636 |
- behaves; a bitwise OR of the flags described in libmagic(3), but
|
|
 |
7ed636 |
- without the MAGIC_ prefix.
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- Returns -1 on systems that don't support utime(2) or utimes(2)
|
|
 |
7ed636 |
- when PRESERVE_ATIME is set.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return _setflags(self._magic_t, flags)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def load(self, filename=None):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Must be called to load entries in the colon separated list of database
|
|
 |
7ed636 |
- files passed as argument or the default database file if no argument
|
|
 |
7ed636 |
- before any magic queries can be performed.
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- Returns 0 on success and -1 on failure.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return _load(self._magic_t, filename)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def compile(self, dbs):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Compile entries in the colon separated list of database files
|
|
 |
7ed636 |
- passed as argument or the default database file if no argument.
|
|
 |
7ed636 |
- Returns 0 on success and -1 on failure.
|
|
 |
7ed636 |
- The compiled files created are named from the basename(1) of each file
|
|
 |
7ed636 |
- argument with ".mgc" appended to it.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return _compile(self._magic_t, dbs)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def check(self, dbs):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Check the validity of entries in the colon separated list of
|
|
 |
7ed636 |
- database files passed as argument or the default database file
|
|
 |
7ed636 |
- if no argument.
|
|
 |
7ed636 |
- Returns 0 on success and -1 on failure.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return _check(self._magic_t, dbs)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
- def errno(self):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Returns a numeric error code. If return value is 0, an internal
|
|
 |
7ed636 |
- magic error occurred. If return value is non-zero, the value is
|
|
 |
7ed636 |
- an OS error code. Use the errno module or os.strerror() can be used
|
|
 |
7ed636 |
- to provide detailed error information.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return _errno(self._magic_t)
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-
|
|
 |
7ed636 |
-def open(flags):
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- Returns a magic object on success and None on failure.
|
|
 |
7ed636 |
- Flags argument as for setflags.
|
|
 |
7ed636 |
- """
|
|
 |
7ed636 |
- return Magic(_open(flags))
|
|
 |
7ed636 |
--
|
|
 |
7ed636 |
2.14.3
|
|
 |
7ed636 |
|