本文整理匯總了Python中calibre.ebooks.docx.container.DOCX.get_document_properties_names方法的典型用法代碼示例。如果您正苦於以下問題:Python DOCX.get_document_properties_names方法的具體用法?Python DOCX.get_document_properties_names怎麽用?Python DOCX.get_document_properties_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calibre.ebooks.docx.container.DOCX
的用法示例。
在下文中一共展示了DOCX.get_document_properties_names方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_metadata
# 需要導入模塊: from calibre.ebooks.docx.container import DOCX [as 別名]
# 或者: from calibre.ebooks.docx.container.DOCX import get_document_properties_names [as 別名]
def set_metadata(stream, mi):
from calibre.utils.zipfile import safe_replace
c = DOCX(stream, extract=False)
dp_name, ap_name = c.get_document_properties_names()
dp_raw = c.read(dp_name)
try:
ap_raw = c.read(ap_name)
except Exception:
ap_raw = None
cp = etree.fromstring(dp_raw)
update_doc_props(cp, mi)
replacements = {}
if ap_raw is not None:
ap = etree.fromstring(ap_raw)
comp = ap.makeelement('{%s}Company' % namespaces['ep'])
for child in tuple(ap):
if child.tag == comp.tag:
ap.remove(child)
comp.text = mi.publisher
ap.append(comp)
replacements[ap_name] = BytesIO(xml2str(ap))
stream.seek(0)
safe_replace(stream, dp_name, BytesIO(xml2str(cp)), extra_replacements=replacements)