def tag2html(tag): def trim_str(vstr): if len(vstr) > 90: vstr = vstr[:75] + " ... " + vstr[-10:] return vstr tpl = TAG_TPL if tag.code in HANDLE_DEFINITIONS: # is handle definition tpl = TAG_HANDLE_DEF_TPL elif tag.code in HANDLE_LINKS: # is handle link tpl = TAG_HANDLE_LINK_TPL vstr = trim_str(ustr(tag.value)) return tpl.format(code=tag.code, value=escape(vstr), type=escape(tag_type_str(tag.code)))
def hdrvars2html(hdrvars, custom_vars): """DXF header section as <div> container. """ def vartype(hdrvar): if is_point_code(hdrvar.code): dim = len(hdrvar.value) - 2 return ("<point 2D>", "<point 3D>")[dim] else: return tag_type_str(hdrvar.code) varstrings = [ HEADER_VAR_TPL.format(code=name, value=escape(ustr(hdrvar.value)), type=escape(vartype(hdrvar))) for name, hdrvar in hdrvars.items() ] custom_property_strings = [ CUSTOM_VAR_TPL.format(tag=escape(ustr(tag)), value=escape(ustr(value))) for tag, value in custom_vars ] varstrings.extend(custom_property_strings) return HEADER_SECTION_TPL.format(content="\n".join(varstrings))
def tag2html(tag): def trim_str(vstr): if len(vstr) > 90: vstr = vstr[:75] + " ... " + vstr[-10:] return vstr tpl = TAG_TPL if tag.code in HANDLE_DEFINITIONS: # is handle definition tpl = TAG_HANDLE_DEF_TPL elif tag.code in HANDLE_LINKS: # is handle link if tag.value in self.entitydb: tpl = TAG_VALID_LINK_TPL else: tpl = TAG_INVALID_LINK_TPL vstr = trim_str(ustr(tag.value)) type_str = tag_type_str(tag.code) if type_str == '<bin>': if isinstance(tag, CompressedTags): type_str = '<multiple binary encoded data tags compressed to one tag>' else: type_str = '<binary encoded data>' vstr = "" return tpl.format(code=tag.code, value=escape(vstr), type=escape(type_str))
def var2str(hdrvar): if hdrvar.ispoint: return ustr(hdrvar.getpoint()) else: return ustr(hdrvar.value)