本文整理匯總了Python中calibre.ebooks.docx.container.DOCX.close方法的典型用法代碼示例。如果您正苦於以下問題:Python DOCX.close方法的具體用法?Python DOCX.close怎麽用?Python DOCX.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calibre.ebooks.docx.container.DOCX
的用法示例。
在下文中一共展示了DOCX.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_metadata
# 需要導入模塊: from calibre.ebooks.docx.container import DOCX [as 別名]
# 或者: from calibre.ebooks.docx.container.DOCX import close [as 別名]
def get_metadata(stream):
c = DOCX(stream, extract=False)
mi = c.metadata
try:
cdata = get_cover(c)
except Exception:
cdata = None
import traceback
traceback.print_exc()
c.close()
stream.seek(0)
if cdata is not None:
mi.cover_data = cdata
return mi
示例2: get_metadata
# 需要導入模塊: from calibre.ebooks.docx.container import DOCX [as 別名]
# 或者: from calibre.ebooks.docx.container.DOCX import close [as 別名]
def get_metadata(stream):
c = DOCX(stream, extract=False)
mi = c.metadata
c.close()
stream.seek(0)
cdata = None
with ZipFile(stream, 'r') as zf:
for zi in zf.infolist():
ext = zi.filename.rpartition('.')[-1].lower()
if cdata is None and ext in {'jpeg', 'jpg', 'png', 'gif'}:
raw = zf.read(zi)
try:
width, height, fmt = identify_data(raw)
except:
continue
if 0.8 <= height/width <= 1.8 and height*width >= 12000:
cdata = (fmt, raw)
if cdata is not None:
mi.cover_data = cdata
return mi