当前位置: 首页>>代码示例>>Python>>正文


Python HTTP.get_with_timeout方法代码示例

本文整理汇总了Python中http.HTTP.get_with_timeout方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.get_with_timeout方法的具体用法?Python HTTP.get_with_timeout怎么用?Python HTTP.get_with_timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.HTTP的用法示例。


在下文中一共展示了HTTP.get_with_timeout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_epub

# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import get_with_timeout [as 别名]
    def open_epub(cls, url, content=None):
        """Cracks open an EPUB to expose its contents

        :param url: A url representing the EPUB, only used for errors and in
            the absence of the `content` parameter
        :param content: A string representing the compressed EPUB

        :return: A tuple containing a ZipFile of the EPUB and the path to its
        package
        """
        if not (url or content):
            raise ValueError("Cannot open epub without url or content")
        if url and not content:
            # Get the epub from the url if no content has been made available.
            content = HTTP.get_with_timeout(url).content
        content = StringIO(content)

        with ZipFile(content) as zip_file:
            if not cls.CONTAINER_FILE in zip_file.namelist():
                raise ValueError("Invalid EPUB file, not modifying: %s" % url)

            with zip_file.open(cls.CONTAINER_FILE) as container_file:
                container = container_file.read()
                rootfiles_element = etree.fromstring(container).find("{urn:oasis:names:tc:opendocument:xmlns:container}rootfiles")

                if rootfiles_element is None:
                    raise ValueError("Invalid EPUB file, not modifying: %s" % url)

                rootfile_element = rootfiles_element.find("{urn:oasis:names:tc:opendocument:xmlns:container}rootfile")
                if rootfile_element is None:
                    raise ValueError("Invalid EPUB file, not modifying: %s" % url)

                package_document_path = rootfile_element.get('full-path')
            yield zip_file, package_document_path
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:36,代码来源:epub.py


注:本文中的http.HTTP.get_with_timeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。