當前位置: 首頁>>代碼示例>>Python>>正文


Python magic.MAGIC_MIME_TYPE屬性代碼示例

本文整理匯總了Python中magic.MAGIC_MIME_TYPE屬性的典型用法代碼示例。如果您正苦於以下問題:Python magic.MAGIC_MIME_TYPE屬性的具體用法?Python magic.MAGIC_MIME_TYPE怎麽用?Python magic.MAGIC_MIME_TYPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在magic的用法示例。


在下文中一共展示了magic.MAGIC_MIME_TYPE屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _try_magic

# 需要導入模塊: import magic [as 別名]
# 或者: from magic import MAGIC_MIME_TYPE [as 別名]
def _try_magic(self):
        try:
            import magic
            import weakref
        except ImportError:
            self._magic = None
        else:
            try:
                _magic = magic.Magic(flags=magic.MAGIC_MIME_TYPE)

                def cleanup(x):
                    _magic.close()

                self._magic_weakref = weakref.ref(self, cleanup)
                self._magic = _magic
            except TypeError:
                self._magic = None
            except AttributeError:
                self._magic = None 
開發者ID:pycontribs,項目名稱:jira,代碼行數:21,代碼來源:client.py

示例2: unzip_content

# 需要導入模塊: import magic [as 別名]
# 或者: from magic import MAGIC_MIME_TYPE [as 別名]
def unzip_content(r, *args, **kwargs):
        content = r.content

        with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
            mime = m.id_buffer(content)

        if mime == "application/zip":
            zip_buffer = io.BytesIO(content)
            with zipfile.ZipFile(zip_buffer) as zf:
                fn = zf.namelist()[0]
                with zf.open(fn) as f:
                    r._content = f.read()
        elif mime == "application/x-gzip":
            gz_buffer = io.BytesIO(content)
            with gzip.GzipFile(fileobj=gz_buffer) as gz:
                r._content = gz.read()
        else:
            r._content = content

        return r 
開發者ID:HurricaneLabs,項目名稱:machinae,代碼行數:22,代碼來源:base.py

示例3: scan

# 需要導入模塊: import magic [as 別名]
# 或者: from magic import MAGIC_MIME_TYPE [as 別名]
def scan(self, payload: Payload, request: Request) -> WorkerResponse:
        if USE_PYTHON_MAGIC:
            magic_scan = magic.Magic(mime=True)
            magic_result = magic_scan.from_buffer(payload.content[0:1000])
        else:
            with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
                magic_result = m.id_buffer(payload.content[0:1000])
        if hasattr(magic_result, 'decode'):
            magic_result = magic_result.decode('utf-8')
        return WorkerResponse(results={'mimetype': magic_result}) 
開發者ID:PUNCH-Cyber,項目名稱:stoq-plugins-public,代碼行數:12,代碼來源:mimetype.py


注:本文中的magic.MAGIC_MIME_TYPE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。