def METHOD_NAME(write, elem, *args, **kwargs):
    if elem.tag in CNAME_TAGS:
        attrs = ' '.join(
            ['{}={}'.format(k, quoteattr(v))
             for k, v in sorted(elem.attrib.items())]
        )
        attrs = ' ' + attrs if attrs else ''
        text = CNAME_PATTERN.format(elem.text)
        write(TAG_PATTERN.format(
            tag=elem.tag,
            attrs=attrs,
            text=text
        ))
    else:
        original_serialize(write, elem, *args, **kwargs)