diff options
| author | christos <christos@NetBSD.org> | 2011-05-12 20:46:28 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2011-05-12 20:46:28 +0000 |
| commit | 2e1c341a70f7caef4d6e90366d38ad67a73d4268 (patch) | |
| tree | a36fffd54164a36beadc417d10011df51997f9e8 /external/bsd/file/dist/python | |
| parent | b6f96da23234479bfc1f4f36bc0854ec46105fa9 (diff) | |
from ftp.astron.com.
- many security related fixes
- no MAXPATHLEN limits
- fixed missing text specification on ascii magic
- new ``pascal'' style string formats
- whitespace comparison fix
- more magic
Diffstat (limited to 'external/bsd/file/dist/python')
| -rw-r--r-- | external/bsd/file/dist/python/Makefile.am | 3 | ||||
| -rw-r--r-- | external/bsd/file/dist/python/Makefile.in | 28 | ||||
| -rw-r--r-- | external/bsd/file/dist/python/README | 23 | ||||
| -rw-r--r-- | external/bsd/file/dist/python/example.py | 17 | ||||
| -rw-r--r-- | external/bsd/file/dist/python/magic.py | 204 | ||||
| -rw-r--r-- | external/bsd/file/dist/python/setup.py | 20 |
6 files changed, 243 insertions, 52 deletions
diff --git a/external/bsd/file/dist/python/Makefile.am b/external/bsd/file/dist/python/Makefile.am index 6052d9cb198..e0c469528e9 100644 --- a/external/bsd/file/dist/python/Makefile.am +++ b/external/bsd/file/dist/python/Makefile.am @@ -1,2 +1,3 @@ -EXTRA_DIST = README example.py py_magic.c py_magic.h setup.py +EXTRA_DIST = README example.py magic.py setup.py + diff --git a/external/bsd/file/dist/python/Makefile.in b/external/bsd/file/dist/python/Makefile.in index 7fd88ca6d7d..94c199c400e 100644 --- a/external/bsd/file/dist/python/Makefile.in +++ b/external/bsd/file/dist/python/Makefile.in @@ -33,8 +33,10 @@ host_triplet = @host@ subdir = python DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ - $(top_srcdir)/configure.ac +am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -56,38 +58,40 @@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ -ECHO = @ECHO@ +DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ +FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ +MINGW = @MINGW@ MKDIR_P = @MKDIR_P@ +NM = @NM@ NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ @@ -107,8 +111,7 @@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ @@ -140,6 +143,7 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ @@ -154,7 +158,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -EXTRA_DIST = README example.py py_magic.c py_magic.h setup.py +EXTRA_DIST = README example.py magic.py setup.py all: all-am .SUFFIXES: diff --git a/external/bsd/file/dist/python/README b/external/bsd/file/dist/python/README index ba22eb01fe4..8b9a2a7e407 100644 --- a/external/bsd/file/dist/python/README +++ b/external/bsd/file/dist/python/README @@ -1,26 +1,13 @@ - This directory contains Python bindings to allow you to access the -libmagic api. At the moment their status is "experimental" and -they are not built by default. You may need to edit include and library -search paths in setup.py so that python's distutils build process can -find the magic header and lib files. - -In order to be able to compile magic-python you need to have python -and the python-dev packages installed. - -Python libraries are always built for a particular version of Python -(2.2, 2.3, etc), and libraries built for one version will not be seen -by another. +libmagic api. At the moment their status is "experimental". -To build: +You can install the modules either with: $ python setup.py build +$ python setup.py install -Now, you can install the modules: +or, if you have easy_install: -$ cp build/lib.*/magic.so /usr/lib/python2.3/lib-dynload/ - -(the directory /usr/lib/python2.3 may vary, depending on your installation) +$ easy_install . magic-python should work now! - diff --git a/external/bsd/file/dist/python/example.py b/external/bsd/file/dist/python/example.py index fc41a86d7ed..0cd0b5e7ec2 100644 --- a/external/bsd/file/dist/python/example.py +++ b/external/bsd/file/dist/python/example.py @@ -1,16 +1,17 @@ +#! /usr/bin/python + import magic -ms = magic.open(magic.MAGIC_NONE) +ms = magic.open(magic.NONE) ms.load() -type = ms.file("/path/to/some/file") -print type +tp = ms.file("/bin/ls") +print (tp) -f = file("/path/to/some/file", "r") -buffer = f.read(4096) +f = open("/bin/ls", "rb") +buf = f.read(4096) f.close() -type = ms.buffer(buffer) -print type +tp = ms.buffer(buf) +print (tp) ms.close() - diff --git a/external/bsd/file/dist/python/magic.py b/external/bsd/file/dist/python/magic.py new file mode 100644 index 00000000000..41a42ee553f --- /dev/null +++ b/external/bsd/file/dist/python/magic.py @@ -0,0 +1,204 @@ +#!/usr/bin/env python +''' +Python bindings for libmagic +''' + +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 + """ + return ctypes.cdll.LoadLibrary(find_library('magic')) + +_libraries = {} +_libraries['magic'] = _init() + +# Flag constants for open and setflags +MAGIC_NONE = NONE = 0 +MAGIC_DEBUG = DEBUG = 1 +MAGIC_SYMLINK = SYMLINK = 2 +MAGIC_COMPRESS = COMPRESS = 4 +MAGIC_DEVICES = DEVICES = 8 +MAGIC_MIME_TYPE = MIME_TYPE = 16 +MAGIC_CONTINUE = CONTINUE = 32 +MAGIC_CHECK = CHECK = 64 +MAGIC_PRESERVE_ATIME = PRESERVE_ATIME = 128 +MAGIC_RAW = RAW = 256 +MAGIC_ERROR = ERROR = 512 +MAGIC_MIME_ENCODING = MIME_ENCODING = 1024 +MAGIC_MIME = MIME = 1040 +MAGIC_APPLE = APPLE = 2048 + +MAGIC_NO_CHECK_COMPRESS = NO_CHECK_COMPRESS = 4096 +MAGIC_NO_CHECK_TAR = NO_CHECK_TAR = 8192 +MAGIC_NO_CHECK_SOFT = NO_CHECK_SOFT = 16384 +MAGIC_NO_CHECK_APPTYPE = NO_CHECK_APPTYPE = 32768 +MAGIC_NO_CHECK_ELF = NO_CHECK_ELF = 65536 +MAGIC_NO_CHECK_TEXT = NO_CHECK_TEXT = 131072 +MAGIC_NO_CHECK_CDF = NO_CHECK_CDF = 262144 +MAGIC_NO_CHECK_TOKENS = NO_CHECK_TOKENS = 1048576 +MAGIC_NO_CHECK_ENCODING = NO_CHECK_ENCODING = 2097152 + +MAGIC_NO_CHECK_BUILTIN = NO_CHECK_BUILTIN = 4173824 + +class magic_set(Structure): + pass +magic_set._fields_ = [] +magic_t = POINTER(magic_set) + +_open = _libraries['magic'].magic_open +_open.restype = magic_t +_open.argtypes = [c_int] + +_close = _libraries['magic'].magic_close +_close.restype = None +_close.argtypes = [magic_t] + +_file = _libraries['magic'].magic_file +_file.restype = c_char_p +_file.argtypes = [magic_t, c_char_p] + +_descriptor = _libraries['magic'].magic_descriptor +_descriptor.restype = c_char_p +_descriptor.argtypes = [magic_t, c_int] + +_buffer = _libraries['magic'].magic_buffer +_buffer.restype = c_char_p +_buffer.argtypes = [magic_t, c_void_p, c_size_t] + +_error = _libraries['magic'].magic_error +_error.restype = c_char_p +_error.argtypes = [magic_t] + +_setflags = _libraries['magic'].magic_setflags +_setflags.restype = c_int +_setflags.argtypes = [magic_t, c_int] + +_load = _libraries['magic'].magic_load +_load.restype = c_int +_load.argtypes = [magic_t, c_char_p] + +_compile = _libraries['magic'].magic_compile +_compile.restype = c_int +_compile.argtypes = [magic_t, c_char_p] + +_check = _libraries['magic'].magic_check +_check.restype = c_int +_check.argtypes = [magic_t, c_char_p] + +_list = _libraries['magic'].magic_list +_list.restype = c_int +_list.argtypes = [magic_t, c_char_p] + +_errno = _libraries['magic'].magic_errno +_errno.restype = c_int +_errno.argtypes = [magic_t] + +class Magic(object): + def __init__(self, ms): + self._magic_t = ms + + def close(self): + """ + Closes the magic database and deallocates any resources used. + """ + _close(self._magic_t) + + def file(self, file): + """ + Returns a textual description of the contents of the argument passed + 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. + """ + return _file(self._magic_t, file) + + def descriptor(self, fd): + """ + Like the file method, but the argument is a file descriptor. + """ + return _descriptor(self._magic_t, fd) + + def buffer(self, buf): + """ + Returns a textual description of the contents of the argument passed + 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. + """ + return _buffer(self._magic_t, buf, len(buf)) + + def error(self): + """ + Returns a textual explanation of the last error or None + if there was no error. + """ + 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. + + Returns -1 on systems that don't support utime(2) or utimes(2) + when PRESERVE_ATIME is set. + """ + return _setflags(self._magic_t, flags) + + def load(self, file=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. + + Returns 0 on success and -1 on failure. + """ + return _load(self._magic_t, file) + + def compile(self, dbs): + """ + Compile entries in the colon separated list of database files + passed as argument or the default database file if no argument. + Returns 0 on success and -1 on failure. + The compiled files created are named from the basename(1) of each file + argument with ".mgc" appended to it. + """ + return _compile(self._magic_t, dbs) + + def check(self, dbs): + """ + Check the validity of entries in the colon separated list of + database files passed as argument or the default database file + if no argument. + Returns 0 on success and -1 on failure. + """ + return _check(self._magic_t, dbs) + + def list(self, dbs): + """ + Check the validity of entries in the colon separated list of + database files passed as argument or the default database file + if no argument. + 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 + magic error occurred. If return value is non-zero, the value is + an OS error code. Use the errno module or os.strerror() can be used + to provide detailed error information. + """ + return _errno(self._magic_t) + +def open(flags): + """ + Returns a magic object on success and None on failure. + Flags argument as for setflags. + """ + return Magic(_open(flags)) diff --git a/external/bsd/file/dist/python/setup.py b/external/bsd/file/dist/python/setup.py index 7c861948441..2c3b527bb89 100644 --- a/external/bsd/file/dist/python/setup.py +++ b/external/bsd/file/dist/python/setup.py @@ -1,16 +1,10 @@ # Python distutils build script for magic extension -from distutils.core import setup, Extension +from distutils.core import setup -magic_module = Extension('magic', - libraries = ['magic'], - library_dirs = ['./','../','../src','/usr/lib/'], - include_dirs = ['./','../','../src','/usr/include/'], - sources = ['py_magic.c']) - -setup (name = 'Magic file extensions', - version = '0.1', - author = 'Brett Funderburg', - author_email = 'brettf@deepfile.com', +setup(name = 'Magic file extensions', + version = '0.2', + author = 'Reuben Thomas', + author_email = 'rrt@sc3d.org', license = 'BSD', - description = 'libmagic python bindings', - ext_modules = [magic_module]) + description = 'libmagic Python bindings', + py_modules = ['magic']) |
