예제 #1
0
    def __init__(self, paths=None, flags=MAGIC_NONE):
        """Open and initialise resources from libmagic.

        ``paths`` is a list of magic database files to load.  If None, the
        default database will be loaded. For details on the magic database file
        see magic(5).

        ``flags`` controls how libmagic should behave. See libmagic(3) for
        details of these flags.
        """
        self._repr = "Magic(paths={0!r}, flags={1!r})".format(paths, flags)
        cookie = api.magic_open(flags)
        def cleanup(_):
            warnings.warn("magic.Magic() not closed before being garbage "
                    "collected. Magic.close() should be called when finished"
                    "with",
                    CleanupWarning)
            api.magic_close(cookie)
        self.weakref = weakref.ref(self, cleanup)
        self.cookie = cookie
        pathstr = b':'.join(iter_encode(paths)) if paths else None
        try:
            api.magic_load(self.cookie, pathstr)
        except MagicError:
            self.close()
            raise
예제 #2
0
    def __init__(self, paths=None, flags=MAGIC_NONE):
        """Open and initialise resources from libmagic.

        ``paths`` is a list of magic database files to load.  If None, the
        default database will be loaded. For details on the magic database file
        see magic(5).

        ``flags`` controls how libmagic should behave. See libmagic(3) for
        details of these flags.
        """
        self.cookie = api.magic_open(flags)
        pathstr = b':'.join(iter_encode(paths)) if paths else None
        api.magic_load(self.cookie, pathstr)
예제 #3
0
    def __init__(self, paths=None, flags=MAGIC_NONE):
        """Open and initialise resources from libmagic.

        ``paths`` is a list of magic database files to load.  If None, the
        default database will be loaded. For details on the magic database file
        see magic(5).

        ``flags`` controls how libmagic should behave. See libmagic(3) for
        details of these flags.
        """
        self.cookie = api.magic_open(flags)
        pathstr = b':'.join(iter_encode(paths)) if paths else None
        api.magic_load(self.cookie, pathstr)
예제 #4
0
    def __init__(self, paths=None, flags=MAGIC_NONE):
        """Open and initialise resources from libmagic.

        ``paths`` is a list of magic database files to load.  If None, the
        default database will be loaded. For details on the magic database file
        see magic(5).

        ``flags`` controls how libmagic should behave. See libmagic(3) for
        details of these flags.
        """
        cookie = api.magic_open(flags)
        def cleanup(_):
            warnings.warn("Implicitly cleaning up {0!r}".format(cookie),
                    CleanupWarning)
            api.magic_close(cookie)
        self.weakref = weakref.ref(self, cleanup)
        self.cookie = cookie
        pathstr = b':'.join(iter_encode(paths)) if paths else None
        try:
            api.magic_load(self.cookie, pathstr)
        except MagicError:
            self.close()
            raise