本文整理汇总了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