コード例 #1
0
    def guess_type(self, path):
        """Guess at the mime type for the specified file.
        """
        mimetype = srvmod.SimpleHTTPRequestHandler.guess_type(self, path)

        # If the default guess is too generic, try the python-magic library
        if mimetype == 'application/octet-stream' and magic_from_file:
            mimetype = magic_from_file(path, mime=True)

        return mimetype
コード例 #2
0
ファイル: server.py プロジェクト: btnpushnmunky/pelican
    def guess_type(self, path):
        """Guess at the mime type for the specified file.
        """
        mimetype = srvmod.SimpleHTTPRequestHandler.guess_type(self, path)

        # If the default guess is too generic, try the python-magic library
        if mimetype == 'application/octet-stream' and magic_from_file:
            mimetype = magic_from_file(path, mime=True)

        return mimetype
コード例 #3
0
    def __init__(self, stream):
        self.mime = magic_from_file(stream.name, mime=True)
        logging.debug(_('MIME type: %s'), self.mime)

        if self.mime in [
                b'application/x-object', b'application/x-executable',
                b'application/x-sharedlib'
        ]:
            self.binary = ELF(stream)
            self.system = 'linux'
            self.prefix = 'elf'
        elif self.mime == b'application/x-mach-binary':
            raise NotImplementedError(self.mime)
        elif self.mime == b'application/x-dosexec':
            self.binary = PE(stream)
            self.system = 'windows'
            self.prefix = 'pe'
        else:
            raise NotImplementedError(self.mime)
コード例 #4
0
    def __init__(self, stream):
        self.mime = magic_from_file(stream.name, mime=True)
        logging.debug(_('MIME type: %s'), self.mime)

        if self.mime in [
                b'application/x-object',
                b'application/x-executable',
                b'application/x-sharedlib']:
            self.binary = ELF(stream)
            self.system = 'linux'
            self.prefix = 'elf'
        elif self.mime == b'application/x-mach-binary':
            raise NotImplementedError(self.mime)
        elif self.mime == b'application/x-dosexec':
            self.binary = PE(stream)
            self.system = 'windows'
            self.prefix = 'pe'
        else:
            raise NotImplementedError(self.mime)