def write_content_types(workbook, as_template=False):
    """Write the content-types xml."""

    seen = set()
    if workbook.vba_archive:
        root = fromstring(workbook.vba_archive.read(ARC_CONTENT_TYPES))
        for elem in root.findall('{%s}Override' % CONTYPES_NS):
            seen.add(elem.attrib['PartName'])
        for elem in root.findall('{%s}Default' % CONTYPES_NS):
            seen.add(elem.attrib['Extension'])
    else:
        if LXML:
            NSMAP = {None : CONTYPES_NS}
            root = Element('{%s}Types' % CONTYPES_NS, nsmap=NSMAP)
        else:
            root = Element('{%s}Types' % CONTYPES_NS)

    for setting_type, name, content_type in static_content_types_config:

        attrib = {'ContentType': content_type}
        if setting_type == 'Override':
            if '/' + name not in seen:
                tag = '{%s}Override' % CONTYPES_NS
                attrib['PartName'] = '/' + name
                SubElement(root, tag, attrib)
        else:
            if name not in seen:
                tag = '{%s}Default' % CONTYPES_NS
                attrib['Extension'] = name
                SubElement(root, tag, attrib)

    nodes = root.findall('{%s}Override' % CONTYPES_NS)
    for wb_elem in nodes:
        if wb_elem.get("PartName") == "/" + ARC_WORKBOOK:
            ct = as_template and XLTX or XLSX
            if workbook.vba_archive:
                ct = as_template and XLTM or XLSM
            wb_elem.set("ContentType", ct)

    drawing_id = 1
    chart_id = 1
    comments_id = 1

    for sheet_id, sheet in enumerate(workbook.worksheets):
        name = '/xl/worksheets/sheet%d.xml' % (sheet_id + 1)
        if name not in seen:
            SubElement(root, '{%s}Override' % CONTYPES_NS, {
                'PartName': name,
                'ContentType': WORKSHEET_TYPE
            })

        if sheet._charts or sheet._images:
            name = '/xl/drawings/drawing%d.xml' % drawing_id
            if name not in seen:
                SubElement(root, '{%s}Override' % CONTYPES_NS, {
                    'PartName': name,
                    'ContentType': DRAWING_TYPE
                })

            drawing_id += 1

            for chart in sheet._charts:
                name = '/xl/charts/chart%d.xml' % chart_id
                if name not in seen:
                    SubElement(root, '{%s}Override' % CONTYPES_NS, {
                        'PartName': name,
                        'ContentType': CHART_TYPE
                    })

                chart_id += 1

        if sheet._comment_count > 0:
            name = '/xl/comments%d.xml' % comments_id
            if name not in seen:
                SubElement(root, '{%s}Override' % CONTYPES_NS, {
                    'PartName': name,
                    'ContentType': COMMENTS_TYPE
                })
            comments_id += 1

    for idx, _ in enumerate(workbook._external_links, 1):
        el = Element('{%s}Override' % CONTYPES_NS, {
            'PartName': '/xl/externalLinks/externalLink{0}.xml'.format(idx),
            'ContentType': EXTERNAL_LINK
        })
        root.append(el)

    return tostring(root)
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/openpyxl-2.3.0-b2/openpyxl/writer/workbook.py/write_content_types/original