import random
from typing import Any, Dict, List, Set, Union
from lxml import etree
LEVELS = {"coverage", "coverageSet", "coverageEmpty", "quality"}
MODES = {"oneLine", "multipleLines"}
[docs]
def quote_list(it: Union[Dict[str, Any], List[str], Set[str]]) -> str:
"""
Wrap each element in single quotation marks and return as a comma-separated string.
:param it: an iterable
"""
return ", ".join(f"'{el}'" for el in sorted(it))
[docs]
def box_image(tag, function, filename: str, *args, **kwargs) -> etree.Element:
"""
Add an image to the OpenDocument file and return an image within a frame.
"""
buffer, aspect_ratio = function(*args, **kwargs)
path = tag.gdocs.add_image_file(buffer, filename)
buffer.close()
frame = etree.Element(
"{urn:oasis:names:tc:opendocument:xmlns:drawing:1.0}frame",
attrib={
# '{urn:oasis:names:tc:opendocument:xmlns:drawing:1.0}style-name': 'fr1',
"{urn:oasis:names:tc:opendocument:xmlns:drawing:1.0}name": path,
"{urn:oasis:names:tc:opendocument:xmlns:text:1.0}anchor-type": "as-char",
"{urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0}width": "6.0cm",
"{urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0}height": "%fcm" % (6 * aspect_ratio),
"{urn:oasis:names:tc:opendocument:xmlns:style:1.0}rel-width": "100%",
"{urn:oasis:names:tc:opendocument:xmlns:style:1.0}rel-height": "scale",
"{urn:oasis:names:tc:opendocument:xmlns:drawing:1.0}z-index": "0",
},
)
frame.append(
etree.Element(
"{urn:oasis:names:tc:opendocument:xmlns:drawing:1.0}image",
attrib={
"{http://www.w3.org/1999/xlink}href": path,
"{http://www.w3.org/1999/xlink}type": "simple",
"{http://www.w3.org/1999/xlink}show": "embed",
"{http://www.w3.org/1999/xlink}actuate": "onLoad",
"{urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0}mime-type": "image/png",
},
)
)
return frame