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
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)
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)