Markdown Format | JSON API | MCP Server Tool
Help on package magic: NAME magic - magic is a wrapper around the libmagic file identification library. DESCRIPTION See README for more information. Usage: >>> import magic >>> magic.from_file("testdata/test.pdf") 'PDF document, version 1.2' >>> magic.from_file("testdata/test.pdf", mime=True) 'application/pdf' >>> magic.from_buffer(open("testdata/test.pdf").read(1024)) 'PDF document, version 1.2' >>> PACKAGE CONTENTS compat loader CLASSES builtins.Exception(builtins.BaseException) MagicException builtins.object Magic class Magic(builtins.object) | Magic(mime=False, magic_file=None, mime_encoding=False, keep_going=False, uncompress=False, raw=False, extension=False) | | Magic is a wrapper around the libmagic C library. | | Methods defined here: | | __del__(self) | | __init__(self, mime=False, magic_file=None, mime_encoding=False, keep_going=False, uncompress=False, raw=False, extension=False) | Create a new libmagic wrapper. | | mime - if True, mimetypes are returned instead of textual descriptions | mime_encoding - if True, codec is returned | magic_file - use a mime database other than the system default | keep_going - don't stop at the first match, keep going | uncompress - Try to look inside compressed files. | raw - Do not try to decode "non-printable" chars. | extension - Print a slash-separated list of valid extensions for the file type found. | | from_buffer(self, buf) | Identify the contents of `buf` | | from_descriptor(self, fd) | | from_file(self, filename) | | getparam(self, param) | | setparam(self, param, val) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) class MagicException(builtins.Exception) | MagicException(message) | | Method resolution order: | MagicException | builtins.Exception | builtins.BaseException | builtins.object | | Methods defined here: | | __init__(self, message) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args FUNCTIONS POINTER(...) byref(...) byref(C instance[, offset=0]) -> byref-object Return a pointer lookalike to a C instance, only usable as function argument coerce_filename(filename) detect_from_content = _(*args, **kwargs) detect_from_filename = _(*args, **kwargs) detect_from_fobj = _(*args, **kwargs) errorcheck_negative_one(result, func, args) errorcheck_null(result, func, args) from_buffer(buffer, mime=False) Accepts a binary string and returns the detected filetype. Return value is the mimetype if mime=True, otherwise a human readable name. >>> magic.from_buffer(open("testdata/test.pdf").read(1024)) 'PDF document, version 1.2' from_descriptor(fd, mime=False) Accepts a file descriptor and returns the detected filetype. Return value is the mimetype if mime=True, otherwise a human readable name. >>> f = open("testdata/test.pdf") >>> magic.from_descriptor(f.fileno()) 'PDF document, version 1.2' from_file(filename, mime=False) " Accepts a filename and returns the detected filetype. Return value is the mimetype if mime=True, otherwise a human readable name. >>> magic.from_file("testdata/test.pdf", mime=True) 'application/pdf' magic_buffer(cookie, buf) magic_descriptor(cookie, fd) magic_file(cookie, filename) magic_getparam(cookie, param) magic_load(cookie, filename) magic_setparam(cookie, param, val) maybe_decode(s) # return str on python3. Don't want to unconditionally # decode because that results in unicode on python2 open = _(*args, **kwargs) version() DATA APPLE = 2048 CHECK = 64 COMPRESS = 4 CONTINUE = 32 DEBUG = 1 DEFAULT_MODE = 0 DEVICES = 8 ERROR = 512 MAGIC_APPLE = 2048 MAGIC_CHECK = 64 MAGIC_COMPRESS = 4 MAGIC_CONTINUE = 32 MAGIC_DEBUG = 1 MAGIC_DEVICES = 8 MAGIC_ERROR = 512 MAGIC_EXTENSION = 16777216 MAGIC_MIME = 16 MAGIC_MIME_ENCODING = 1024 MAGIC_MIME_TYPE = 16 MAGIC_NONE = 0 MAGIC_NO_CHECK_APPTYPE = 32768 MAGIC_NO_CHECK_ASCII = 131072 MAGIC_NO_CHECK_BUILTIN = 4173824 MAGIC_NO_CHECK_CDF = 262144 MAGIC_NO_CHECK_COMPRESS = 4096 MAGIC_NO_CHECK_ELF = 65536 MAGIC_NO_CHECK_ENCODING = 2097152 MAGIC_NO_CHECK_FORTRAN = 524288 MAGIC_NO_CHECK_SOFT = 16384 MAGIC_NO_CHECK_TAR = 8192 MAGIC_NO_CHECK_TEXT = 131072 MAGIC_NO_CHECK_TOKENS = 1048576 MAGIC_NO_CHECK_TROFF = 262144 MAGIC_PARAM_BYTES_MAX = 6 MAGIC_PARAM_ELF_NOTES_MAX = 4 MAGIC_PARAM_ELF_PHNUM_MAX = 2 MAGIC_PARAM_ELF_SHNUM_MAX = 3 MAGIC_PARAM_INDIR_MAX = 0 MAGIC_PARAM_NAME_MAX = 1 MAGIC_PARAM_REGEX_MAX = 5 MAGIC_PRESERVE_ATIME = 128 MAGIC_RAW = 256 MAGIC_SYMLINK = 2 MIME = 1040 MIME_ENCODING = 1024 MIME_TYPE = 16 NONE = 0 NO_CHECK_APPTYPE = 32768 NO_CHECK_BUILTIN = 4173824 NO_CHECK_CDF = 262144 NO_CHECK_COMPRESS = 4096 NO_CHECK_ELF = 65536 NO_CHECK_ENCODING = 2097152 NO_CHECK_SOFT = 16384 NO_CHECK_TAR = 8192 NO_CHECK_TEXT = 131072 NO_CHECK_TOKENS = 1048576 PRESERVE_ATIME = 128 RAW = 256 RTLD_GLOBAL = 256 RTLD_LOCAL = 0 SYMLINK = 2 libmagic = <CDLL 'libmagic.so.1', handle 55aeb7ea3cb0> magic_check = <_FuncPtr object> magic_close = <_FuncPtr object> magic_compile = <_FuncPtr object> magic_errno = <_FuncPtr object> magic_error = <_FuncPtr object> magic_open = <_FuncPtr object> magic_setflags = <_FuncPtr object> magic_version = <_FuncPtr object> FILE /usr/lib/python3/dist-packages/magic/__init__.py
Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:13 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)